Custom Search

Monday, May 16, 2011

The very beginning(see java JDK post first)

In this post we will be building a simple java program.
Before this you will need to download and install the java JDK.
This is available for download at http://oracle.com
You may have to look up other tutorials on installing this, or I might do a post on it.

After you do this open up any basic text editor.  Lets begin with the basics of java, a class.  Type this code into your text editor:

public class pear{
public static void main(String[] args){
 System.out.println("Hey");


}

Lets work our way from the top down.
PUBLIC: declaring the class available to look at by other classes.
CLASS:base of a java application.Java is built out of classes.
PEAR:what we named the class.
PUBLIC STATIC VOID MAIN(STRING[] ARGS): our main method, in later posts we will be going over this.
SYSTEM:telling the system to do something.
OUT:telling the system to put something out.
PRINTLN:telling the system to print something(the LN is stands for next line).

Lets save this to the desktop for easy access.When saving save the file name as this:pear.java, then save it as an all file type.Next go into command prompt and type:
cd desktop

then type:

Javac pear.java

now on your desktop you should have a .class
now in command prompt type:
java pear

the words "hey" should appear.  I know this isnt a super sweet java application, but you have to start somewere!

No comments:

Post a Comment