QuickStart Java                                  

by Dr. Tom Way

Step-by-step instructions for learning to program in Java


 About the language                                                    

Name:  Java
Year created: 1996
Created by: Sun Microsystems, Patrick Naughton, James Gosling, Mike Sheridan
Paradigm: Object-oriented
Platform: Platform-independent, runs intermediate bytecode, which is interpreted by a platform-dependent virtual machine. The motto is "write once, run anywhere."
Domain: Web applications (Applets, JSP), Database (JDBC), General applications
Advantages: Platform independence, fast prototyping of user interfaces, excellent documentation, great for teaching and learning about programming, increasing in popularity, used in industry, automatic garbage collection
Disadvantages: Compiled to Java bytecode, which is interpreted, so it can be slower that true compiled languages like C++, but this shortcoming is gradually diminishing
Specification: http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html
Grammar: http://java.sun.com/docs/books/jls/third_edition/html/syntax.html#18.1

Step 1. Download and install the latest JDK

 

Step 2. Download and install the latest version of Eclipse

 

Step 3. Write a "hello world" program

public class HelloWorld {

   public static void main(String[] args) {
      System.out.println("Hello world!");
   }
}

 

Step 4. Run the "hello world" program

 

Step 5. Make it visual

 

Step 6. Explore the possibilities

import javax.swing.*;
import java.util.*;
import java.lang.*;

public class BubbleSort
{
   final private int N = 10;
   private String names[];
   private static Random rng = new Random();

   public BubbleSort()
   {
      initArray();
      printArray("Unsorted");
      sortArray();
      printArray("Sorted");
   }
	
   private void initArray()
   {
      names = new String[N];
      for (int i=0; i<N; i++)
      {
         names[i] = randomWord();
      }		
   }
	
   private void sortArray()
   {
      String temp;
      boolean swapped = true;
      while (swapped)
      {
         swapped = false;
         for (int i=1; i<N; i++)
         {
            if (names[i-1].compareTo(names[i]) > 0)
            {
               temp = names[i-1];
               names[i-1] = names[i];
               names[i] = temp;
               swapped = true;
            }
         }
      }
   }
	
   private void printArray(String type)
   {
      System.out.println(type + " array of " + N + " words");
      Object o[] = new Object[2];
      for (int i=0; i<N; i++)
      {
         System.out.println((i+1)+" "+names[i]);
      }
   }

   public String randomWord()
   {
      return randomString(5,5);
   }

   public String randomString(int lo, int hi)
   {
      int n = rand(lo, hi);
      byte b[] = new byte[n];
      for (int i = 0; i < n; i++)
      {
            b[i] = (byte)rand('a', 'z');
      }
      return new String(b);
   }

   public static int rand(int lo, int hi)
   {
      int n = hi - lo + 1;
      int i = rng.nextInt() % n;
      if (i < 0)
      {
         i = -i;
      }
      return lo + i;
   }

   public static void main(String[] args)
   {
      BubbleSort bs = new BubbleSort();
   }
}

 Learning more                                                        

There is a vast amount of information available on the Internet.  Some of the best sources are:

 QuickStart Presentation                                           

Download and view the QuickStart Java PowerPoint Presentation.

Back to QuickStart Languages