Monday, September 26, 2016

More About "javac" et cetera ...


javac - Java compiler
javac [ options ] [ sourcefile.java ] [ @filelist ]
  • For large number of source files, list all file names in @filelist
  • In <filelist>, separate files with space or line breaks.
  • Inner class definitions produce additional class files.
  • [ options ]
-classpath pathname Set the user class path
-d directory Set the destination directory for class files
-g Generate all debugging information, including local variables.
-g:none Does not generate any debugging information.
-g:source Generate source file debugging information
-help Prints a synopsis of standard options
-nowarn Disables warning messages. (Same as -Xlint:none)
-sourcepath path Specify the source code path to search for class or interface definitions
-verbose Verbose output.
-X Display information about non-standard options and exit.

EXAMPLE
// Create a file named "options" containing:
//
//    -d classes
//    -g
//    -sourcepath /java/pubs/src/share/classes
//
// Create a file named "classes" containing:
//
//    MyClass1.java
//    MyClass2.java
//    MyClass3.java
//
// Run javac as follows:
//    javac @options @classes
//    javac @path1/options @path2/classes
//
% ls path1
   options
% cat path1/options
   -d classes
   -g
   -sourcepath /java/pubs/src/share/classes
% ls path2
   classes
% cat path2/classes
   MyClass1.java MyClass2.java MyClass3.java
% javac @path1/options @path2/classes
% java -classpath classes MyClass1
...

JVM

  1. Invoking the class's main method.
  2. There are 3 things that JVM do:
    • Loading
    • Linking
      • Verification - Checks the binary code with Java's semantic requirements.
      • Preparation - Prepares the class for execution by allocating memory space for data and static variables.
      • Resolution (optional) - Checks if the class references other classes/interfaces and find/load them. Checks are done recursively.
    • Initialization
      • Initializes static variables and execute static initializers in static blocks. This is done before the main method is executed. Before the class can be initialized, its parent class has to be loaded, linked and initialized first so this process happens recursively to the top most class.

JDK
  • javac - Java compiler
  • jar - Java Archive
  • javap - Java Disassembler
  • jdb - Java Debugger

No comments:

Post a Comment