The Java programming language is an object-oriented language designed to be
portable
. Unlike languages like C, Java programs follow a "write once, run anywhere" model. You write the program one time, compile it to byte code, and run it on any computer that has a Java Virtual Machine (JVM) available.
Implementation and Compilation
Writing and running a Java program involves three steps.
-
The programmer writes Java code and stores that code in files ending with the extension .java.
-
Open an editor of your choice and write your code. Class X must be stored in file X.java.
-
The Java code is compiled into Java
byte code
. The byte code for the code stored in file X.java is stored in file X.class.
-
From the command line,
navigate to the directory
where your Java file is stored and type
javac classname.java
-
If there are errors in your program, the compiler will tell you. If there are no errors, a .class file will be created.
-
The Java Virtual Machine (
JVM
) is launched. The JVM reads and interprets the byte code stored in the specified class files. The result is a running program.
-
From the command line,
navigate to the directory
where your Java file is stored and type
java classname
-
Note that you do not include an extension after the class name.
For more information see the following:
Syntax Highlights
-
Java programs consist of one or more
classes
. A class X is stored in a file X.java.
-
There are two ways to
comment
your code in Java. The first option is to use
//
. A
//
will comment every from the the
//
to the end of the line.
|