71
GENESIS OF JAVA & AN OVERVIEW SHASHI BHUSHAN SOCIS, IGNOU

GENESIS OF JAVA & AN OVERVIEW

Embed Size (px)

DESCRIPTION

GENESIS OF JAVA & AN OVERVIEW. SHASHI BHUSHAN SOCIS, IGNOU. TODAY’S AGENDA. GENESIS OF JAVA AN OVERVIEW OF JAVA. GENESIS OF JAVA. SOFTWARE DEVELOPMENT BURDEN THE WEB REVOLUTION NEW ORDER OF COMPUTING PHILOSOPHY OF JAVA AND DESIGN GOALS JAVA BUZZWORDS. GENESIS OF JAVA (CONTD..). - PowerPoint PPT Presentation

Citation preview

Page 1: GENESIS OF JAVA &  AN OVERVIEW

GENESIS OF JAVA &

AN OVERVIEW

SHASHI BHUSHANSOCIS, IGNOU

Page 2: GENESIS OF JAVA &  AN OVERVIEW

TODAY’S AGENDA

GENESIS OF JAVAAN OVERVIEW OF JAVA

Page 3: GENESIS OF JAVA &  AN OVERVIEW

GENESIS OF JAVASOFTWARE DEVELOPMENT BURDENTHE WEB REVOLUTIONNEW ORDER OF COMPUTINGPHILOSOPHY OF JAVA AND DESIGN

GOALSJAVA BUZZWORDS

Page 4: GENESIS OF JAVA &  AN OVERVIEW

GENESIS OF JAVA (CONTD..)

MULTIPLE INCOMPATIBLE HARDWARE ARCHITECTURE

MULTIPLE INCOMPATIBLE OPEARATING SYSTEM

INCOMPATIBLE GUI

SOFTWARE DEVELOPMENT BURDEN:

Page 5: GENESIS OF JAVA &  AN OVERVIEW

GENESIS OF JAVA(CONTD..)

GROWTH OF INTERNET, WWW AND ELECTRONIC COMMERCE

THE WEB RESOLUTION WHOSE KEYPOWER IS “WRITE ONCE AND RUN ANYWHERE” MODEL REQUIRED A NEW PARADIGM

Page 6: GENESIS OF JAVA &  AN OVERVIEW

GENESIS OF JAVA (CONTD..)

DATA ONLYINFORMATION IS STATICHTML IS NOT FLEXIBLELARGE NUMBER OF COMPUTING

PROTOCOLS AND STANDARDS

LIMITATIONS OF WEB TECHNOLOGY:

Page 7: GENESIS OF JAVA &  AN OVERVIEW

GENESIS OF JAVA (CONTD..)

JAVA PHILOSOPHY AND DESIGN GOALS “WRITE ONCE, RUN ANYWHERE ON ANY PLATEFORM”. THE NETWORK BECOMES THE DISTRIBUTION VEHICLE FOR S/W APPLICATION. IT MUST ENABLE THE DEVELOPMENT OF SECURE HIGH PERFORMANCE AND HIGHLY ROBUST APPLICATION ON MULTIPLE PLATFORM IN HETEROGENEOUS & DISTRIBUTED NETWORKS.

SUPPORT OF DYNAMIC ACTIVE PROGRAMS (APPLETS) FOR TRANSMISSION BETWEEN CLIENTS AND SERVERSATTATCHED TO INTERNET.

Page 8: GENESIS OF JAVA &  AN OVERVIEW

GENESIS OF JAVA (CONTD..)

AN APPLICATION IS A PROGRAM WHICH RUNS ON ANY COMPUTER UNDER THE OPERATING SYSTEM OF THAT COMPUTER. IT IS SIMILAR TO ANY APPLICATION PROGRAM CREATED BY C OR C++.

AN APPLET IS AN APPLICATION DESIGN TO BE TRANSMITTED OVER THE INTERNET AND EXECUTED BY JAVA COMPATIBLE BROWSERS. AN APPLET IS LIKE TINY JAVA PROGRAM DYNAMICALLY LOADED ACROSS THE NETWORK JUST LIKE AN IMAGE , SOUND FILE OR VIDEOCLIP.

