Bright Java Tutorial

is brought to you by DoITBright LLC

Java

First Java Program Using JDK

JDK is an acronym for Java Development Kit. It is a software development environment for creating Java applications. It is released under GNU General Public License which means it is a free software.
The first thing to do is download a copy of the JDK from the Oracle website. At the time of this writing, the current version is 1.8 or also known as Java 8. For your quick reference, you can click here to go to the Oracle download site for the JDK. The page will look something like this.

Download JDK


My development environment is Windows 8 platform. So I will download the JDK for windows. After downloading it, you may want to install the JDK on your machine. During installation, it will prompt you the default installation folder.

Install JDK


You may choose to change it to another folder.

Install JDK To Chosen Path


Open a command prompt by clicking the Windows icon on your tool bar and typing 'cmd' on the search. Execute the following on your command prompt.

cd \BrightJavaTutorial
set path=c:\BrightJavaTutorial\jdk1.8\bin
javac

Set Path on Command Prompt


As you can see, the 'javac' command is now recognized by your system after setting the path on your command prompt. However, after you close the command prompt and you reopen another command prompt, you will need to perform the above steps again. It is now time to create your first Java program. Open your note pad and create a new file. Save the blank file in c:\BrightJavaTutorial folder and name it as MyFirstProgram.java. Below will be the contents of the file.

                            
    public class MyFirstProgram {
        public static void main(String[] args) {
            System.out.println("Congratulations!");
        }
    }
                           

On the command prompt, make sure you are on c:\BrightJavaTutorial folder, execute the command 'javac MyFirstProgram.java'. Then, execute the command 'java MyFirstProgram'. Here is how it looks like.

Java Console Output


The javac command is to compile the Java file into a byte code that JVM can understand. The java command is to run the compiled Java file which is a .class file extension. Go to your c:\BrightJavaTutorial folder and observe that after compiling the .java file, a .class file was generated.


Next