Home : Course Map : Chapter 2 : Java : Structure
Basic Structure of a Java Program
JavaTech
Course Map
Chapter 2

Introduction
Essentials
Structure

Keywords
Primitive Types
Comments
Literals
Expressions
Operators
Statements
Casts & Mixing
Strings
Console Output 
   Demo
Exercises

    Supplements
Conditional: if-else
Repetitions
Flow Control

Java vs C/C++
JVM Instructions 1

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

As we saw in the applet and application examples in the first chapter, all Java programs are built within a class framework.

Note: You can begin to program in Java without understanding the details of object oriented code. Later chapters discuss classes and objects in detail. For now you can note the overall framework and then just concentrate on the code within a method and write programs just as if Java were a procedural language.

We provide program Starters in which you can simply insert example and exercise codes without dealing with the details of class design.

Below we show a simple example of a Java application program. In Java all coding occurs within a class definition like this. It begins with a class title line such as

public class SimpleApp1

followed by the members of the class enclosed within curly braces. The members include fields for data and methods, which are similar to functions or subroutines in other languages.

/*
 * A Simple application.
 */
public class SimpleApp1
{


 public static void main(String args[])
 {
 
   // A method to output to the console.
  
   
   System.out.println("Simple program");

 }
}

A comment describing
the program.

Begin with the class specification.


Required method for application programs.

Comment using 2 slashes.
 
Print to console.

Curly braces span the code for a class. They also bracket the code of a method.


Many details will vary and classes can be much longer and more complicated but this same basic framework holds for all Java programs.

Programmers in C/C++ will note the resemblance to the main method in those languages, though its argument is not a string array.

We will discuss in later chapters the meanings of the keywords "public", "static" and "void".

Latest update: Dec.11.2003

            Tech
Arithmetic Ops
Math Class
More on Integers
FP : Overview
FP : Java  
  
Demo 1
More Mix/Cast
  Demo 2
Exercises

           Physics
Differential Eq.
Euler Method
  
Demo 1
Predictor-Corrector
  
Demo 2
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.