Sei sulla pagina 1di 71

Submitted by:- Submitted to:-

Kuldeep chouhan Ms. Pragya mam


CATAGORIES OF JAVA
 J2SE:- Java 2 Standard edition
 J2EE:- Java 2 Enterprice edition

USES OF JAVA
 - Electronics
 - web applications
 - System application
 - mobile application
 - robotics
 - gaming
 - Testing
COMPILATION OF JAVA
JAVA Java compile BYTE CODE

Java class run


Source code
EXE FILE Class
file
Programme excetuble file

Code machine code

Binary(0,1)
JDK (java development kit)
 It is a software

 It is a resourse

 It is used to provide some features


and library to compile run over and
application.

 It is physically present
JVM (java virtual machine)
It is a part of SDK

It is physically not present

JVM is your compiler

Source code to machine code

(Programme) (Machine code)


JRE (Java Runtime Entity)

 JRE is physically present in JDK.


 It is a collection of packages and features
that are used at run time of a program.
 It is also known as Java Runtime
Environment.
Features of Java:-
1. Security: java is more secure because of there is a concept
of oops(class and object)

2. WORA(write once run anywhere): once the code is


written then it can be run on any place inside the machine and
on another machine when providing the code.

3.Distributed System: work/project based on java can be


distributed among no. of persons so that the speed of work is
increased.

4. High performance: both interpreter and compiler works


according to their requirement in java hence the performance is
automatically increased.
5 .Flexible:- java adopted many changes according to market
needs . In this way java is flexible language.

7. Robust:- code of java can not be easily cracked because the


code is robust.

8. Reusability:- The code in java once written can be reused


by the concept of class and objects and also through the
property of Inheritance.

9. Portable:- The code of java can be taken in usb or pendrive


and easily porting from one machine to other.
Difference b\w compiler and
interpreter
COMPILER INTERPRETER
• It is a convertor. • It is a convertor.

• It used to covert source • It is used to convert source


code into machine code. code into machine code.

• Compile is one in one • Interpreter is working


format. compile and execute line by
line.
Data type:- it is a feature which is use to declare and
define the type of variable that is called data type.
1. Int

2. Char

3. Float

4. double

Sizes:- Data types size


1. Int 4 byte

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.

PROCESS OF VARIABLE:- variable


 Declaration of a variable:-
data type int a ; terminator
 Value assignment:-
a = 10;
Left Right
 Initialization:- Combination of declaration and value assignment is
Initialization.
i.e.

Int a=10;
public static void main(String arg[])

public:-when we use public keyword with


datamember and member function then we
can access within the class and out side the
class.

Static:-No need to create object.

void:- No return type or nothing.

main():-This farmat is called method.

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.

syntax:- final int a=10;

Difference b\w variable and constant

Variable constant

Int a,b; final int a=10;


a=10;
b=20; final int b=20;
a=a=b; a=a+b;
a=30
error
OPERATORS

Operators are the function which is use to perform the task


with the help of operator

Arithmatic - (+,-,/,*)
Relational – (<,>,<=,>=,!)
Turnery and conditinal – (:,?)
Bitwise – (&,||,~)
Unary – (++,--)
Logical – (&&,||,!)
Assignment – (=,== )
Statement:-

 Conditional Statements
 Control Statements
 Jumping statements

Conditional Statements:- The statements which are used for a particular


condition or for true or false operation are called conditional statement.
It includes the following statement:
If :- Having one condition and one statement.
If-else :- having one condition and more than one statement.
Nested If else:- having multiple condition and multiple statement.

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;

 WAP to print even no. from 1 to 20;

 WAP to print odd no. from 1 to 20;

 WAP to print fabonicci series.

 WAP to print factorial of any no.

 WAP to print palindrome no.

 WAP to print reverse no. from 1 to 5

 WAP to print table of any no.

 WAP to print table from 2 to 5.

 WAP to print alphabet in upper case.

 WAP to print alphabet in lower case.


Scanner :- It is the class of util package
which is used to get the value from user at
run time.
Scanner class is belongs to util package it
means we must import a package of scanner.
package first
1) import java.util.Scanner;
2) import java.util *;
Scanner s=new Scanner(System.in);
Scanner =null
S=new Scanner(System.in;)
Public static Scanner getinsta()
{
Return s=new Scanner(System.in);
}
Formats of scanner class :-

int :-nextInt()

char:-next()char at(0);

float:-nextfloat()

