Learning Java – Introduction

As a beginner in programming, the first thing I always do to put one through is to first explain explain the JVM, Source format and the IDE. This gives a basic understanding of what you are getting into and an idea of the structure on how it works.

Java is just another programming language (like c#, c) with more powerful features and more platform independent. Java runs on all the major OSs on PCs, laptops,Palm tops, tablets and mobile devices.

Firstly, you write you code/logic in a file and save it in file with .java extention (g.e Hello.java). This is an important step because this get starters really frustrated, you will really need to understand how to create a source file and how it works. Find a more detailed explanation below;

Source File Layout

Basic syntax of a Java source file:

[<package_declarations>]
[<import_declarations>]
<class_declarations>+

Example, the VehicleCapacityReport.java file

package shipping.reports;
import shipping.domain.*;
import java.util.List;
import java.io.*;

public class VehicleCapacityReport {
			private List vehicles;
			public void generateReport (Writer output) { . . . }
}

The package Statement

Basic syntax of the package statement

package <top_pkg_name> [.sub_pkg_name];

Examples:

package shipping.reports;

  • Specify the package declaration at the beginning of the source file
  • Only one package declaration per source file
  • If no package is declared, then the class “belongs” to the default package
  • Package names must be hierarchical and seperated by dots

The import Statement

Basic syntax of the import statement

import <pkg_name>[.sub_pkg_name>].<class_name>;

Or

import <pkg_name> [.<sub_pkg_name>].*;

Examples:

import shipping.domain.*;

import java.util.List;

import java.io.*;

  • Precedes all class declarations
  • Tells the compiler where to find classes to use

Leave a Reply

Your email address will not be published. Required fields are marked *