Sei sulla pagina 1di 40

 Java is a Object Oriented Programming language as well

as platform.

 Java was developed by a team led by James Gosling at


Sun Microsystems.

 Java is a first programming language which provide the


concept of writing programs that can be executed using
the web.
HISTORY OF JAVA

o It is a programming
language.
o It is a Computer
Language.
o It is a high level language.
o First appeared in 1995.
o It is originally developed
by James Gosling at Sun
Microsystem.
o Java uses in:
• Electronic Machines.
• Setup box.
• Mother board.
• ECG
PROGRAM
The collection of work in a sequence or step by step.
OR
It is a set of instructions in a sequence, that is called
Program.
CATEGORIES OF JAVA

 J2SE (Java 2 Standard Edition)

 J2EE (Java 2 Enterprise Edition)

 J2ME (Java 2 Micro Enterprise)


C++ JAVA
PARTS OF PROGRAM

Flowchart Design

Algorithm Code Analyse Code

Machine User
Mind mind
ALGORITHM V/S FLOWCHART

1. Start Start

2. Declaration int a,b,c

3. Value assignment a=10 , b=10

4. Action c=a+b

5. Result Result

6. End End
COMPILATION PROCESS IN JAVA
1. Secure
2. Platform Independent
3. Flexible
4. Robust
FEATURES
5. Portable
OF
JAVA 6. Distributed System
7. WORA (Write Once Run Anywhere)
8. High Performance
9. Reusability
DATATYPE
• It is a state which is used to define or declare the type of variable. It is of two types :-

Datatype
Non -
Primitive
primitive

int – 4 Char – 2 Float – 8 Double –


bytes bytes byte 10 byte
JDK JRE
(Java Development Kit) (Java Runtime Environment)

It is a software. It is physically present.

It is a resource.
It provides java packages &
classes to compile & running
Which is use to compile and run the process.
app.

If we want to access java code in our It provides all the features to


machine then we must install JDK. compiling and running
process.
J AVA V I R T U A L M A C H I N E
Java Code (.java)

JAVAC
compiler

Byte Code (.class)

JVM JVM JVM

Windows Linux Mac


SOME DEFINITIONS….
 COMPILER  It is a tool which is use to compile our program and
convert into byte code. It is execute the code in one
format.
 INTERPRETER  It is also work like compiler which is use to
compile our source code. In java, JDK provides
both compiler (interpreter as well as compiler).
 VARIABLE  Changeable values are called Variable. In another
word we can say, it works like a place holder which
is use to hold the values of any variable.
 DECLARATION OF VARIABLE  int a; Variable

Datatype
Contd…

 VALUE ASSIGNMENT  a = 10;


LR
 INITIALLIZATION  int a = 10;
* NOTE 
Q.1 How to check that JDK is install or not ?
Ans. Start  cmd  javac
Q.2 Saving convention of java program ?
Ans. Add.java OR “Add.java”
QUESTIONS…
Q.1 Write a program to perform addition, subtraction, Q.13 How to set path of JDK?
multiplication and division with sort hand operator.
Q.14 How to compile our java program?
Q.2 Write a program to perform addition, subtraction,
Q.15 How to run a java program?
multiplication, division without using 3rd variable.
Q.16 How to exit from folders in cmd?
Q.3 Write a program to convert fahrenheit to celsius.
Q.17 How to exit from a drive in cmd?
Q.4 Write a program to calculate simple interest.
Q.18 How to enter in a folders in cmd?
Q.5 Write a program to calculate square of any number.
Q.6 Write a program to calculate cube of any number.
Q.7 Write a program to swap 2 numbers with using 3rd
variable.
Q.8 Write a program to swap 2 numbers without using
3rd variable.
Q.9 Write a program to convert Kilometer to Meter.
Q.10 Write a program to find area of triangle.
Q.11 Write a program to find area of rectangle.
Q.12 Write a program to find area of circle.
SOME DEFINITIONS...
CONSTANT 
• It is a concept which is use to fix the value of any variable. It means we can’t modify the value of
any variable. In C language we use #define keyword for constant. In C++ language we use const
keyword and when we become in java we use final keyword.
 With the help of final keyword we fix the value of any variable.

 Syntax :- final int a;

TYPES OF VARIABLE 
• LOCAL VARIABLE :- Those variable which are declare within a scope that is called local variable.
• GLOBAL VARIABLE :- Those variable which are declare outside the scope i.e. called global variable.
Note :- We can’t declare class as constant.

OPERATORS 
• It is a feature which is use to operate some features like arithmetic, unary, ternary operators and
some other.
STATEMENTS
Having one condition and
if
one statement.

Having one condition and


if else
more than one statement.
Statements

