Learning Java
Custom Search

Previous Next

Testing The Set Up

After you set up your Java environment, you can test your setup by copying (Ctl C) and pasting (Ctl V) the following code into Notepad and naming it MyTest.java. Java is case sensitive, so be sure to put capitals where you see them.

public class MyTest {
   public static void main(String args[]) {
      System.out.println
	("In the beginning God created the heaven and the earth.");
   }
}

All this program does is display a message. It demonstrates the minimum required for a Java application.

All java code must be contained in a Java class. Each class should, generally, be placed in its own source file which should preferably be named after that class. Thus, in our example, the class was named MyTest and the source file was named MyTest.java. There can be multiple classes in the same source file, but only one can be accessible outside of the source and it should be declared as public.

Curly braces, such as { and }, are used to group related lines of code together. The code for the class MyTest is contained within the outermost 2 curly braces. The innermost curly braces group together some lines called a main method, labelled public static void main.

In our example class above, the method named main contains the action we want to perform, which is print a line of text.

To test the sample program in MyTest.java, open a cmd window by clicking on the Start menu and then the Run option. Enter cmd in the text box and click OK.

At the prompt, get to the directory where you saved MyTest.java. To compile it, enter the following: Put capitals where you see them.

    javac MyTest.java

This creates the file MyTest.class

Now to execute, enter

    java MyTest

If this works, you have successfully installed the jdk.

 

Previous Next

Steps In Learning

Contact us

Copyright © 2008      N. Nelson      All Rights Reserved