Introduction to the Java Platform

The Java platform consists of the Java APIs and the Java Virtual Machine (JVM).
Java APIs are libraries of compiled code that you can use in your programs. They enable you to add ready-made and customizable functionality to save you programming time. The simple program below uses a Java API to print a line of text to the console. The printing capability is provided in the API ready for you to use. You supply the text to be printed.

javaarchitecture

Figure 1 shows the Java platform architecture. The JVM sits on top of your native operating system. Your program sits on top of the JVM and calls compiled code from the API libraries that are provided by the JVM.

Programs written in Java are run (or interpreted) by the JVM. If you have used Visual Basic or another interpreted language, this concept is probably familiar to you. Rather than running directly on the native operating system, the program is interpreted by the JVM for the native operating system. This means that any computer system with a JVM installed can run programs written in Java regardless of the computer system on which the applications were originally developed.

Create An Eclipse Project

  1. In Eclipse, select File > New > Project
  2. In the New Project dialog, select Java Project and click Next
  3. Name the project, ExampleProgram and click Finish
  4. If prompted to open the Java perspective, click Yes
  5. Expand ExampleProgram and right-click src
  6. Select New > Package
  7. Enter the name simple.program for the package name
  8. Click Finish
  9. Right-click simple.program and select New > Class
  10. Name the class, ExampleProgram and click Finish
  11. Copy the following code into the ExampleProgram class file. Replace the stub code currently in the ExampleProgram class file with the code below.
  12. File > Save

ExampleProgram class file:

package simple.program;

//A Very Simple Example
 class ExampleProgram {
   public static void main(String[] args){
     System.out.println("I am a Simple Program");
   }
 }

Run the Program

  1. To run the simple program, right click the ExampleProgram project name.
  2. Select Run As > Java Application
  3. Check the Console window in Eclipse to see the program output
console
Console Window in Eclipse where I am a Simple Program displays

ExampleProgram class file:

package simple.program;

//A Very Simple Example
 class ExampleProgram {
   public static void main(String[] args){
     System.out.println("I am a Simple Program");
   }
 }

Code Comments

Code comments are placed in source files to describe what is happening in the code to someone who might be reading the file, to comment-out lines of code, to isolate the source of a problem for debugging purposes, or to generate API documentation. to accommodate these needs, Java supports the following types of comments.

C++-Style Comments

You can use C++-style double slashes (//) to tell the compiler to treat everything from the slashes to the end of the line as text.

//A Very Simple Example
class ExampleProgram {
  public static void main(String[] args){
    System.out.println(“I am a Simple Program”);
  }
}

C-Style Comments

Instead of double slashes, you can use C-style comments (/* */) to enclose one or more lines of code to be treated as text.

/* These are C-style comments */
 class ExampleProgram {
   public static void main(String[] args){
     System.out.println(“I am a Simple Program”);
   }
 }

Doc Comments

To generate documentation for your program, use doc comments (/** */) to enclose lines of text for the javadoc tool to find. The javadoc tool locates the doc comments embedded in source files and uses those comments to generate API documentation.

/** This class displays a text string on the console. */
 class ExampleProgram {
   public static void main(String[] args){
     System.out.println(“I am a Simple Program”);
   }
 }
Advertisements
Introduction to the Java Platform

One thought on “Introduction to the Java Platform

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s