Conditional
Having multiple conditions
nested if
and multiple statements.
Control
Having multiple conditions
Ladder if else and multiple statements but
syntax will be different.
Jumping

Syntax 
SYNTAX;
• IF  • IF ELSE  • NESTED IF  • LADDER IF ELSE 
IF(CONDITION) IF(CONDITION) IF(CONDITION) IF(CONDITION)

{ { { {
IF(CONDITION) STATEMENT;
STATEMENT; STATEMENT;
{ }
} }
STATEMENT; ELSE
ELSE
}
{ IF(CONDITION)
ELSE
STATEMENT; {
{
} STATEMENT;
STATEMENT;
}
}
ELSE
}
{
ELSE
STATEMENT;
{
}
STATEMENT;
}
QUESTIONS BASED ON CONDITIONAL STATEMENTS...
1) Write a program to find even and odd.
2) Write a program to find vowel and consonant.
3) Write a program to find leap year.
4) Write a program to find who can give the vote and how much age is left for vote.
5) Write a program to print the salary of an employee where salary is equals to 5000 and
condition is 
a) If salary is less than 5000 than add Rs.1000.
b) If salary is greater than 5000 then deduct Rs.200.
c) If salary is equals to 5000 then print same salary.

6) Write a program to find how much notes are belongs to the money.
7) Write a program to find greatest number among A, B and C where A=10, B=20, C=30.
CONTD…
8) Write a difference between Object Based Programming and Object Oriented
Programming.
9) Which one is correct?
a) public static void main(String args[])
b) public static void main(String []pra)
c) public static void main(String []args)
d) static public void main(String …p)
e) public static void main(String …pra)
f) public static int main(String args[])
g) static public void main(String args[])
Autoboxing :-
• It is a concept which is use to convert value to the reference variable.
• Value  reference variable

autoboxing

Wrapper class :-
• Those classes which are already define in java.lang package.
• Some already define wrapper classes are :-
1. Integer
2. Character
3. Float
4. Double Predefined classes
5. String
6. Object
7. Byte
PROCESS OF OBJECT CREATION IN JAVA
class Test
{
public static void main(String args[])
{
int a;
a=10;
value
}
keyword
Demo d=new Demo();

class Reference
variable constructor
Integer i=new Integer(a);
System.out.println(i);
}
}
AUTOUNBOXING

• It is a process to convert reference variable to value.


• Lets look below to understand how autounboxing works 
class Demo
{
public static void main(String[] args)
{
Object o=50; //reference variable
int a; //normal variable
a=int(o); //value of reference variable passed to normal variable.
System.out.println(a);
}
}
1) It is a class in java.
2) This class is use to get the value from user at run time.
3) This class belongs to util package.
4) We must import a package.
5) Syntax :- import java.util.Scanner;
OR
import java.util.*; //where * means all classes of util package.
6) We must have to create an object of Scanner class.
7) There are 3 ways to create an object of Scanner class :-
A. Scanner s=new Scanner(System.in);
B. Scanner s=null;
s=new Scanner(System.in);
C. public static void Scanner getInstance()
{
return new Scanner(System.in);
}
CONTD…
 FORMATS OF SCANNER CLASS 
1) nextInt()  Scan the next token of the input as an integer.
2) next()  Scan the next token of the input as string.
3) nextLine()  Scan the next token of the input as string.
4) nextFloat()  Scan the next token of the input as float.
5) nextDouble()  Scan the next token of the input as double.
6) next().charAt(0)  Scan the next token of the input as a character.
 QUESTIONS 
1) Write a simple program of Scanner class.
2) Write a program to take two values from user and perform arithmetic operations.
3) Write a program to perform swapping of two numbers.
4) Write a program to calculate area and perimeter of all type of solids.
ARRAY
• It is a collection of similar datatypes contiguous memory allocation.
• For Example 

int char float double String


0 ‘1’ 1.2f 33.99 x 1023 “hello”
-1 ‘a’ 1.3f 46356 x 105 “1”
1 ‘2’ 1.436f 4.0 x 10-36 “sad”

• Question  How to declare array in a program ?


• Answer  We can only initialize array in our program. For example :-
int ar[] = {11, 12, 13, 14, 15};

This is a correct way to initialize an array.


 ADVANTAGES OF AN ARRAY  5) Write a program to search an element in an
array.
1) In an array we can collect multiple data in a
variable. 6) Write a program to sort an array.
2) In an array we can collect only similar data. 7) Write a program to find maximum element
in an array.
3) We can operate some operations like
searching, sorting, deleting. 8) Write a program to find minimum element in
an array.
 DISADVANTAGE OF AN ARRAY 
