Let’s get into Details…

1.    public class FirstProgram

2.   {

3.   public static void main(String[] args)

4.  {

 5.  System.out.println(“This is to try my first program”);

6.   }

7.  }

Line number 1:

public – means everyone can access this program.

class – means object-oriented style of programming, the program is encapsulated within the class and that’s java.

FirstProgram – means the name of the class, to identify which or what class you’re working on, basically the name of your java program.

Line number 2:

{ – symbol which means start or begin for the class. Easy right?

Line number 3:

public – means the method can be called or invoked anywhere.

static – means no object  is needed to call this method. I’ll explain more about this word on my next post.

void – means no value is being returned.

main – the name of the method or procedure which means the main method, it’s like the main body in the program. I’ll discuss more about methods and main later. Just take it as it is that this is the name of the method.

(String[] args) – the argument that is being passed to this method main is an array of String and the name is args. I’ll discuss more about arguments and parameters on my succeeding posts. Example of String argument that is being passed to the main is the command line statement for executing the program (ex. java FirstProgram).

Line number 4:

{ – means begin for the main method.

Line number 5:

System.out.println – a program statement which means, print something to standard output device which is the screen monitor.

(“This is to try my first program”) – parenthesis is the symbol to enclose the function values or parameters. In this case, you have a string value that you want to print on the screen, the string value that will be printed on the screen is enclosed with the double quotations. String means a list of characters.

; – semicolon is to terminate the statement. Every statement must end with the semicolon. Like a period symbol in the sentence. In   java program, semicolon symbol is used.

Line number 6:

} – meaning end symbol for main method.

Line number 7:

} – meaning end symbol for the class.

I hope the above explanations are clear. Just leave your comments and questions below.

Try your first JAVA program

Try out the following steps:

1. First you need to have the Java Development Kit. You can download the kit on this website-


You can download the JDK SE 6, there’s the new version 7, but you can stick with version 6 for now. In the download website, choose which operating system you are using and just follow the instructions on how to download the JDK. I’m using Windows OS, the steps that I’m going to discuss is in windows environment, and the Editor is Notepad.

2. After you downloaded the java development kit, then you are ready to try your first java program.

3. Launch Notepad and then type the following code:

public class FirstProgram{

       public static void main(String[] args){

          System.out.println(“This is to try my first program”);

Let’s just try this program and on my next post I’ll explain each line in the code. For now, let me explain what is System.out.println(“This is to try my first program”);

*This is the program statement in java to display a message into the screen.

* The message that you want to display is enclosed in the double quotations and then enclosed inside the parenthesis.

*semicolon is a symbol which means to end the line or terminate the program statement. Program statement is like a sentence then semicolon is like the period in the sentence.

*System.out.println – is the command to display or print a message into an output stream which is the monitor.

* The command might be wordy and very long to type but later on you’ll get used to it. The main idea here is that, it’s readable and the commands are easy to understand.

* Later on, we’ll try more sophisticated programs like programs with graphics components.

4. Save the file with extension name .java like this – FirstProgram.java, it’s very important to remember that the   filename should be the same as your class name – class FirstProgram. Java is case sensitive, so make sure it is exactly the same as your class name on how it was written. For easy access, you can save your program in C: drive, you can create a folder and name it as – javacodes. So, your program should be in C:/javacodes directory.

5. In start menu, select Run, then on the Open box, type cmd to open command prompt.

6. On the command prompt, access your directory where you save your program, type C: then press enter. On C:\ , type cd javacodes (ex. C:\cd javacodes)

7. On the javacodes directory, we’ll set the path where your jdk is located, make sure you know where is jdk is save in your computer, copy the path. To set the path, here’s how:

C:\javacodes>set path=”C:\Program Files\Java\jdk1.6.0_30\bin” 

set path command is to be able to access the compiler and interpreter of java so that your java program in your directory can be compiled and interpreted.

8. Compile your java program using javac command, and here’s how:

C:\javacodes> javac FirstProgram.java

After compiling your .java source code, another file will be created which is .class file. This .class file is called bytecode.

Bytecode can be ready to run and interpreted in any system. So the next step is to run our bytecode file.

9. Run your program using java command, and here’s how:

C:\javacodes> java FirstProgram

So here you’ll notice that the command is java to run your java program and then the filename without the extension name.

10. Wait then you’ll see your output:

This is to try my first program

Additional Information:

If you would like to use an IDE (Integrated Development Environment) system to type and run your java program, here are my recommended links:

To download NetBeans: http://netbeans.org/

To download Eclipse: http://www.eclipse.org/downloads/

For questions and clarifications, don’t hesitate to leave your message in the comment section.


Phases of a Java Program

1. Start by writing your java source code in an Editor software or any IDE (Integrated Development Environment) (ex. notepad, IDE like Eclipse and NetBeans)

2. Save your java source code with filename extension java (ex. Hello.java)

3. Compile the .java source code resulting to bytecode with file extension name  .class

4. Bytecode will be Interpreted to run the program and see the output.

For practice, I’ll post the steps and instructions next week. This post is just to present the whole idea of how a java program is executed.
In my next post I’ll include recommended links about IDE software and where to download the java system.