Usage: javac <options> <source files> where possible options include: -g Generate all debugging info -g:none Generate no debugging info -g:{lines,vars,source} Generate only some debugging info -nowarn Generate no warnings -verbose Output messages about what the compiler is doing -deprecation Output source locations where deprecated APIs are used -classpath <path> Specify where to find user class files and annotation processors -cp <path> Specify where to find user class files and annotation processors -sourcepath <path> Specify where to find input source files -bootclasspath <path> Override location of bootstrap class files -extdirs <dirs> Override location of installed extensions -endorseddirs <dirs> Override location of endorsed standards path -proc:{none,only} Control whether annotation processing and/or compilation is done. -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process -processorpath <path> Specify where to find annotation processors -parameters Generate metadata for reflection on method parameters -d <directory> Specify where to place generated class files -s <directory> Specify where to place generated source files -h <directory> Specify where to place generated native header files -implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files -encoding <encoding> Specify character encoding used by source files -source <release> Provide source compatibility with specified release -target <release> Generate class files for specific VM version -profile <profile> Check that API used is available in the specified profile -version Version information -help Print a synopsis of standard options -Akey[=value] Options to pass to annotation processors -X Print a synopsis of nonstandard options -J<flag> Pass <flag> directly to the runtime system -Werror Terminate compilation if warnings occur @<filename> Read options and filenames from file
Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) where options include: -d32 use a 32-bit data model if available -d64 use a 64-bit data model if available -server to select the "server" VM The default VM is server.
-cp <class search path of directories and zip/jar files> -classpath <class search path of directories and zip/jar files> A ; separated list of directories, JAR archives, and ZIP archives to search for class files. -D<name>=<value> set a system property -verbose:[class|gc|jni] enable verbose output -version print product version and exit -version:<value> Warning: this feature is deprecated and will be removed in a future release. require the specified version to run -showversion print product version and continue -jre-restrict-search | -no-jre-restrict-search Warning: this feature is deprecated and will be removed in a future release. include/exclude user private JREs in the version search -? -help print this help message -X print help on non-standard options -ea[:<packagename>...|:<classname>] -enableassertions[:<packagename>...|:<classname>] enable assertions with specified granularity -da[:<packagename>...|:<classname>] -disableassertions[:<packagename>...|:<classname>] disable assertions with specified granularity -esa | -enablesystemassertions enable system assertions -dsa | -disablesystemassertions disable system assertions -agentlib:<libname>[=<options>] load native agent library <libname>, e.g. -agentlib:hprof see also, -agentlib:jdwp=help and -agentlib:hprof=help -agentpath:<pathname>[=<options>] load native agent library by full pathname -javaagent:<jarpath>[=<options>] load Java programming language agent, see java.lang.instrument -splash:<imagepath> show splash screen with specified image See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
//construct clone of an object Box(Box ob){//pass object to constructor width=ob.width; height=ob.height; depth=ob.depth; } //constructor used when all dimensions specified Box(double w,double h,double d){ width=w; height=h; depth=d; } //constructor used when no dimensions specified Box(){ width=-1; height=-1; depth=-1; } //constructor used when cube is created Box(double len){ width=height=depth=len; } //compute and return volume doublevolume(){ return width*height*depth; } } classOverloadCons2{ publicstaticvoidmain(String args[]){ //create boxes using the various constructors Box mybox1=new Box(10,20,15); Box mybox2=new Box(); Box mycube=new Box(7); Box myclone=new Box(mybox1);
double vol; //get volume of first box vol=mybox1.volume(); System.out.println("Volume of mybox1 is "+vol); //get volume of second box vol=mybox2.volume(); System.out.println("Volume of mybox2 is "+vol); //get volume of cube vol=mycube.volume(); System.out.println("Volume of cube is "+vol); //get volume of clone vol=myclone.volume(); System.out.println("Volume of clone is "+vol); } }
运行结果:
1 2 3 4
Volume of mybox1 is 3000.0 Volume of mybox2 is -1.0 Volume of cube is 343.0 Volume of clone is 3000.0
publicclassClass3{ publicstaticvoidmain(String args[]){ SubSubClass x = new SubSubClass(10, 20, 30); x.show(); } } classSuperClass{ int a, b; SuperClass(int aa, int bb) { a = aa; b = bb; } voidshow(){ System.out.println("a=" + a + "\nb=" + b); } } classSubClassextendsSuperClass{ int c; SubClass(int aa, int bb, int cc) { super(aa, bb); c = cc; } } classSubSubClassextendsSubClass{ int a; SubSubClass(int aa, int bb, int cc) { super(aa, bb, cc); a = aa + bb + cc; } voidshow(){ System.out.println("a=" + a + "\nb=" + b + "\nc=" + c); } }