Saturday 30 July 2011

Caller Class will use both Classes Object in Main Method


class Caller{
public static void main(String m[]){
//The commented code can be run  by removing the // sign from each line
//String myname;
//int myage;
//Human h=new Human();
//h.setAge(20);
//h.setName("Mamoon");
//System.out.println("Your age"+h.Age+"\n"+"your Name"+h.Name);
//System.out.println(h.getAge());
//System.out.println(h.getName());
//myage=h.getAge();
//myname=h.getName();
//System.out.println("Age:"+myage+"\n"+"Name:"+myname);

    Student s =new  Student();
      s.Age=32;
     int x= s.getAge();
   System.out.println("Age:"+x);

}// end of void
}//end of main

Student Class which will inherit the Human class as Parent


class Student extends Human{
int RollNo;
String ClassName;
public void setRollNo(int r){
RollNo=r;
}//end of set
public int getRollNo(){
return RollNo;
}// end of get


public void setClassName(String s){
ClassName=s;
}//end of set
public String getClassName(){
return ClassName;
}// end of get







}//end of main

Concept of Inheritance in Java


//create a class Human  in java
class Human{
String Name;
int Age;
public void setAge(int a){
Age=a;
}//end of set
public int getAge(){
return Age;
}// end of get

public void setName(String n){
Name=n;
}// end of set

public String getName()
{
return Name;
}// end of get


}//end of main class

Tuesday 26 July 2011

Your First Programe in Java

class FirstPro{

public static void main(String agr[]){
System.out.println("Welcome to  your First Java Programe");
}

}

Explaination:- class is keyword for defination a class in java on which we create multiple object of this class.

public is a acess modifier which means this function is public for all datamember of the class.
static keyword is used to associate the function with class and not with its object,here main() is function which is public as well as statics which means datamember and datafunction can access it and can use it which class name like this First.functionName()// here fucnitonName is a static function. you dont need to creat an object of the class to call a static function.

void keyword mean  function will not return us any keyword.


compile the programe with javac the compiler of the javalanguage comes with jkd1.6// you may download it form web.
javac FirstPro.java
java FirstPro // do this commad to run the programe in  DOS Environment.

Monday 25 July 2011

What is a Class,Object and Inheritance.

Class:- The Image of  an object is class class. When you create a class you create a you own DATA Type.
ForExample:- if  I write int x it means, variable x will have an integer type. When you create Human Class  then I can write  Human  h;  It mean  h is a variable which can have the data of Human type.


Objects:- Any thing which will have properties and functions. The  Human Object, of class Human will have the properties like age,name,color; and function will setAge(), setName(), getAge(), getName();


Inheritance:- Is explained as two type of relationships 1)IS A relation ship 2) Has a relationship. For example the java class  as follow explains is a  relationship;
that is:-; Class Student extends Human{ } 
you can read it as  Student is a Human. This concept is class association.


On the other hand,

if you write  Class Student {

 Human h=new Human();      //This is called aggregation concept. That is the has a relationship which
                                            //mean Student class has a  Human class object. 
}

Friday 22 July 2011

Dear students,
To have good understanding of Object Oriented Programming you must understand about Objects.
Object are real world entities or thing.

Objects:- An object Must have some properties and function associated to it. Forexample  If We take Human as an object then Any Human  should my properties like:- Age,Name,Color, Height-

Functions:- Are defined as Opertations which are made to define and assign some value to the properties of an object. Forexample if I define some function associated to Human Object then they may have some implementation like.
 setAge(int a){ Age=a;}
setName(String name){Name=name;}
setColor(String c){Color=c;}
setHeight(int h){Height=h;}

Wednesday 20 July 2011

Java Lecturer Basic

Java is an object Oriented Language, Object are things in real world for example Human is an object because Human has both Properties and Function. That is an  a Human will have  Name, age, Height act as properties and Eating , Seeing, and Walking will  be the function performed by the Human, I can say that If I make a Human Class in Java. It will have Name, Age, and Height as attributes or properties. And the Eating (), seeing (), Walking () will act as the function of the Human Class. On the basis of this class I can make many objects of Human Class. The Simple syntax of Human class will be as follows.

class Human{
String Name;
int Age;
int Height;


setName(String name){ Name=name;}

setAge(int a){Age=age;}

setHeight(int h) {Height=h;}

}