JAVA Document
JAVA Document
USES OF JAVA
- Electronics
- web applications
- System application
- mobile application
- robotics
- gaming
- Testing
COMPILATION OF JAVA
JAVA Java compile BYTE CODE
Binary(0,1)
JDK (java development kit)
It is a software
It is a resourse
It is physically present
JVM (java virtual machine)
It is a part of SDK
2. Char
3. Float
4. double
2. Char 2 byte
3. Float 8 byte
4. Double 16 byte
VARIABLE:- Changeable values are called variable. In another words,
we can say its work like a place holder which is used to hold the value.
Int a=10;
public static void main(String arg[])
String:- class.
Args:- variable.
Task on variable :-
Write a program to add, substract,divide and multiply using
third variable?
Write the same program above without using third variable?
WAP using shorthand operator?
WAP to find square and cube of any no.
WAP a program to find area of a circle, rectangle and triangle?
WAP a program to swap two no. with using third variable and
without using third variable.
WAP a program to convert Fahrenheit to celclius.
WAP a program to convert Kilometer to meter.
WAP a program to convert meter to centimeter.
CONSTANT :- it is a feature of java which is use to fixed value
of any variable with the final keyword we can not modify the
value of final keyword. We can only share it.
Variable constant
Arithmatic - (+,-,/,*)
Relational – (<,>,<=,>=,!)
Turnery and conditinal – (:,?)
Bitwise – (&,||,~)
Unary – (++,--)
Logical – (&&,||,!)
Assignment – (=,== )
Statement:-
Conditional Statements
Control Statements
Jumping statements
Ladder if else:- having multiple condition and multiple statement but system will be
different.
Control Statement:-
It control the order of execution in a program .
It includes following statements:
1. if – then
2. If – then – else
3. Switch case
The Looping statements:-
Such as for,while,do-while and,
The Branching Statements:
1. Break.
3. return.
Jumping Statements:-
In java jump statements are mainly used to transfer control to the other parts of our program
depending on our conditions. These Statements can be used to jump directly to the other
statements, skip a specific statements and so on. In Java we have following three jump
statements.
1> break
2> continue
3> return
Example of if condition
Class if
{
Public static void main(String var[])
{
int a,b;
a=20;
b=10;
if(a>b)
{
System.out.println(“A is grater”);
}
}
}
Example of if else
Class if
{
Public static void main(String var[])
{
int a,b;
a=30,b=10;
If(a>b)
{
System.out.println(“a is greater”);
}
else
{
System.out.println(“b is greater”);
}
}
}
Control statements:-
For loop
Syntax:- for(initiliazation
;condition;inc/dec )
{
Statements
}
while loop
Syntax:- while(condition)
{
Statements
in/dec;
}
Do while loop
Syntax: - do
{
Statements
in/dec;
}
while(condition);
Task of loop
1) A
B C
D E F
G H I J
2) A
b c
d e f
g h i j
3) 1
2 3
4 5 6
7 8 9 10
4) 1
1 2
1 2 3
1 2 3 4
5)2
4 6
8 10 12
14 16 18 20
6) * * * *
* * *
* *
*
1 Write a program to print integers from 1 to 20;
int :-nextInt()
char:-next()char at(0);
float:-nextfloat()
double:-nextdouble()
o class?
Switch(ch)
{
case1:
{
Statement
break;
}
case2:
{
Statement
break;
}
default:
{
Statement
}
}
Task of switch case :-
1 2 3 4 5
Indexing :-
c o n c e p t
0 1 2 3 4 5 6
Declaration of array :-
int ar[]
ar[]={1,2,3,4}
int ar[5]
ar[5]={1,2,3,4}
Task of array :-
Object
Encapsulation
Data hiding
Abstraction
Polymorphism
Class:-class is the collection of data member and member
function . where data member is means variable and
member function means method.
Encapsulate
Encapsulation
data
Covering
the data
Data hiding:-It is a process to hidding the data into the
class or scope that is called data hidding.
Write a programme to print name of student and check eligibility for vote?
class
{
int x;
Void setA(int a)
{
x=a;
}
void dis()
{
}
Syntax of getter method
Void seta(int a)
{
X=a;
}
Int get a()
{
Return x;
}
Types of variable :-
Global variable
Local Variable
Instance variable
Implicit Explicit
Non
parameter copy
parameter
Multiple constructor :- when we create more
than one constructor in programme than it is called
multiple constructor.
when we use static keyword with our method than it became static method
No need to use static variable in static method because it gives the error
When we create a static method within single class than we can call static
function with there name
When we create an static method within two class than we use reference of a
class for calling an static method
Static variable:-
when we use static keyword with over variable than variable became static
variable
Static variable we can free to us static method as well as non static method
when we not declare static keyword with our method than it became non static
method
In non static method we can free to use static variable as well as non static
variable
Task on static :-
Write a programme to create on static method and non static method with
using static variable.
Write a programme to create a two static method in class A and create non
static method in class B and call them in class c.
Write a programme to print table from two to five in known static method
Write a programme to crate an static method and known static method and
print assci value of alphabet
Write a programme to create an array in static reverse with using static variable
When we declare any variable into static block then its by default convert in
static block.
Static block when we define in class anywhere but its execution is always first
Syntax:-
static
{
}
Inheritance-
It is a feature of OOPS which is used to create a class from an
existing class. it is a concept to which show the property to
inherit one class into another class .
Multilevel inheritance
Multiple inheritance
Hiearchical inheritance
Method overriding
It is a problem
Syntax:- super();
Interface
Interface is a solution of multiple inheritance we can call
interface as a code reusability
Syntax:-
Class test
{
Pulic static void main(String ar[])
{
Int x;
Int[] arr={10,20,30,40};
For (int x:arr)
{
System.out.println(x);
}
}
}
Nested class:- when we define a class inside another
class then its feature is called nested class .
Example of nested class:-
Enumeration
It is a constant block
We can only call those values which are only declared inside
the enumeration.
Enum weekdays
{
Sun,mon,tues,wed,thur,fri,sat
}
Class test
{
Public static void main(String ar[])
}
Weekdays wk;
Wk=weekdays.fri;
System.out.println(“today is”+wk);
}
}
Enumeration with switch case
Enum restaurants
{
Dominos,kfc,pizzahut,burgerking
}
Class test
{
Public static void main(String ar[])
{
Restaurant r;
R=restaurant.kfc;
Switch(r)
{
Case dominos :
System.out.println(“I am ”+r.dominos);
Break;
}
}
}