Invented and first implemented by Dennis Ritchie on a DEC PDP-11 running the UNIX operating system, C was the result of a development process that started with an older language called BCPL, developed by Martin Richards. BCPL influenced a language called B, invented by Ken Thompson, which led to the development of C
C is not good for lengthy programs so C++ is response to decrease the complexity of programs has driven the objects and communicated each others
C, C++ program for
just about any type of CPU, to do so require a full C++ compiler targeted for
that CPU. The problem is that compilers are expensive and time-consuming to
create. “JAVA” was designed to solve a certain set of problems.
Byte code is a highly optimized set of instructions designed to be executed
by the Java run-time system, which is called the Java Virtual Machine (JVM).
JVM will differ from platform to plat form , all interpret the same Java byte code
Java program is interpreted also helps to make it secure. Because the execution of every Java program is under the control of the JVM. When the JIT compiler is part of the JVM, it compiles byte code into executable code in real time, on a piece-by-piece, demand basis. Just-in-time approach still yields a significant performance boost.
Byte code is a highly optimized set of instructions designed to be executed
by the Java run-time system, which is called the Java Virtual Machine (JVM).
JVM will differ from platform to plat form , all interpret the same Java byte code
Java program is interpreted also helps to make it secure. Because the execution of every Java program is under the control of the JVM. When the JIT compiler is part of the JVM, it compiles byte code into executable code in real time, on a piece-by-piece, demand basis. Just-in-time approach still yields a significant performance boost.
OOPSCONCEPT IN JAVA
An object-oriented program can be characterized as data controlling access to code.
Abstraction:
Hidden information about the objects. objects as concrete entities that respond to messages telling them to do something. This is the essence of object-oriented programming.
Encapsulation:
Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps 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.
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.
Polymorphism:
Polymorphism (from the Greek, meaning “many forms”) is a feature that allows one interface to be used for a general class of actions.
CLASS:
A class describes all the attributes of objects, as well as the methods that implement the behavior of member objects. It’s a comprehensive data type which represents a blue print of objects. A template that describes the kinds of state and behavior that objects of its type support.
OBJECT:
An object is an entity
that has attributes, behavior, and identity. Objects are members of a class.
Attributes and behavior of an object are defined
by the class definition At runtime, when the Java Virtual Machine (JVM) encounters the new keyword, it will use the appropriate class to make an object which is an instance of that class.
by the class definition At runtime, when the Java Virtual Machine (JVM) encounters the new keyword, it will use the appropriate class to make an object which is an instance of that class.
***SAMPLE PROGRAM***
class Example {
// Your program begins with a call to main ().
public static void main(String args[]) {
// main( ) must be declared as public, since it must be called by code outside of
// Your program begins with a call to main ().
public static void main(String args[]) {
// main( ) must be declared as public, since it must be called by code outside of
//its class when the program is started Static -instantiate a particular instance of the class
//args receives any command-line argumentspresent when the program is executed.
System.out.println("This is a simple Java program.");
//System is a predefined class that provides access to the system, and out is the output stream that is connected to the console. println ( ) displays the string which is passed to it
}
}
//args receives any command-line argumentspresent when the program is executed.
System.out.println("This is a simple Java program.");
//System is a predefined class that provides access to the system, and out is the output stream that is connected to the console. println ( ) displays the string which is passed to it
}
}
Source File Name: Example.java
Compile: javac Example.java
Run: java Example
Compile: javac Example.java
Run: java Example
APPLET:
An applet is an application designed to be transmitted over the Internet and executed by a Java-compatible Web browser. An applet is actually a tiny Java program, dynamically downloaded across the network, just like an image, sound file, or video clip.
MULTITHREADING:
Multi threading is process of program’s are executed simultaneously without effecting any system crashes. The Java run-time system comes with an elegant yet sophisticated solution for multiprocess synchronization that enables you to construct smoothly running interactive systems.
KEY WORDS
abstract continue goto package synchronized
assert default if private this
boolean do implements protected throw
break double import public throws
byte else instanceof return transient
case extends int short try
catch final interface static void
char finally long strictfp volatile
class float native super while
const new switch
DATA TYPE:
INTRGER
FLOAT
BOOLEAN
byte 16 long 64
float 32 char 8
int 32
int 32
DECLARE THE VARIABLE / ARRAY DECLARATION IN JAVA
Variable is identifier its holds a value
int a; a has integer type
Assigned a value to variable
a=10;
Type Casting:
var=(type)var
ARRAY:
int a[]=new in[12]
char[][] name=new char[][]
class classname {
type instance-variable1;
type instance-variable2;
// ...
type instance-variableN;
type methodname1(parameter-list) {
// body of method
}
type methodname2(parameter-list) {
// body of method
JAVA LANGUAGE
}
// ...
type methodnameN(parameter-list) {
// body of method
}
}
The data, or variables, defined within a class are called instance
variables. The code
is contained within methods. Collectively,
the methods and variables defined within
a
class are called members of the class.
class
Satya
{
double a;
double b;
double c;
}
class
Learn1
{
public static void main(String s[])
{
Satya
s=new Satya(); //create instance of the class
double tot;
s.a=10;
s.b=12;
s.c=15;
tot=s.axs.bxs.c;
System.out.println(“total=”+tot);
} }
//
create one r more instances
class
Satya
{
double a;
double b;
double c;
}
class
Learn1
{
public static void main(String s[])
{
Satya
s=new Satya(); //create instance of the class
Satya
s1=new Satya();
double tot;
s.a=10;
s.b=12;
s.c=15;
s1.a=10;
s1.b=12;
s1.c=15;
tot=s.a
x s.b x s.c;
System.out.println(“total=”+tot);
tot=s1.a x s1.b x s1.c;
System.out.println(“total=”+tot);
} }
//
using a member mehtod
class
Satya
{
double a;
double b;
double c;
vod
method()
{
System.out.println(“total=”+
(a*b*c));
}
}
class
Learn1
{
public static void main(String s[])
{
Satya
s=new Satya(); //create instance of the class
Satya
s1=new Satya();
s.a=10;
s.b=12;
s.c=15;
s1.a=10;
s1.b=12;
s1.c=15;
s.method();
s1.method();
} }
//
method with return type
class
Satya
{
double a;
double b;
double c;
double
method()
{
return (a*b*c));
}
}
class
Learn1
{
public static void main(String s[])
{
Satya
s=new Satya(); //create instance of the class
Satya
s1=new Satya();
double
tot;
s.a=10;
s.b=12;
s.c=15;
s1.a=10;
s1.b=12;
s1.c=15;
tot=s.method();
System.out.println(“total=”+tot);
s1.method();
System.out.println(“total=”+tot);
} }
//
parameterized method
class
Satya
{
double a;
double b;
double c;
double
method()
{
return (a*b*c));
}
void
setValue(double d,double e,double f)
{
a=d;
b=e;
c=f;
}
}
class
Learn1
{
public static void main(String s[])
{
Satya
s=new Satya(); //create instance of the class
Satya
s1=new Satya();
double
tot;
s.setValue(10,12,13);
s1.setValue(14,15,16);
tot=s.method();
System.out.println(“total=”+tot);
s1.method();
System.out.println(“total=”+tot);
} }
CONSTRUCTORS
Once defined,the constructor is automatically called immediately
after the object is created.
Syntax : nameof the
class()
Ex: Satya();
class
Satya
{
double a;
double b;
double c;
void
Satya()
{
a=12;
b=13;
c=15;
}
double
method()
{
return (a*b*c));
}
}
class
Learn1
{
public static void main(String s[])
{
Satya
s=new Satya(); //create instance of the class
Satya
s1=new Satya();
double
tot;
tot=s.method();
System.out.println(“total=”+tot);
s1.method();
System.out.println(“total=”+tot);
} }
class
Satya {
Satya()
{
System.out.println("Creating
Rock");
}
}
public
class Learn1 {
public
static void main(String[] s) {
for(int
i = 0; i < 10; i++)
new
Satya();
}
}
//
parameterized constructor
class
Satya
{
double a;
double b;
double c;
Satya(double
d,double e,double f )
{
a=d;
b=e;
c=f;
}
double
method()
{
return (a*b*c));
}
}
class
Learn1
{
public static void main(String s[])
{
Satya
s=new Satya(10,12,15);
Satya
s1=new Satya(21,12.3,24.5);
double
tot;
tot=s.method();
System.out.println(“total=”+tot);
s1.method();
System.out.println(“total=”+tot);
} }
THIS
KEYWORDS
Javadefines the this keyword. this can be used inside any method to refer to the current object.
this anywhere a reference to an object of the current
class’ type is permitted.
class
Satya
{
double a;
double b;
double c;
Satya(double
d,double e,double f )
{
this.a=d;
this.b=e;
this.c=f;
}
double
method()
{
return (a*b*c));
}
}
class
Learn1
{
public static void main(String s[])
{
Satya
s=new Satya(10,12,15);
Satya
s1=new Satya(21,12.3,24.5);
double
tot;
tot=s.method();
System.out.println(“total=”+tot);
s1.method();
System.out.println(“total=”+tot);
} }
//
OVERLOADED/POLYMORPHISM
class Satya
{
void
test() {
System.out.println(“test case”);
}
void
test(int a) {
System.out.println(“test case”+a);
}
void
test(int a int b) {
System.out.println(“test case”+(a+b));
}
double test(double a)
{
return
a*a;
}
}
class
Overload {
public
static void main(String[] s)
{
Satya
s=new Satya();
double r;
s.test();
s.test(12);
s.test(12,13);
r=s.test(12.56);
System.out.println(“result=”+r);
}
}
//
use obj as parameter
class Satya {
int a, b;
Satya(int i, int j) {
a = i;
b = j;
}
// return true if o is equal to the invoking object
boolean equals(Satya o) {
if(o.a == a && o.b == b)
return true;
else
return false;
}
}
class PassOb {
public static void main(String[] s) {
Satya ob1 = new Satya(100, 22);
Satya ob2 = new Satya(100, 22);
Satya ob3 = new Satya(-1, -1);
System.out.println("ob1 == ob2: " + ob1.equals(ob2));
System.out.println("ob1 == ob3: " + ob1.equals(ob3));
}
}
Accesss specifiers
Same class - Public, Protected, and Private
Same-package & subclass - Public, Protected
Same Package & non-sub
classes - Public, Protected
Different package & Sub
classes - Public, Protected
Different package & non- sub
classes - Public
Inheritance: is the Process by which the Obj of one
class acquires the properties of Obj’s
another Class.
A reference variable of a Super Class can be assign to any Sub class derived from
the Super class.
Inheritance is the method of creating the new class based on already existing class
, the new class derived is called Sub class which has all the features of
existing class and its own, i.e sub class.
Adv:
Reusability of code , accessibility of variables and methods of the Base class
by the Derived class.
In Inheritance incorporate the definition of one class into another by using
the extends keyword.
To
use keyword extends to create a
class that inherits attributes and behaviors from another class.
Interface:
Interfaces can be used to implement the Inheritance relationship between the
non-related classes
A class can implement more than one Interface.
An Interface can extend one or more interfaces, by using the keyword extends.
All the data members in the interface are public, static and Final by
default.
An Interface method can have only Public, default and Abstract
modifiers.
An Interface is loaded in memory only when it is needed for the first
time.
A Class, which implements an Interface, needs to provide the
implementation of all the methods in that Interface.
An Interface can’t be instantiated. Intf Are designed to support
dynamic method resolution at run time.
An interface can not be native, static, synchronize, final, protected or
private.
If an Interface can’t specify an exception list for a method, the class
can’t throw an exception.
The general form of Interface is
Access interface name {
return-type
method-name1(parameter-list);
type
final-varname1=value;
}
-----------------------
Marker Interfaces : Serializable,
Clonable, Remote, EventListener,
Abstract Class: Abstract classes can be used to implement the inheritance relationship
between the classes that belongs same hierarchy.
Classes and
methods can be declared as abstract.
Abstract
class can extend only one Class.
If a Class
is declared as abstract , no instance of that class can be created.
If a method
is declared as abstract, the sub class gives the implementation of that
class.
Even if a
single method is declared as abstract in a Class , the class itself can be declared as abstract.
Abstract
class have at least one abstract
method and others may be concrete.
Combination
of modifiers Final and Abstract is illegal in java.
Abstract
Class means - Which has more than one abstract method which
doesn’t have method body but at least one of its methods need to be
implemented in derived Class.
Difference Between Interfaces And
Abstract class ?
All the methods declared in the Interface are Abstract, where as
abstract class must have atleast one abstract method and others may be
concrete.
In abstract class keyword abstract must be used for method, where as in
Interface we need not use the keyword for methods.
Abstract class must have Sub class,
where as Interface can’t have sub classes.
An abstract class can extend only one class, where as an Interface can
extend more than one.