Tuesday, 31 August 2010

Module 2: Introduction to OOP

In manufacturing, a blueprint describes a device from which many physical devices are constructed.
In Java, a class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviors. Java class objects exhibit the properties and behaviors defined by its class. A class can contain fields and methods to describe the behavior of an object.

Declaring Java Technology Classes

Basic syntax of a Java class:

<modifiers> class <class_name> {
  [<attribute_declarations>]
  [<constructor_declarations>]
  [<method_declarations>]
}


Methods are nothing but members of a class that provide a service for an object or perform some business logic. Java fields and member functions names are case sensitive. Current states of a class’s corresponding object are stored in the object’s instance variables. Methods define the operations that can be performed in java programming.


Basic syntax of an attribute:

<modifiers> <type> <name>;


Basic syntax of a method:
<modifiers> <return_type> <name>
([<argument_list>]) {
[<statements>]
}

Examples:

public class Dog {
  private int weight;
  public int getWeight() {
    return weight;
  }
  public void setWeight(int newWeight) {
    weight = newWeight;
  }
}


Example of class definition


public class Foo {
  private int x;
  private float y = 10000.0F;
  private String name = "Motel";
}

Thursday, 19 August 2010

Module 01: Getting started

Primary Goals of the Java Programming Language
  • Provides an easy-to-use language by
  1. Avoiding the pitfalls of other languages
  2. Being object-oriented
  3. Enabling users to create streamlined and clear code
  • Provides an interpreted environment for:
  1. Improved speed of development
  2. Code portability
  • Enables users to run more than one thread of activity
  • Loads classes dynamically, that is, at the time they are actually needed
  • Provides better security
The following features fulfill these goals
  • The Java Virtual Machine (JVM)
    • Provides hardware platform specifications
    • Reads compiled byte codes that are platform independent
    • Is implemented as software or hardware
    • Is implemented in a Java technology development tool or a Web browser
  • Garbage Collection
  • Code Security

Saturday, 7 August 2010

First tutorial

First Java progrm:


public class HelloWorld{

  public static void main(String[] args) {
     System.out.println("Hello, World!");
  }

}


To compile:
>javac HelloWorld.java
To Run:
>java HelloWorld