Java Programming 1
Java Programming 1
Genesis of Java
High Level Languages Prior to C Structured Programming ShortComings of Structured Programming Object Oriented Paradigm Need of Java Evolution of Java
Uptec Civil Lines, Allahabad
Continued
2
Not Applicable System Code Large Program Not Easy to Learn System Program
4
Structured Programming
A language is said to be structured if it supports the following construct
Sequential Selection
IF CASE
Iteration
FOR WHILE DO WHILE
Uptec Civil Lines, Allahabad 5
Security Reusability
Encapsulation
Mechanism that binds code and data together.
Abstraction
Hiding Complexity of Data Can be done by breaking a complex problem into more manageable pieces. Internal Structure and Organization of Data is completely Hidden. Similarly the working methodology of methods is completely Hidden from the external view.
Uptec Civil Lines, Allahabad 8
Encapsulation
Mechanism that binds data and code together. Keeps code and data safe from outside interference and misuse. Class is the implementation of Encapsulation
Class
Defines the structure and behaviour shared by the set of objects. Class is a logical construct. The elements which are defined inside the class are called the member of the class. The Variables defined inside the class are known as member Variables ans Similarly the code defined inside the class is known as methods. Class is a data type for creating objects. Continued
Uptec Civil Lines, Allahabad 10
Class Continued
Class Name Account Holder ac_no name Member functions op_bal deposit() withdrawl() Member Variables
11
Objects
Are also known as instance of a class. An Object is a class type variable holding individual copy of data. The variables defined inside the class are known as Properties/ Attributes of the object of that class and similarly the methods defined inside the class are known as Behaviour of the Objects for that Class.
12
Declaration of Object
Account Holder ac_no name op_bal deposit() withdrawl() ac1 is an object of Account Holder Class ac1
13
Inheritance
The Process by which one object acquires the properties of another object The class whose members are being used by the objects of another class is known as Superclass. The class whose objects uses members defined in another class is known as subclass
Continued
Uptec Civil Lines, Allahabad 14
Inheritance (Continued )
Super Class Account Holder
ac_no name op_bal
Sub Class
Polymorphism
Allows one interface to be used for general class of actions and the specific action is determined by the exact nature of the situation. Polymorphism can be expressed by One Interface multiple methods . Eg. Dog s Smell
If dog smells a cat , it will bark and if it smells food then it will run to the bowl.
16
Platform Independence
Before discussing Platform Independence we have to understand the Compilation of any Program in High Level language
17
Compilation of a Program
Source Code
18
Need of Java
The Primary Motivation for Java was the need for Platform Independent Language to create Softwares to be embedded in various Consumer Electronic Devices. Platform Independent Language means that can be used to produce code which can run on variety of CPU under different environments.
19
Evolution of Java
Java was invented by James Goasling Initially it was known as Oak but later renamed Java in 1995. Java was primarily designed for Consumer Electronic Devices but due to plateform independence feature it has proven to be the most suitable language for Internet Applications.
Uptec Civil Lines, Allahabad 20
Java Compiler
22
Features of Java
Simple Portable Object Oriented Robust Multithreaded Interpreted Distributed
Uptec Civil Lines, Allahabad 23
Continued 25
26
27
javac compiler creates a class file having extension .class which represents the bytecode of the program.
30
31
C:\jdk1.3\bin>
33
Data Types
Primitive
Non Primitive
Character char
Class
34
Operators
Arithmetic +, - , * , / ,% Relational <, <,>=,<=,== Logical &&,|| , ! Bitwise <<,>>,>>>
35
Sequential Construct
if statement if (condition)
{ statement; statement; } else { statement ; statement; }
36
Sequential Construct
if statement if (condition)
{ statement; statement; } else { statement ; statement; } Condition True Condition True
37
Sequential Construct
if statement if (condition)
{ statement; statement; } else { statement ; statement; } Condition False
38
Loops
While Loop
Protested loops Loop continues till condition remains true Loop terminates as condition becomes false Syntax while (condition) { statement; }
39
Loops
do while Loop
Post tested loops condition is given at the end of the loop loop is executed at least once irrespective of condition evaluation Loop continues till condition remains true Loop terminates as condition becomes false Syntax do { statement; }while (condition);
Uptec Civil Lines, Allahabad 40
Arrays
Continuous Memory location for holding similar type of data under a single heading Syntax
Datatype variable name [] =new Datatype[size]; Array locations are referenced by arrayname[subscript];
41
Points to Remember
Java is case sensitive. Class name and source file name should be same otherwise it will generate error at the time of execution. Java is Strictly Object Oriented language therefore everything should be inside the class Definition.
Uptec Civil Lines, Allahabad 42
Summary
Therefore , we have covered Genesis of Java Java Features Object Oriented Pradaigm Java Overview Queries ?
43