E-Book
“ Code is like humor. When you have to explain it, it’s bad.” – Cory House
Java programmin
J
ng ogr
Notes
While(!(succeed=try());
pr
g
am
ava
m
i
Ankush
Page:
JAVA 1
Object oriented programming paradigm:
The object oriented programming paradigm enables you to develop complex software
applications for different domain problems with reduced cost and high maintenance.
Object oriented Analysis (OOA):
This process determines the functionality of the system .In other words , it determines the
purpose of developing an application.
Object Orinted Degsine (OOD):
This is the process of planning a system in which objects interact with each other to solve
a software problem.
Object Oriented Programing (OOP):
This is the process that deals with the actual implementation of the application.
PTO
Page:
2
OBJECT ORIENTED DEVELOPMENT:-
Object-
Oriented
Object
+ Oriented
Degsine
Object
+
Oriented
Programi
Analysis ngare as
An OOP language is based on certain principles that
follows:
---------------------------------------------------------------------------------------
-------------
Object: It represents an entity which possesses certain features and behaviours.
Class : It is a template that is used to create objects.
Abstraction: It is a design technique that focuses only on the essential features
of any entity for a specific problem domain.
PTO
Page:3
Encapsulation: It is a mechanism that combines data and implementation details into a
single unit called class. It also secures the data through a process called
[Link] also secures the data through a process called data hiding where
a user can’t manipulate the data directly.
Inheritance: Enables the developer to extend and reuse the features of existing
classes and create new classes. the new classes referred to as derived
classes.
Polymorphism: It is the ability of an object to respond to same massage in
different ways.
Java has three parts:
1. Java Standard edition.
2. Java Enterprise edition.
3. Java mobile edition.
PTO
Page:4
Difference between a class and an object:
class object
I. Class is a conceptual model. I. Object is a real thing.
II. Class describe an entity. II. Object is the actual entity.
III. Class consists a fields(data III. Object is an instance of a class.
members)and functions.
Java :
Java is one of the most popular oop language. It helps programmers to
develop wide range of applications that can run on various hardware
and operating system(os). Java is also a platform that creates an
environment for executing java application.
PTO
Page:5
Java standard edition : Java standard edition is a base platform for other editions.
(SE) developer use the java standard edition platform to develop
console and networking application for desktop computers.
Java Enteriprice Java enterprise edition is built on top of java standard platform.
edition (EE) : The java enterprise edition platform provides a standard
specification for developing and deploying distributed, scalable
and multi-tier enterprise applications. The enterprise applications
are large server-side business applications with complex business
logics.
Java mobile edition(ME) : Java mobile edition is a robust platform for developing
embedded java applications for consumer electronics
devices, such as mobiles, personal digital assistants, tv set
up boxes and so on.
PTO
Page:
Components of java se platform: 6
o The java SE platform provides two software components namely JRE and JDK.
JR E: JRE provides JVM and java libraries that are used to run a java program.
JDK: Java development kit (JDK) is a binary software development kit released by
oracle [Link] is an implementation of java and distributed for different
platforms such as windows, LINUX , MAC , OS x and so on.
Full name :
o JRE: Java runtime program.
o JDK : Java development kit.
o Jvm: Java virtual machine.
PTO
Page:
7
How to install java path setting:
path [Link]
Install JDK– open c-drive – program files –java –JDK –bin –click on the
address bar and copy the path –click on search –edit the system
environment variables – environment variables –under system variables –
click new –type ”Path” on variable name – paste the path under
variable value – then ok ,ok, ok .
Java first program(Hello world) :
* class ankush{
public static void main(String args[])
{
[Link]("Hello world!!");
}
} PTO
Page:8
• HOW TO COMPILE AND RUN JAVA PROGRAM ON CMD:
TYPE THE PROGRAM FIRST.
SAVE THE PROGRAM (LOCATION: DESKTOP).
PUT . JAVA DURING SAVE THE PROGRAM (Ex: ankush. java),(putting same of
class name during save for own help).
Open CMD.
For compilation : javac class name(EX: ankush). Java
To run the program: java class name(ankush).
Use CLS to clear screen of command prompt.
PTO
Working function in java: Page:9
Java filecompile[compiler/jdk].classfilerun[loader/runner/jvm]output
Comment entry:
// single line comment.
/* */ multi line comment.
Class keyword to declare any class.
Public global use.
Static run at first.
Void no return type.
Main function name.
String args[] String argument.
Package in java:
A package defines a namespace that stores classes with similar
functionalities in them. We call the package with important
keywords.
Variables: Variables are the instance fields which store the value.
PTO
Page:1
METHOD Methods are function that represents some action to be performed on an
S: object. Code is written within methods. They are also referred to as instance
methods.
The default package of java is lang.
Varriable:
// Int abcd =10; //right.
right: Int a_b_cd=10;//right.
Int a_=10;//right.
Int a1=10;//right.
[Link] (a+” ”+abcd+” ”+a_b_cd+”
”+a_+” ”+a1);
//wrong:
Int 1a=10;//wrong.
Int ab cd=10;//wrong.
Int 1=10;//wrong.
Int a%=10;//wrong.
[Link] (1a+””+ab cd+””+1+””+a%);
PTO
Page:1
• Type of variables:- 1
Instance variables.
Static variables.
Local variables.
• Instance variables:
It is a variables which is declared in a class.
• Static Variables:
These are also known as class variables. Only one copy of static variable is
maintained in the memory that is shared by all the objects belonging to that
class. These fields are declared using the static keywords.
• Local Variables:
The variables declared within the blocks or methods of a class are called local
• variables
Data Type:
Primitive Data Type
Integer Float Character Boolean PTO
Page:1
2
Reference Data Type
Array Class Interface
• Special Character:
Escape Character value
Sequence
\b Backspace Character.
\t Horizontal Tab Character.
\n New Line Character.
\’ Single Quote Marks.
\\ Back Slash.
\r Carriage Return Character.
\” Double Quote marks.
\f From Feed.
PTO
Page:1
3
Area of a circle in java program:
Double rad=5.5
Double area=3.14*5.5*5.5
[Link](“Area of a circle”+
area);
:Opertaor:
• Arithmetic Operators : ‘+’, ‘-’, ’*’, ‘/’, ‘%’
• Comparison : ‘>’, ‘<’, ‘>=’, ‘<=‘, ‘==’, ‘!=’
• Assignments: ‘=’
• Logical: ‘&&[and]’, ‘||[or]’, ‘![not]’
• Bitwise: ‘&[and]’, ‘|[or]’, ‘^[Xor]’, ‘<<[left shift]’, ‘>>[right shift]’
• Turnerry: ‘?’
PTO
Truth Table-Logic Gate Page:1
4
• OR: • AND
I1 I2 R I1 : I2 R
0 0 0 0 0 0
0 1 1 0 1 0
1 0 1 1 0 0
1 1 1 1 1 1
• XOR
I1 I2 R
0 0 0
0 1 0
1 0 0
1 1 1
Rule:
number x 23 + Number x 22 +Number x 21 +Number x
20 .
PTO
Page:1
5
PTO