|
|
|
1000 Java Tips ebook
|
|
 

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!. |
|
The Java Lesson 2: Anatomy of a simple Java program
|
JavaFAQ Home » Java Lessons by Jon Huhtala

In order to code and test Java programs, you need Java
development software and must know how to use it. Before you go on, you MUST
read and master the essential skill of running Java programs
A sample Java program
The following program
is a slight variation of the program that is part of the original
Test project. When
executed, it will display the message "Hello
World!" on the system output
device (the computer console):
/** * This
class defines a program that displays a message on the console. * *
Written by: Jon Huhtala */
public class App {
// This
required method is the starting point for processing.
public
static void main(String[] args) {
System.out.println("Hello World!"); // Display the message.
} }
Testing the sample
program
Assuming you have a
Test project and have already opened a
Notepad window and a Command Prompt window, the procedure to test
this sample program is as follows:
-
"Copy" the source statements
(shown in blue above).
-
"Paste" the source
statements into your Notepad window being sure to replace the entire
contents of the window if it contained previous code.
-
Save the source file under
the name "App.java" in your
Test project.
-
Compile the "App.java" source file by entering the
following command in the Command Prompt window:
javac App.java
-
Run the "App.class" bytecode file by entering the
following command in the Command Prompt:
java App
Program analysis
Studying this sample program
line-by-line will start you on the path to learning Java. The sections that
follow will help you analyze the sample program. For now, it is not important
that you understand everything completely. Through constant usage, you will
eventually know what it all means.
Comments in Java
-
Javadoc.
Begin with /** and end
with */. Everything
between is treated as a comment.
-
Single-line.
Begin with // and
automatically continue to the end of the line.
-
Multi-line.
Begin with /* and end
with */. Everything
between is treated as a comment.
The lesson continues here
The program's
class
- Every Java program must be defined as a class. The statement
public class
App
is the class header. It declares that a class named App is to be defined
and that it is to be publicly available for access from other places. In order
for the Java Virtual Machine to find and use the program's class, always make
it public. Other access modifiers (private,
protected, and default or package access) will be presented
later.
Printer Friendly Page
Send to a Friend
..
Search here again if you need more info!
|
|
|