double:-nextdouble()

String:-next()or next time()


Example of scanner :-
Import java.util.Scanner;
Class sc
{
Public static void main(String var[])
{
int a,b,c;
Scanner s=new Scanner(System.in);
System.out.println(“enter the value of a&b”);
a=s.nextInt();
b=s.nextInt();
c=a+b;
System.out.println(“ADD”+c);
}
}
INTERVIEW QUE FOR SCANNER

o Describe the super class of scanner?

o Describe type of package is belong to sum

o class?

o Describe the all method of scanner class?

o Describe the get instant method of scanner


class?
Switch case

 It is a jumping statement where we have


multiple cases that work like if condition.

 We have a default block and its work like


else.

 Switch case is a optional based


programming.

 Break:-It is a keyword which is used to


terminate the case.
Syntax of switch case :-

Switch(ch)
{
case1:
{
Statement
break;
}
case2:
{
Statement
break;
}
default:
{
Statement
}
}
Task of switch case :-

 Write a programme to make a calculator?

 Write a programme to make a 7 day calendar ?

 Write a programme to make a 12 month


calendar?
Array :-

Its the collection of elements of similar data type in contigous


memory allocation.

Contigous memory allocation :-

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 :-

o Write a programme to print character in aaray?

o Write a programme to print float in array?

o Write a programme to print maximum element


in array?

o Write a programme to print minimum element


in array?

o Write a programme to short an array asending


to desending ?

o write a programme to prime number in array?


Logical question of an array :-

Write a programme to revers an element of a array?

 12345 output-> 54321

 12345 output-> 52341

 12345 output-> 14325

 12345 output-> 3345

 12345 output-> 12345

 12345 output-> 12354a

 12345 output-> 32145


OOPS (object oriented programming)
 Class

 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.

Object:- Real word entity


Active part of class
instance of a class

Encapsulation:- It is feature of oops. The process of


rapping the data or encapsulate the data. When we use
private keyword with data member and member function
than we can only access with the scope.
Rapping of
data

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.

 Abstraction:- Abstraction it show essential data and


hide the other data.

Polymorphism:-It means a function having multiple


operation.
poly mean-> Many
morphism-> phases
Task on class and object-

 Write a programme to find factorial of any number?

 Write a programme to print name of student and check eligibility for vote?

 Write a programme to make the grading system


where four subject if marks between
Percentage Grading
90-80 A
80-70 B+
70-60 B
60-50 C
below 40 fail

 Write a programme swap 3 number without using third variable?

 Write to find greater among abc using ladder?


 Write a programme to salary of employ and name of an
employee and check eligibility for retirimen where age is 60?

 Write a programme to find the simple interest?

 Write a programme to print student name ,student id,


student marks with four subject and collage name with
Scanner?

 Write a programme to make a calculator in switch case in class?

 Write a programme to fareniet to Celsius with class?


Task on encapsulation -
 Write a programme to find area of triangle, rectangle,circle where
method name is area?

 Write a programme to print alphabate in upper case


Alphabet in lower case where method name is alphabet?

 Write a programme to print table of any number and print table


from 2-5 where method name is table?

 Write a programme to print prime number or not and print prime


from 1 to 20 where method name is prime number?

 Write a programme to add, sub,mul,div where method name is


calci?

 Write a programme to swap two number with using third variable


or without using third variable?
 Write a programme to print fabonaci series and factorial of any
number where method name is series?

 Write a programme to print even number and print odd number 1-


where method name no.

 Write a programme to print reverse number 1-30 find pallidram


number method name reverse?

 Write a programme to print information about the student and print


information about the collage where method name is information?

 Write a programme to print armstrong number and print simple


message where method name is simple?
Access Specifier :-

 Public:- when we use public keyword with our data


member and member function .when we access out side the
scope.

 Private:-when we use private keyword with data member


and member function .we access only in class.

 Protected:-when we use protected keyword with data


member and member function that is work like within the
class is public and outside the class is private.
Getter method and setter method :-

 Getter method :- This is also user define method. getter method


return type as depend on setter method parameter . With getter
method we always us return keyword.

 Setter method :- This method is used to set the value in given


variable with setter method we can apply any kind of return type
In setter we set the value the use of (this) keyword
In setter method we can set the value without this keyword
We always provide a parameter to over setter method.his

 this:- this is a keyword which use to current value of object


 Syntax of setter method

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

 Global variable:-These variable we can access out side the