APPLETS AND APPLICATIONS:

Page 9: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA

SIMPLE, FAMILIAR AND OBJECT ORIENTED ROBUST HIGH SECURITY ARCHITECTURE NEUTRAL AND PORTABLE MULTITHREADED HIGH PERFORMANCE DISTRIBUTED AND DYNAMIC

JAVA BUZZWORDS:

Page 10: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD..)

JAVA.LANG JAVA.IO JAVA.AWT JAVA.APPLET JAVA.SQL JAVA.NET JAVA.UTIL

JAVA API AND CORE LANGUAGE FUCTIONS:

Page 11: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD..)

NO MORE TYPEDEFS, OR PREPROCESSOR NO MORE STRUCTURE OR UNIONS NO MORE MULTIPLE INHERITANCE NO MORE GOTO STSTEMENTS NO MORE AUTOMATIC COERSIONS NO MORE POINTERS NO MORE POINTER ARITHMETICS

FETURES REMOVED FROM C & C++

Page 12: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD..)

THE FIRST SAMPLE PROGRAM:

/*

Using a text editor create a file named HelloWorld. java with the java code shown below*/

class HelloWorld {public static void main (String[ ] args) {System.out.println (“HelloWorld”); //display the string }}

Page 13: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD..)

Compiling the source file using the JDK

• Javac HelloWorld.java The compiler creates a file named HelloWorld. Class in the same directory as the java source file HelloWorld.java. The class file contains platform independent java bytecodes.

Run the application

• java HelloWorld

Page 14: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD..)

The System Class

• Member of the Java.lang package provides access to the system functionality such as standard I/O, copying arrays, getting the current date and time provides access to externally defined properties, means of loading files and libraries.

• System.out is a class variable that is a reference to an object implementing the standard output stream.

Page 15: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD..)

The System Class

• System.in is a class variable that is a reference to an object implementing standard input stream.

• System.err implements the standard error system.

• System class can not be instantiated.

Page 16: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA CONTD..

NUMERIC DATA TYPES & CHARACTER DATA TYPES

BOOLEAN TYPES ARRAYS

MAIN FEATURES OF THE JAVA LANGUAGE:

JAVA FOLLOWS C & C++ FAIRLY CLOSELY IN ITS SET OF BASIC DATA TYPES. THERE ARE ONLY THREE GROUPS OF PRIMITIVE DATA TYPES, NAMELY:

Page 17: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA CONTD..

BYTE - 8 BIT SIGNED QUANTITYSHORT - 16 BIT SIGNED QUANTITY INT - 32 BIT SIGNED QUANTITYFLOAT - 32 BIT IEEE 754 SPECIFICATIONLONG - 64 BIT SIGNED QUANTITYCHARACTER DATA TYPE - 16 BIT UNICODE

CHAR

NUMERIC DATA TYPES:

Page 18: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA CONTD..

BOOLEAN DATA TYPES AND ARITHMETIC & RELATIONAL OPEARTORS:

A JAVA BOOLEAN IS A DISTINCT DATA TYPE (TRUE OR FALSE) UNLIKE COMMON ‘C’ PRACTICE. A JAVA BOOLEAN TYPE CANNOT BE CONVERTED TO ANY NUMERIC TYPE 1 OR 0.

Page 19: GENESIS OF JAVA &  AN OVERVIEW

BOOLEAN DATA TYPES AND ARITHMETIC & RELATIONAL

OPEARTORS (CONTD..) :

ARITHMETIC & RELATIONAL OPEARTORS ARE :

• SIMILAR TO ‘C’ OR ‘C++’

• >>> INDICATES UNSIGNED (LOGICAL) RIGHT

• + IS USED TO COMBINE TWO SHIFTS STRINGS

• System.out.println (“THERE ARE” + num + “CHARS IN A FILE”)

Page 20: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

// a single dimension array of ints

