An Overview Of Java




Object Oriented Programming
Object Oriented Programming (OOPs) is an extension of the concept of structured programming. It specifies that a program is composed of objects that contain both data and procedures that act on that data.
Properties of OOPs
Abstraction
An essential element of object oriented programming is abstraction. Human manages complexity through abstraction. People do not think of a car as a set of tens of thousands of individual parts. They think of it as a well defined object with its own unique behavior.
Three Principles of OOPS
All object-oriented programming languages provide mechanisms that help you implement the object oriented model. They are encapsulation, inheritance and polymorphism.
Encapsulation
Encapsulation is the mechanism that binds together code and data it manipulates and keep both safe from outside interference and misuse.


Inheritance
Inheritance is the process by which one object acquires the properties of another object. This is important because it supports the concept of hierarchical classification. As mentioned earlier, most knowledge is made manageable by hierarchical (top-down) classifications.
Animal

Mammal

Dog
Polymorphism
Polymorphism is a feature that allows one interface to be used for a general class of actions.
Vehicles are of different types. School bus, Mercedes etc.
Vehicle
First Sample program
class Example{
Public static void main(String args[]){
System.out.println(“This is a simple java program”);
}
}
Example.java
C:/> javac Example.javaC:/> java Example
Javac compiler creates a file called Example.class that contains the bytecode version of the program.

Second program
class Example {
Public static void main(String args[]){
int num;
num=100;
System.out.println(“This is num ”+num); num=num*2;
System.out.println(“ The value of num*2 is”+ num);



output

The if Statement:
The if else construct is also known as the conditional control structure or the selection structure because it checks for a given condition and based on the result of the condition selects a particular action or just ignores it.

if(condition) statement;
condition is a boolean expression. If condition is true, then the statement is executed. If condition is false, then the statement is bypassed.
if( num<100)println(“num is less than 100”);
Relational operators which may be used in a conditional expression.


class Ifsample {
public static void main(String args[]){
int x,y;
x=10;y=20;
if(xx=x+2;
if(x==y) System.out.println(x now equal to y”);
X=x*2;
If(x>y) System.out.println(x now greater than y”);
If(x==y) System.out.println(“ you wont see this”);
}
}

Comments

Popular posts from this blog

Why to do a POC (Proof Of Concept)