9) Write a program to reverse element in an
1) There is a big demerit of an array that if array size array.
is 50 and provide only 5 data than it can’t allow to
access other memory which is occupied by an 10) Write a program to convert the following :
array and which is free.
1) 1234554321
 QUESTIONS 
2) 1234514325
1) Write a simple program of an array.
3) 1234552341
2) Write a program to find even number given
in an array. 4) 1234512354
3) Write a program to find odd number given 5) 1234521345
in an array. 6) 123451239
4) Write a program to find prime number given 7) 123453345
in an array.
8) 1 2 3 4 5  addition
OOPS (Object Oriented Programming)

 CONCEPT OF OOPS 
1. Class
2. Object
3. Encapsulation
4. Abstraction
5. Data hiding
6. Polymorphism
7. Inheritance
 NOTE  All points we will discuss one by one.
 CLASS   OBJECT 
z
It is collection of data members and  Active part of a class.
member functions. It is a collection of
 Real World Entity.
objects.
 Instance of a class.

class Demo d.show();


{
public static void main(String[] args)
{
int a=10;
Active part
Demo d=new Demo();
d.show();
}
public void show()
{
System.out.println(a);
}
}
CONSTRUCTOR
■ It is use to initialize the value. writing constructor.
■ Constructor name and class name should be ■ EXPILICIT CONSTRUCTOR 
same. 1. Copy constructor (object slicing)
■ Constructor has no return type. 2. Non parameterized constructor
■ By default there are four things call in our 3. Parameterized constructor
program :-
public Test(int a)
1. Constructor
{
2. Destructor }
3. Object Test t=new Test(10);
4. toString()
public Test()
■ Constructor are of two types  {
1. Implicit constructor a=10;
}
2. Explicit constructor Test t=new Test();
■ IMPLICIT CONSTRUCTOR 
public Test(Test t)
Those constructor where we are not using
■ this keyword 
It is a keyword which is use to show the current value of object. For example
■ CONSTRUCTOR OVERLOADING 
When we use more than one parameter with our constructor.
o this() 
 This() is a function which is private int x, y, z;
use to call constructor Test()
variable into another {
constructor. private int x, y, z;
 This() is only use in Test(int a, int b)
}
constructor, we can’t use in {
Test(int a, int b)
any function. x=a;
{
 We use this() in a y=b;
this();
constructor as a first }
x=a;
statement then write the Test(int p, int q, int r)
y=b;
other statements. {
}
this(p,q);
Test(int p, int q, int r)
o Constructor z=r;
{
Chaining  }
this(p,q);
 It means we can call z=r;
constructor by the help of }
this().
DESTRUCTOR & GARBAGE COLLECTOR
 DESTRUCTOR 
In java we have a concept of destructor which is use to destroy the
memory which is construct by constructor. We no need to call destructor
because destructor calls itself by default. We no need to write any statement
for destructor. If we want to write destructor method then we use finalize
method. Finalize method works as a destructor which is use to destroy or
flush the memory. Finalize method is a predefined method, it is not
compulsory to create constructor.
 GARBAGE COLLECTOR 
It is a concept which is use to destroy the object in java we have a tool
like Garbage Collector with the help of Garbage Collector we have no found
in java. That’s why we use public static void main(), it means main method
always have void.
INHERITANCE
• Inheritance is the main concept of oops which is use to access the property of one member to another
member.
• We can say in other word that inherit the property of one class into another class.
• We can call parent class as a base class or super class.
• We can call child class as a derived class or sub class.
• When we access one class property to another class, we use extends keyword.
• Class into class always extends.
• Type of inheritance 
1. Single level Inheritance
2. Multilevel Inheritance
3. Multiple Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance
SINGLE LEVEL INHERITANCE

parent
child
MULTI LEVEL INHERITANCE
grandparent

parent

child
• It is a collection of abstract method and variables.
Did u know….???
• This is the solution of Multiple interface.
• Abstract method is a • We can use interface for code reusability.
method which we
only declare. We • Interface always implements into the class.
can’t provide the • Interface - interface always extends like a class.
body of this method,
but we can declare • When we use multiple interface in a single file than one
variable with value. interface must be public.
o SYNTAX 
public interface Demo
{ . . . .}
• It is not a class that’s why we do not need to create an
object of interface.
• We always create instance of interface.
INTERFACE • We can call those things by instance which are declared
in interface.
SETTER METHOD 
• This method is use to set the value.
• We always have void type of setter method.
• We always provide parameter to setter method.
• setter method always has a user define method.

GETTER METHOD 
• It is also a user define method to get value from setter
method.
• We always use return type of getter method as the
parameter of setter method.
• We use return keyword.

Potrebbero piacerti anche