Java file layout without IDE (OS: Ubuntu) -
i writing java code without ide, got little problem when try run code after compiling it. (i using ubuntu 64)
$ javac classname.java $ java classname not find or load main class classname
my directory structure following:
projectname
----- packagename
---------- classname.java
---------- classname.class
my code start writing down packagenmae. when remove package statement, works. while error occur when statement included.
package packagename; public class myclass { // .... used in main class } public class classname { public static void main(string args[]) { // .... } }
could tell me problem.
the main issue trying run command from. not run inside package directory, root of package tree (in example, projectname directory).
from there, should doing:
javac packagename.classname
which tells compile "classname"[sic] inside package "packagename"[sic]. way doing it, telling compile class not part of package (which discouraged).
notes:
- each file can have "general" class, name of file.
you may define inner classes inside class, inside code block of class.
package packagename;
public class classname { public class innerclass { ... }
public static void main(string args[]) { ... } }
file name , class name must same. includes case (lowercase or uppercase) of name.
class names begin in uppercase.
package names should in camelcase.
usually not want leave compiled (.class) files source (.java) files. usual structure is, @ minimum:
--> project --> src --> mypackage --> myclass.java --> bin --> mypackage --> myclass.class
so need copy .class files distribute executable.
Comments
Post a Comment