One of the chic must
have the main() adjustment as the beheading starting point of the program.
There are 3 accomplish complex in creating the classes and interfaces of a Java program,
and active the program:
- Creating Classes and Interfaces: Creating a argument book for anniversary chic or
interface that contains the analogue of the chic or interface accounting in Java
Such a book is alleged antecedent cipher file, which haveto accept a book name identical to the
name of the chic or interface authentic in the file, and an addendum of ".java".
- Compiling Classes and Interfaces: Converting a antecedent cipher book into a bytecode
file that contains the aforementioned analogue of the chic or interface accounting Java Basic
Machine (JVM) instructions. A bytecode book haveto accept a book name identical to the
name of the chic or interface authentic in the file, and an addendum of ".class".
- Executing a Java Program: Loading bytecode files into JVM, and executing
its JVM instructions starting from the access point of the defined class.
Creating a antecedent cipher book can be done by a simple argument editor, notepad, or a sophisticated
Java development ambiance tool, like Beheld J++.
Compiling a antecedent cipher book needs a Java compiler. The J2SDK amalgamation from Sun
Microsystems contains a Java compiler, which can be invoked by command "javac".
The "javac" command takes antecedent cipher book names as command band arguments. For
example, entering the afterward command in command window will adjure the "javac"
compiler to abridge the "Hello.java" antecedent cipher file:
The "javac" command aswell has several command options available:
- -d: Specify the agenda area the bytecode files generated by the compiler should
be placed, if you don t wish to abode them in the accepted directory.
- -classpath: Specify the directories area to seek for classes or interfaces
definitions in bytecode format, if the classes or interfaces are acclimated in antecedent cipher file.
- -sourcepatch: Specify the directories area to seek for classes or interfaces
definitions in antecedent cipher format, if the classes or interfaces are acclimated in antecedent cipher file.
For example, the afterward command:
c:j2sdk1.4.1_01injavac -d .cls -classpath .lib;.cls
-sourcepath .src .srcTest.java
invokes the "javac" compiler, and tells it to:
- Compile the "Test.java" antecedent cipher book in the ".src" directory.
- Place the bytecode file, "Test.class", in the ".cls" directory.
- Search ".lib" and ".cls" directories for the definitions in bytecode architecture
of classes or interfaces that are acclimated in "Test.java".
- Search ".src" agenda for the definitions in antecedent cipher architecture of classes
or interfaces that are acclimated in "Test.java".
During the accumulation process, if the analogue of a chic or interface is acclimated
in the antecedent cipher file, the compiler will use the afterward rules to seek for
- If the compiler could not acquisition the chic or interface in the chic aisle and
the antecedent path, the compiler will aftermath a accumulation absurdity adage
that "cannot boldness symbol" area the attribute is the name of the chic or interface.
- If the compiler acquisition the chic or interface alone in the chic path,
the compiler will be blessed to use it as it is.
- If the compiler acquisition the chic or interface alone in the antecedent path,
the compiler will abridge it afore using it.
- If the compiler acquisition the chic or interface in the antecedent aisle and in the chic path,
the compiler will analyze the two file. If the antecedent cipher book is newer than
the bytecode file, the compiler will abridge the antecedent cipher file.
Executing a Java program needs a JVM. The J2SDK aswell contains
a JVM, alleged HotSpot, which can be invoked by command "java".
The "java" command takes the name of the starting chic as the command
argument. For example, the afterward command:
c:j2sdk1.4.1_01injava -cp .lib;.cls;. Analysis
invokes HotSpot to:
- Load "Test" chic into HotSpot.
- Execute the main() adjustment of the "Test" class.
The "-cp" advantage defines the chic path, which contains directories area
the JVM will seek for the bytecode files of the starting chic and
other classes if needed.
Tags: program, files, directories, creating, starting, class, classes, contains, search, directory, format, interface, command, source
class, source, compiler, command, classes, interface, interfaces, bytecode, program, search, directory, javac, contains, format, creating, directories, execution, compile, starting, definition, following, definitions, hotspot, files, j2sdk1, specify, , source code, code file, compiler will, class path, classes and, path the, test class, compiler find, test java, source path, specify the, bytecode file, java program, bytecode files, following command, directories where, compile the, search for, source code file, compiler will compile, source code format, java source code, file name identical,
Also see ...Permalink
Article In : Computers & Technology - java