• Syntax in Java is much the same as in C.• Arrays are (references to) objects• new operator is used to create an array• Indexed with any integer type primitive

int numbers[ ] = new int[10];int [ ] numbers = new int[10];• Array’s size can not be changed after it is created• For dynamically sized array, java.util.Vector class is

used

ARRAYS :

Page 21: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

ARRAYS :

All arrays have instance variable length which hold the size of the array.

class Length {public static void main(String[ ] args){

int a1[ ] = new int [10];int a2[ ] = {3, 5, 7, 1, 8, 99, 44};

System.out.println (“length of a1 is” + a1.length)System.out.println (“length of a2 is” + a2.length);}}

Page 22: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

ARRAYS OF OBJECTS :

Arrays can contain any legal java data types including reference types such as object or other arrays. For example, the following declares an array of ten String objects.

String[ ] arrayofStrings = new String[10];

Page 23: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

ARRAYS OF OBJECTS (Contd...):

The element in this array are reference types that is, each element contains a reference to a String object. At this point, enough memory has been allocated to contain String references but no memory has been allocated for the String objects themselves. If you attempt to access one of the array of Strings elements at this point, you will get NullpointerException because the array is empty and contains no String objects.

Page 24: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

ARRAYS (Command line arguments explained):

Explanation: This simple application displays each of its command line arguments on a line by itself. class Echo{ public static void main (String[ ] args) { for (int i = 0; i<args.length; i++)

System.out.println (args [i] ); }

}

Page 25: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

STRING:

A sequence of char data is called a string and is implementd in the java environment by the String class (a member of the java.lang package).

The following statement explicitly declares an array named args that contains String objects. The empty bracket indicates that the lenght of the array is unknown at compilation time because the array is passed in at run time.

(String[ ] args) //declared with the main( )“IGNOU” // literal strings“IGNOU”+ ”Conducts” + ”Java” + “Seminar”

Page 26: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD..) :

STRINGS:

• STRING CLASS IS A JAVA CLASS. AN INSTANCE OF A STRING CLASS IS OF COURSE AN OBJECT. IN JAVA EACH AND EVERY STRING IS AN OBJECT.

• STRINGS ARE NOT ARRAY OF CHARACTERS IN JAVA AS C-LANGUAGE.

Page 27: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

STRING:

String class methods:booleans equals (String object)

int length ( ) char charAt(int index)

Page 28: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

STRING:

EXAMPLE 1: String methods

class Stringmethods{public static void main ( String[ ] args){ string strobj1 = “first string”; string strobj2 = “second string”; string strobj3 = strobj1; System.out.println (“Length of Strobj1:” + Strobj1.length( )); System.out.println (“Char at index 3 in strolbj1:”+strobj1.charAt (3));If (strobj1.equals (strobj2)) System.out.println (“strobj1 == strobj2”);else System.out.println (“strobj1!= strobj2”); } }

Page 29: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

STRING:EXAMPLE :Character counting program

class CountChar{public static void main(String[ ] args) { throws java.io.IOException {

int count = 0; while(System.in.read( )!= -1)

count++; System.out.println(“Input has”+counts+”chars”);

}}

Page 30: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

EXPLANATION : Throws java.io.exception

This statement specifies that the main method can throw an exception called java.io.IOException. An exception is an event that occurs during the execution of a program that prevents the continuation of the normal flow of instructions.

•Main method does not throw any exception directly. But it can throw a java.io.IOException indirectly throgh its call to System.in.read.

Page 31: GENESIS OF JAVA &  AN OVERVIEW

AN OVERVIEW OF JAVA (CONTD...)

System.in.read

This method reads a single char and returns either the char that was read or, if there are no more characters to be read, -1.

Page 32: GENESIS OF JAVA &  AN OVERVIEW

FLOW CONTROL STATEMENTS

SWITCH SYNTAX SWITCH STATEMENT IS IDENTICAL TO 'C'

Switch (expression){case value1:

statement(s);break;

case value2:statement(s);break;

default:statement(s);break;

}

AN OVERVIEW OF JAVA (CONTD...)

Page 33: GENESIS OF JAVA &  AN OVERVIEW

Breaking out of Loops Break Continue Break & Continue with Label Without the Label, they are the same as C or

C++

FLOW CONTROL STATEMENTS (Contd. …)

AN OVERVIEW OF JAVA (CONTD...)

Page 34: GENESIS OF JAVA &  AN OVERVIEW

Date tomorrow = new Date( );

This single statement actually performs three functions:

Declaration :

Instantiation:

Initialisation

Creating, Declaring & Instantiating an object:

OBJECT ORIENTED PROGRAMMING IN JAVA

Page 35: GENESIS OF JAVA &  AN OVERVIEW

Date tomorrow;

Instantiation of an object:

The new operator instantiates a class by allocating memory for a new object of that type. The new requires a single argument: a call to a constructor method.

Declaration of an object:

OBJECT ORIENTED PROGRAMMING IN JAVA (Contd....)

Page 36: GENESIS OF JAVA &  AN OVERVIEW

Constructor methods are special methods provided by each Java class that are responsible for initializing new objects of that type. The new operator creates the object and the constructor initializes it.

The Date( ) Constructor used in

Date tomorrow = new Date( ) does not take any argument.

Declaration of an object:

OBJECT ORIENTED PROGRAMMING IN JAVA (Contd...)

Page 37: GENESIS OF JAVA &  AN OVERVIEW

A constructor that takes no argument is called default constructor. Like Date( ), most classes have at least one default constructor.

If a class has multiple constructors, they all have the same name but different number or types of arguments. Date class type provides with another constructor that initialises the new Date with a year, month & day.

Date HisBirthday = new(1971, 6, 30);

OBJECT ORIENTED PROGRAMMING IN JAVA (Contd...)

Page 38: GENESIS OF JAVA &  AN OVERVIEW

No need of keeping track of objects for destroying.

The Java runtime environment has a garbage collector that frees the memory used by objects that are no longer needed.

AN OVERVIEW OF JAVA (Contd...)

OOP : GARBAGE COLLECTOR

Page 39: GENESIS OF JAVA &  AN OVERVIEW

An object is eligible for garbage collection when there are no more references to objects.

The garbage collector run in a low-priority thread and runs both synchronously and asynchronously depending on the situation and the system on which Java is running.

AN OVERVIEW OF JAVA (Contd...)

OOP : GARBAGE COLLECTOR

Page 40: GENESIS OF JAVA &  AN OVERVIEW

A class declaration looks like this:[modifiers] class ClassName [extends SuperClassName]

[implements Interface Names]{--------}

The items between the square are optional.modifiers declares whether the class is public, abstract or

final. extends is used to specify a single inheritance mechanism. Implements is used to specify multiple inheritance.

AN OVERVIEW OF JAVA (Contd...)

OOP : CLASS DECLARATION

Page 41: GENESIS OF JAVA &  AN OVERVIEW

In Java, every class has a superclass. If you don’t specify a superclass for your class it is assumed to be the Object class (declared in Java.lang).

The keyword extends is used to specify the superclass.

Class NameOfClass extends SuperClassName {

----------

----------

}

AN OVERVIEW OF JAVA (Contd...)

OOP : Declaring a class’s superclass

Page 42: GENESIS OF JAVA &  AN OVERVIEW

The Public modifier declares that the class can be used by objects outside the current package.

The abstract modifiers declares that the abstract class may contain methods (without any implementation). These classes are intended to be sub-classed and can not be instantiated.

AN OVERVIEW OF JAVA (Contd...)

OOP : Public, Abstract and Final Class

Page 43: GENESIS OF JAVA &  AN OVERVIEW

The Final modifier declares that this class can not be sub-classed for security reasons & design reasons.

It does not make sense for a class to be both final and abstract.

AN OVERVIEW OF JAVA (Contd...)

OOP : Public, Abstract and Final Class (Contd...)

Page 44: GENESIS OF JAVA &  AN OVERVIEW

Object Oriented Program Package:

A package is a container of related classes and interfaces

Used to access related classes as well as to hide the internals of a package

Package is declared using package keyword Package my-package; Package java.awt.image; All of Java built-in classes are put under the Java

package. Six sub packages are defined under the Java package

Java.lang, Java.awt, Java.io, Java.net, Java.applet, Java.util

AN OVERVIEW OF JAVA (CONTD...)

Page 45: GENESIS OF JAVA &  AN OVERVIEW

Object Oriented Feature (Contd. …)

The Import Statement The Import statement loads existing classes for

using their definition and methods

Example: Importing the class from the package: import

Java.awt.Graphics; Importing the entire package that the class belongs

to:

Import Java.awt.*.

AN OVERVIEW OF JAVA (CONTD...)

Page 46: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW(CONTD…)OOP : Access control mechanism:PRIVATEPROTECTEDPUBLICSTATICFINALABSTRACT

Page 47: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)

OOP : Access control mechanism: PRIVATE:A PRIVATE MEMBER AND METHOD

ARE ACCESSIBLE ONLY TO THE CLASS IN WHICH IT IS DEFINED.

EXAMPLE: class Alpha { private int privateX;

private void privateMethod( ){System.out.println(“PrivateMethod”);}} Contd. ...

Page 48: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)

OOP : Access control mechanism: PRIVATE:Class Beta {void accessMethod ( ) {Alpha a = new Alpha ( ) ;a.privateX = 15; // illegala.privateMethod ( ) ; // illegal}}

Beta class cannot access private variable and private methods on an object of type Alpha because Beta is not the type of Alpha.

Page 49: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)OOP : Access control mechanism: PRIVATE: objects of same type can access to one another’s private members This is because access restriction apply at the class or type level rather than at the object level.example:class Alpha {private int privateX ;boolean isEqualTo (Alpha anotherAlpha) {if (this.privateX= =anotherAlpha.privateX) //legalreturn true;else return false;}}this is a java language keyword that refers to the current object.

Page 50: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)

Protected It allows the class itself, subclasses anc all classes in the same package to access the members. Package Greek ;

Class Alpha { //declared in a Greek packageprotected int protectX ;protected void protectedMethods ( ) {system.out.println(“protectedMethods” ) }} Contd. ...

Page 51: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)

Protected Suppose class Gama is also declared to the member of the Greek package. The class can legally access an alpha object’s privateX member variable and protected. Methods Package Greek ;

Class Gamma{void access Method ( ) {Alpha a = new Alpha ( ) ;a.protectX=10; // legala.protectedMethod ( ) ; // legal}}

Page 52: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Public Any class in any package has access to class’s public member. Declare members to be public only if such access cann’t produce undesirable results if an outsider uses them.Package Greek ;public class Alpha {

public int publicX;public void publicMethod ( ) {System.out.println (“publicMethod”);}

}

Contd. ...

Page 53: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Public Beta class is defined ina different package and not a sub class of Alpha.Package Roman ;import Greek.*;

Class Beta {void accessMethod ( ) {Alpha a=new Alpha ( ) ;a.publicX = 10; // legala.publicMethod ( ) ; // legal}

}Beta can legally inspect and modify the public X and public method in Alpha class.

Page 54: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)OOP : What Method does subclass inherit

Subclasses inherit those superclass method declared as public or protected

SubClass inherit those superclass methods declared with no acces specifier as long as the subclass is in the same package as the superclass

Subclass don’t inherit a superclass’s method if the subclass declares a method using the same name. The method in the subclass is said to override the one in the superclass.

Subclass do not inherit the superclass private methods

Page 55: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Static Used with methods and variables but not with

classes

used to specify a method that can be declared only once such as main ( )

no sub classes are allowed to implement the method of the same name

static methods are not over ridden in subclasses

Page 56: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Final Used with classes, methods and variables

when used with a class this class never have any subclass

when used with any method, this method cannot overridden.

When used with any member variable the variable remains constant.

Contd ...

Page 57: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Final

example 1: // final used with a classfinal class classFinal {

::

}class classInherited extends classFinal{ // illegal

:}

Contd ...

Page 58: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Final (Contd...)

example 2:class NeverChanging {// a Final variableFinal int unchangeble = 21;// a Final methodFinal int unchangingMethod (int a, int b) {}}It defines a complete programming interface, providing its subclasses with the method declaration for all of the methods necessary to support the interface.

Page 59: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Abstract classes & methods

An abstract class is a class that can only be sub-classed - it can not be instantiated.

It contains abstract methods with no implementation. It defines abstract methods.

Used to create a template class or methods. Similar to function prototypes in C or C++.

Page 60: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Abstract classes & methods

abstract class GraphicsObject {int x , y;:void moveTo (int newX, int newY) {:}abstract void draw ( ) ; // to be implemented by all

// subclasses}

Contd. ...

Page 61: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)Abstract classes & methodsEach non-abstract subclass of Graphic object such as circle and rectangle has to provide an implementation for the draw method.

class Circle extends GraphicObject {void draw ( ) {:}

}class Rectangle extends GraphicObject {

void draw ( ) {:}}

An abstract class is not required to have an abstract method in it. But any class that has an abstract method in it or does not provide an implementation, any abstract method declared in its superclass must be declared as an abstract class.

Page 62: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)OOP : Interface An interface is a collection of abstract methods

(without implementations) and constant values

Interfaces add most of the functionality that is required for many applications which would normally resort to using multiple inheritance in a language such as C++

Java program can use interface to make it unnecessary for related classes to share a common abstract super class to add methods to object

Contd. …

Page 63: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)OOP : Interface Accessing multiple implementation of an interface

through an interface reference variable is the most powerful way that Java achieves run-time polymorphism.

Because dynamic lookup of a method at run-time incurs a significant overhead when compared with normal method invocation in java, you should be careful not to use interfaces casually in performance critical code.

Contd. …

Page 64: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD…)

OOP : Interface

A class may be declared to directly implement one or more interfaces, meaning that any instance of the class implements all the abstract methods specified by the interface or interfaces.

Contd. …

Page 65: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD...)

OOP : Interface Declaration

interface Countable { the interface body; }

[Public] interface InterfaceName [extends list of SuperInterfaces]{ the interface body ------- }

Page 66: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD...)

OOP : Interface

The public access specifies indicates that the interface can be used by any class in any package. If you do not specify that your interface is public, then your interface will only be accessible to classes that are defined in the same package as the interface.

Page 67: GENESIS OF JAVA &  AN OVERVIEW

OOP : Interface The extends clause is similar to the extends clause in a class declaration. However an interface can extend multiple interface (a class can only extend one), and an interface cannot extend classes.

JAVA OVERVIEW (CONTD...)

Page 68: GENESIS OF JAVA &  AN OVERVIEW

JAVA OVERVIEW (CONTD...)

OOP : Interface Example

interface Collection{

int MAXIMUM = 500;

void add (Object obj);

void delete (Object obj);

int currentCount( );

}

Page 69: GENESIS OF JAVA &  AN OVERVIEW

class TestStack{public stack void main (String [ ] args) {Stack mystack1 = new Stack(l0); Stack mystack2 = new Stack (8); // push some members onto the stack for (int i=0; i<10, i++) mystack1.push (i); for (int i=0; i<8, i++) mystack2.push (i);// pop off the stackfor (int i=0; i< 10; i++)System.out.println(mystack1.pop( ) );}}

Stack

AN OVERVIEW OF JAVA (CONTD...)

Page 70: GENESIS OF JAVA &  AN OVERVIEW

Recursionclass Factorial {// This is a recursive function int fact (int n) {int result,if (n==1) return 1; elseresult = n * fact(n- 1);return result;}}

AN OVERVIEW OF JAVA (CONTD...)

Page 71: GENESIS OF JAVA &  AN OVERVIEW

class Recursion {public static void main(String args [ ] {Factorial f = new Factorial( );System.out.println ("factorial of 3 is" +f.fact(3));}}

AN OVERVIEW OF JAVA (CONTD...)