Java Reference
In-Depth Information
On the Web
The listed sample header above is contained in the Chapter 2 folder at
www.crcpress.com . ThenameofthefileisHeader.java
The HelloJava code
Let's examine the HelloJava program line-by-line. The program is re-listed be-
low:
// Java version of the Hello World program
// Developed for the topic “Java for Engineers”
// by CRC Press
public class HelloJava
{
public static void main(String[] args)
{
System.out.println(“Hello World, this is Java”);
}
}
The first three program lines are as follows:
//
Java version of the Hello World program
//
Developed for the topic “Java for Engineers”
//
by CRC Press
These three program lines are a comment. They are ignored by the com-
piler and have no other purpose than to document and explain the code. We
have used the // symbol to comment the lines individually.
The first non-comment line of the HelloJava program is as follows:
public class HelloJava
{
Programming languages, Java included, use special language elements
called keywords . Keywords are reserved and cannot be used in regular ex-
pressions. The keyword public , called an access modifier , determines if
other parts of the program can use this code. The keyword class is neces-
sary because everything in a Java program exists in a class.
The first class in a Java program is called the driving class. The driving
class must have the same name as the file in which it is stored. In other words,
if you save a Java program in a file named MyHello.java, then the driving class
must have the name MyHello. In the sample program, the source file has the
filename HelloJava.java, and the driving class is named HelloJava.
Search WWH ::




Custom Search