about


Scribe:

chrono

blog

Time

science!

book musings

gov

'punk

missle defense

jams

antiques

cultcha blog


Construct:

scripts & programs

on the town

snaps


Self:

creds (PDF)

key

missive


The Most Basic Java Program Possible

This is the structure of a basic Java program. It can be written in notepad , or a text editor. and compiled at the command line with the Javac compiler, which is in the Java Development Kit (JDK):
public class BasicJavaProgram {

public static void main(String[] args) {
    System.out.println("I can haz a Javur Program too!");
                                       }  
                  }
Note: A copy of the working program can be found here.

To be compiled, the name of the file must have the .java extension. It must also be the same name as the "public class" declaration. So in this case, it would be BasicJavaProgram.

To break it down some:

public class BasicJavaProgram 
This is the declaration of a class, in this case, the main class of the program. Think of a class as a blueprint, from which individual "instance" objects can be created. A Java program must have at least one class. Since it is a public class, it can be called from code in other classes.

The guts of class itself is contained within the set of { and } -- all the action happens in-between those brackets. In this program,there is one method, called "main." Every java program must have a "main" method--that is what the compiler looks for to run. A method is a subroutine that does a task for the class. The "public" "static" and "void" are reserved keywords that help the compiler understand the method.

Like the class itself, the method is contained within { and the } brackets (They are embedded with the classes' own { and } brackets, so there is some recursion going on here):

{ System.out.println("I can haz a Javur Program too!");}
This one has the command to print out a line of text out ("I can haz a Javur Program too!"), using the print function "println" from the System.Out library of Java.

Taken from the book, "Introduction to Java Programming" (7th edition), by Y. Daniel Liang....

...as well as from the materials of a class I am taking.--Joab Jackson