Creating, Compiling and Executing Java Programs

This section describes the process of Java program creation, compilation and execution. JDK 'javac' and 'java' commands are also described.

There are 3 steps involved in building and running a Java program:

Creating a source code file can be done by a simple text editor, notepad, or a sophisticated Java development environment tool, like Eclipse, or Visual J++.

Compiling a source code file needs a Java compiler. The JDK package contains a Java compiler, which can be invoked by the command "javac". The "javac" command takes source code file names as command line arguments. For example, entering the following command in command window will invoke the "javac" compiler to compile the "" source code file:

herong> javac

The "javac" command also has several command options available:

For example, the following command:

herong> javac -d .\cls -classpath .\lib;.\cls \
   -sourcepath .\src .\src\

invokes the "javac" compiler, and tells it to:

Executing a Java program needs a JVM. The JDK also contains a JVM, called HotSpot, which can be invoked by the command "java". The "java" command takes the name of the starting class as the command argument. For example, the following command:

herong> java -classpath .\lib;.\cls;. Hello

invokes HotSpot to:

The "-classpath" option specifies the class path, which contains directories where the JVM will search for the bytecode files of the starting class and other program units when needed.

Table of Contents

 About This Book

 JDK - Java Development Kit

Execution Process, Entry Point, Input and Output

Creating, Compiling and Executing Java Programs

 main() Method - Java Execution Entry Point

 Java Execution Console - "in", "out" and "err" Data Streams

 Primitive Data Types and Literals

 Control Flow Statements

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

 Enum Types and Enum Constants

 StringBuffer - The String Buffer Class

 System Properties and Runtime Object Methods

 Generic Classes and Parameterized Types

 Generic Methods and Type Inference

 Lambda Expressions and Method References

 Java Modules - Java Package Aggregation

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Assert Statements and -ea" Option

 Annotation Statements and Declarations

 Java Related Terminologies

 Archived Tutorials


 Full Version in PDF/EPUB