Lecture Notes: Introduction to Java

By Jack G. Zheng, CIS@Georgia State University

Last updated 6/12/2006

 

What is Java?

 

Where Java is used?

 

How popular is Java?

 

A little bit history

 

How does it work?

jvm
Figure from Java Tutorial http://java.sun.com/docs/books/tutorial/getStarted/intro/definition.html

 

 

Major features

 

 

Java Development Kit (JDK)


Figure from http://java.sun.com/j2se/1.5.0/docs/

 

J2EE 1.4 Container http://java.sun.com/j2ee/1.4/docs/tutorial/doc/

 

 

Major Java platform products and tools

 

First Simple Java Program

/* CIS3270 Lecture Java Basics Code Example
* Description: the first and the most simple Java program
* Author: Jack G. Zheng
* Date: August 24, 2005
*/

class HelloWorld
{

public static void main(String[] args) //main method is the starting point of a program
{

System.out.print("Hello, "); //console output
String s="World!"; //declaring a variable
System.out.print(s);

}

}

  1. Java source code file ends with ".java"
  2. Comment: /* ... */ or //
  3. Class declaration: every Java program is made up of classes
  4. Curly braces are used to define code blocks, usually used for class, method, conditional and iterative statements
  5. The main method is the starting point of a program
  6. Statement

 

 

Console output

class ConsoleOutput
{

static public void main(String[] args)
{

System.out.print("Hello");
System.out.print(", World");
System.out.print("\nHello\n"); // \n means new line
System.out.println("Hello!"); //println prints a line followed by a line break
System.out.println(); //this prints an empty line
System.out.print("H\te\tl\tl\to"); // \t means tab

}

}

 

 

Compiling and Running a Java Program

  1. "javac.exe" to compile a Java program
  2.  

  3. "java.exe" to run a Java class/program