Java Start
Java Start
C++-->pointers
---Introduction to Java---
Developed by Sun microsystems in 1991
Originally -->Oak
Oracle Corporation-2010
---Java Feature----
1.Platform independent-windows,linux,macintosh.
a.Inheritance
b.Polymorphism
c.Encapsulation
d.Abstraction
3.Robust
-Garbage collector and Exception Handling
a/b;
a=9;
b=0;
try{
c=a/b;
res=c;
}catch(Arithematic Exception)
{
System.out.println("invalid division");
}
4.Secure
5.High Performance
6.byte code---
.java
jvm-Java virtual machine
.class file
Java8-
jdk-->java development kit-SE,EE-1.7,1.8
Interface-abstract class{
method body
boo();
boo();
Syso("Hi");
meow();
7.Multithreading
sync task
async
Eclipse
jre-jar file
8gb
--Types of application--
Front End--UI
Back End--Tabular
--Class Syntax--
object--method is called using object
methods--implementation (action to be performed)
add()
a=
b=
c=a+b
Instance variable--
constructors--if object is created then bydefault jvm creates its default
constructor.
Lights();
constructor--initialize the objects. It is called when object of class is created
class -Employee-- int e_id,String e_name,int age,float salary,float
experience--parameters
---default constructor--Employee();
Employee();
Employee1();
access modifiers
public--class can be accessed anywhere
package name-com.lti
----9 classes
com.lti.service
---classes
private--cannot be accessed outside the class
private int company ps no=907686;--java1
default--can be accessed in the same package outside the defined class
protected--
---Java Program---
class Lights{
boolean isOn; //boolean--datatype--true/false
Void turnOn(){ //void--nothing
isOn=true;
System.out.println("Light is on" +isOn); +-->concatenate -->Light is on true
}
void turnOff(){
isOn=false;
System.out.println("Status of lighton is " +isOn);
}
public static void main(Strings[] args){
Lights l1=new Lights(); ------//Lights(); --->default constructor
--Variables--
.local variable--defined inside the body of the method.
.Static variable--value of variable is fixed.. static pi=3.14--cannot be
modified..memory save
static int data=80;
data=90;
print 80
.Instance variable--declared inside the class but we can use this variable outside
the class and it cannot be static.
---Datatypes--
.Numbers-int,float,double,long,byte
.Character and String-char
string is enclosed in double quotes
syntax of string
String s1="who is playing?";
String s2="And where?";
String s3=s1+s2;
.boolean-true or false
Variables
int a=
char b=
3 types of variables
local variable
instance variable
static variable
Class Area{
int Area1; //instance variable(inside the class)
Area of square=(Side)*(Side);
System.out.println(Area1);
}
Void square(){
int s=9; //local variable(inside the method)
}
Circle Area=pi*r*r;
static float pi=3.14
}
}
Method can have a return type but constructor cannot
Constructor :
-Block of code that is similar to method.
-it is called when an instance of class(Object)is created.
Rules:
-->Constructor name-->Class name
-->have no return type
-->cannot be static,final,synchronized,abstract.
void display(){
System.out.println(id+" "+name);
}
public static void main(String args[]){
Student s1=new Student();//0 null
Student s2=new Student();//0 null
s1.display();
s2.display();
}
}
Parameterized constructor
class Student{
int id;
String name;
//creating a parameterized constructor
Student(int id,String name)
void display(){
System.out.println(id+" "+name);
}
public static void main(String args[]){
Student s1=new Student(1,"Ashish");//1 Ashish
Student s2=new Student(2,"Pawan");//2 Pawan
s1.display();
s2.display();
}
}