Packaging, Compiling, and Interpreting Java Code

Understand Package

Packaging is used to organize related types (classes, interfaces,…).

package X.Y.Z// Package statement

Exemple of the statements : package com.ojcp.tutorial

  • Package statements are optional and must be made at the top of source file (not including comments).
  • package name should be lowercase, cannot be the name of any java keyword.
  • Only one package declaration per source file.
  • If you omit the package keyword, then the compiler places the class in a default package.
  • Packaging helps managing large software systems and promotes code reuse.

Understand Class Structure

<modifiers> class classIdentifier <extends superClassIdentifier>

<implements interfaceIdentifier1, interfaceIdentifier2,…>  {

<data members>

<constructors>

<methods> }

Exemple of the statements :

Public class MyFirstClass extends MySecondClass implements MyFirstInterface,MySecondInterface {

public int x ;     // data memebers

private String s;

protected flaot f ;

MyFirstClass () {}      // Constructor with no paramater

MyFirstClass (int x, String s) {} // Constructor with two paramaters

public void play () {                             // method play

System.out.println(“Hello World !!!”); }

Leave a comment