scope.

 Local variable:-These variable which are defined as parameter


or inside the scope only that type of variable are called the local
variable.

 Instance variable:-Those variable which are defined inside the


class and out side the method which are called instance variable.
Constructor :-

 Constructor is used to initialize the value

 Constructor name class name should be same

 Constructor must be public

 Constructor has no return type


Constructor

Implicit Explicit

Non
parameter copy
parameter
 Multiple constructor :- when we create more
than one constructor in programme than it is called
multiple constructor.

 Singleton constructor :- when we declare over


constructor a private than it is called single
constructor.
Constructor chaining:-
It is a process to call multiple constructor with the help of single object
or single constructor.

 In constructor chaining we always this keyword.

 This function is always use in constructor cant use in method.

 This function is used to call constructor

 We can apply or we can provide the parameter to over this


function.

 With the help of this function we reduced the memory allocation


because we only create one object for one constructor.
Static :-
 It is keyword

 when we use static keyword with our method than it became static method

 In static method we always use static variable

 We no need to create object for calling an 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

Non static variable:-

 when we not declare static keyword with our method than it became non static
method

 For non static method calling we must create object

 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 and call them from a 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

 Write a programme to find area of rectangle, triangle ,circle in non static


method with using static variable with scanner
Static block
 It is a block which is use to write the statement which we want to execute
first over all the statement

 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

 We can define static block out of the main function

 We know need to call static block.

 We can use multiple static block in a single static block.

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 .

 Here we show the relationship between two class that is


parent class or child class

 We can inherit the property of parent class into child class


with the help of extend keyword

 We can show two types of relations in inheritance


1. Is a telationship
2. Has a relationship
Types of inheritance

 Single level inheritance

 Multilevel inheritance

 Multiple inheritance

 Hiearchical inheritance
Method overriding
It is a problem

It is happen with inheritance

In method overriding method name should be


same,parameters are also same that’s why compiler get
confused which method is call.

In c++ we can solve with the help of virtual keyword

We can call as urly binding or late binding.


Example of method overriding :-
Public class pa
{
Void show()
{
System.out.println(“parent class”);
}
}
Class cha extends pa
{
Void show()
{
System.out.println(“child class”);
}
}
Class main
{
Public static void main(String
args[])
{
P[] p=new pa[2]
P[0]=new pa();
}
}
Supper keyword

Super is a keyword which is use to pass or call the


value child class to parent class

Superkeyword we can use in constructor in method


as a method

We can call parent class method in supper class


method with the help of super keyword.

It is little byte similar to this function.r

Syntax:- super();
Interface
 Interface is a solution of multiple inheritance we can call
interface as a code reusability

 Interface is a collection of abstract methods interface into the


class always implements

 Interface always extends.

 Interface into the class always implement

 Whwn we use multiple interface in a file then one interface


must be public.

 When we create a interface then we use interface keyword.


Abstract method :-
 those methods which are only declare it means we cannot
define the body that type of method is called abstract method.
public void show();

 We always create instance of interface

 We cannot create constructor of interface because this is not a


class.
Que.How to call interface member?
Ans- we must create instance of interface for calling the member
of interface we can also call interface member by the object of
person class because we can define our interface member into the
class that’s why we can call by the objec t of class.
Public interface myinter
{
Void setA(int a);
Void getA();
}
___________________

Public class person


{
Int x
Void setA(int a)
{
X=a;
}
Int getA()
{
Return x;
}
Void show()
{
System.out.println(“person class”);
}
}
Public class main
{
Public static void main(String args[])
{
Myinter m=new person();
m.setA(10);
System.out.println(m.getA());
Person p=new person();
p.show();
}
}
Task on interface :-

 Write a programme to print employee name, ID and check how


many employee get salary above 10000.

 Write a programme to make a bank statement.

 Write a programme to find leap year with four file.

 Write a programme to find vowel and consonant.


tostring :-
It is a predefined method which belongs to
lang package this method is return type string
type value

Syntax:-

Public string tostring()


{
Sring name;
Void main()
{
Return name;
}
}
For each loop :-
We can call for loop as a enhanced loop with the help of for each
loop we can access all value of an array into different variable.

Que- write a programme for each loop

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

 This is use to define some constant values inside the


enumeration

 Its work like a class because we create a referance variable


of enumeration

 We can only call those values which are only declared inside
the enumeration.

 We can use enum keyword.


Example of 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;

}
}
}

Potrebbero piacerti anche