Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Learn Java from the ground up

An introduction to Java that will help Java newbies to become Java developers

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 2 of 6

That's about it on the JVM for now. If you want to know more, check out Sun's JVM specification in the Resources section below.

Setting up Java on your system

The first thing you need is the Java 2 Software Development Kit or SDK (formerly known as the Java Development Kit, or JDK). This is a set of software and software tools supplied by Sun that includes all of the basic components needed to build Java programs. If you don't have this, you'll need to download the Java 2 SDK from Sun (see Resources below). Here's a brief description of what you need to do to install version 1.2.x for the Windows platform:

  • For Windows, the download will be a self-extracting archive, and the file name follows the form: jdk<version>-win.exe. For example, for version 1.2.2, the file is named jdk1_2_2-win.exe.
  • Execute the program to install the Java 2 SDK.
    • You can execute it by typing its name at a command prompt.
    • You can double-click it from Explorer.
    • On Windows, the default installation directory is C:\JDK1.2.x


  • You must set up your environment correctly
  • Your path must be set to include the bin subdirectory
  • For example, if you installed the Java 2 SDK in C:\JDK1.2.x, you must include C:\JDK1.2.x\bin in your path
    • If you are using Windows 95/98, you can do this in autoexec.bat
    • If you are using Windows NT, go to Control Panel, System, Environment
    • You can set environment variables in the dialog box there
  • There are other parts of the environment that are important, especially the CLASSPATH environment variable. I'll discuss this in future columns.


  • It's also important to download the javadoc HTML documentation for the core API classes. This is a separate download, in zip format, and the filename is in the form of jdk<version>-doc.zip (for example, jdk1_2_2-doc.zip).
  • The javadoc HTML documentation should be unzipped into the Java 2 SDK installation directory
    • Note that the zip file has a directory structure within it, so that unzipping it into C:\ will place all of the files at the root directory C:\JDK1.2.x\docs, which is a good place for them.


The following tools will be used to create and run our first program:

  • javac: the Java compiler that converts Java source to bytecode
  • java: the Java Virtual Machine


How to write a Java program

OK, it's time to write our first Java program. A Java program looks like this:

public class MyProgram {

public static void main(String[] args) { System.out.println( "Eureka, I can put Java on my resume."); } }


A Java program is a class with a main method in it. The main method is a special method that is the starting point for every Java application. It has to be declared exactly as above, and it has to appear within a class, as the above example also shows. System.out.println is the magic incantation you use to get things sent to the console.

This code example is for a standalone, nongraphical Java program that prints the string Eureka, I can put Java on my resume. to the console. Your salary can double now, so if you want, you can stop here. Those that want to learn more can keep going.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (15)
Login
Forgot your account info?

invoking compiled programBy Anonymous on November 17, 2009, 5:27 amHi, I had to type java -cp . MyProgram to invoke the program. Using java-6-openjdk.

Reply | Read entire comment

i have an information for u abt java learningBy Anonymous on September 23, 2009, 6:44 amread this if u want to learn java program . http://www.bizmartindia.com/education/computer-education-training/java-training-institute-in-delhi-java-j2ee-core-java-language-14398.php

Reply | Read entire comment

i needto study java moreBy Anonymous on September 15, 2009, 7:03 amthis brief tutorial is very nice and i'd like t learn more about java... thank you..

Reply | Read entire comment

Thanks!By Anonymous on September 2, 2009, 3:20 pmThanks a lot!

Reply | Read entire comment

i needBy Anonymous on July 24, 2009, 2:35 pmi need lirning JAVA programe

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources