Skip to main content

Popular posts from this blog

Java Basics Quick Review with examples

Java Programming Language High Level Strongly Typed means no automatic type conversions in java like C++ Case Sensitive Successor of c++ Pure Object Oriented Language  Hello World Problem in java class Test{ public static void main(String a[]) { System.out.println("Hello World");  } } More than one Classes class Test1{ void print () { System.out.println("Test class"); } } class Test{ public static void main(String a[]) { Test1 t=new Test1(); t.print();  } } Rule of Thumb: Don't write extra functions in driver class  Extra function and data in driver class  class Test{ int sq(int p){    return p*p; } public static void main(String a[]) {     Test t = new Test(); System.out.println(t.sq(4));  } } .................................. call without object instantiation .................................. class Test{ static int sq(int p){    return p*p; } public static voi...

Composition in Java with code examples

Composition  "Have a " Relationship  OR  "Must have" relationship                    between two or more classes. Container class contains component's class object For example a  Car is composed of engine and body. Where Car is a container class and both Engine and Body are components class.  Life Time Issue in Composition Life time of component objects depends on container class If Container object destroyed, component objects will be also destroyed Car Example  There is a composition relationship between car's body and engine. Car must have Engine and body If Car destroyed, both Engine and Body will be destroyed class  Engine {   Engine  () {    System.out.println ( "Engine created" ) ; }   void  start () {    System.out.println ( "Engine Start" ) ;   } } class  Body...

Association in Java Programming

What is Association in java Relationship between one or more classes Aggregation and composition is a special type of association For example,  Student Belongs to a specific Faculty and  One faculty has many students Code Example: class  Student  {    String name;    Student  () { name= null ;  }    Student  ( String n ) { name=n;  }    void  setName ( String n ) { name=n; }    String getName () {  return  name; } } class  Faculty {    Student student [] ;    int  size;    Faculty  ( int  s ){ size= 0 ;             student= new  Student [ s ] ; } void  belongsTo ( Student p ){      student [ size ] =p;      size++; } void  prin...