Corporate Training on Java Programming
From : UPTEC Computer Consultancy Ltd Civil Lines , Allahabad
By : Vijay Kumar Dwivedi
Uptec Civil Lines, Allahabad 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
Genesis of Java (Continued..)
Platform Independence in Java Features of Java Java and Internet Java and it s Varieties Starting Java Programming Points to remember Summary
Uptec Civil Lines, Allahabad 3
High Level Language Prior to C
Language FORTRAN BASIC ASSEMBLY COBOL Use Scientific Application Easy to learn Highly Efficient for System Program Business Application
Uptec Civil Lines, Allahabad
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
Shortcomings of Structured Programming
Not Efficient for Handling of Complex Programs in terms of
Maintenance
Addition in existing Programs Modification in Existing Programs
Security Reusability
Uptec Civil Lines, Allahabad
Object Oriented Paradigm
Organizes Program around it s data . Data Controlling access to the Code Abstraction
Hiding Complexity of Data and Code
Encapsulation
Mechanism that binds code and data together.
Uptec Civil Lines, Allahabad
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
Uptec Civil Lines, Allahabad
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
Uptec Civil Lines, Allahabad
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.
Uptec Civil Lines, Allahabad
12
Declaration of Object
Account Holder ac_no name op_bal deposit() withdrawl() ac1 is an object of Account Holder Class ac1
Uptec Civil Lines, Allahabad
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
acOpen() withdrawl() deposit()
Sub Class
ChequeBook Holder chequeBook st_no chequeBook_eno wd_Cheque()
Uptec Civil Lines, Allahabad 15
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.
Uptec Civil Lines, Allahabad
16
Platform Independence
Before discussing Platform Independence we have to understand the Compilation of any Program in High Level language
Uptec Civil Lines, Allahabad
17
Compilation of a Program
Source Code
Dos Based Compiler
Window based Compiler
Unix Based Compiler
Dos/ Windows based Operating System
Unix Operating System
Uptec Civil Lines, Allahabad
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.
Uptec Civil Lines, Allahabad
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
Platform Indepedence in Java
Java Compiler generates the ByteCode for any Source code in java Byte Code is a highly optimized set of instructions designed to be executed by Java Runtime System (Java Virtual Machine). JVM is an interpreter for bytecode. JVM controls the execution of Java Program. JVM can contain the program and prevent it from generating the side effect outside of the System .
Uptec Civil Lines, Allahabad 21
Compilation of a Program in Java
Source Code in Java Output of Compilation Byte Code JVM for Dos/Windows
Java Compiler
JVM for Unix /Linux
Dos/ Windows based Operating System
Unix Operating System
Uptec Civil Lines, Allahabad
22
Features of Java
Simple Portable Object Oriented Robust Multithreaded Interpreted Distributed
Uptec Civil Lines, Allahabad 23
Java and Internet
Java provides facility to create two type of Programs Application Applet An Application is a program that runs on the local computer An applet is a small application designed to be transmitted over INTERNET and executed by Java compatiable Web Browser
Uptec Civil Lines, Allahabad 24
Java & it s Varieties
CORE JAVA- contains general classes and method which can be used to create standalone application. Applet small application that can be executed by Java Web Browser. Swing contains classes & methods to create Advanced Graphical User interface. JSP (Java Server pages) provides facility to create Application that can be executed on the Server. JDBC provides facility to connect databases of different vendors with application & applet.
Uptec Civil Lines, Allahabad
Continued 25
Java & it s Varieties (Continued )
RMI- ( Remote Method Invocation ) provides facility to execute one method on one from another machine. EJB (Enterprise Java Beans) provides application to create middle tier application .
Uptec Civil Lines, Allahabad
26
Starting Java Programming
Java Source code can be created by using any type of text Editor. Java Source Code is a text file having extension . java. Java is Case Sensitive. Sample of the Java Program is
Uptec Civil Lines, Allahabad
27
Sample of Java Program File Name (test.java)
class test { public static void main ( String args[]) { System.out.println( Welcome ); } }
Uptec Civil Lines, Allahabad 28
Explanation of Sample Program
test class name public scope static keyword void - keyword main ()- starting method for execution String bulit in Data Type args[] default array name for storing values System.out.println() - method for displaying information on console
Uptec Civil Lines, Allahabad 29
Compiling a Java Program
javac compiler is used for compiling the source file . The Syntax is
javac sourcefilename
javac compiler creates a class file having extension .class which represents the bytecode of the program.
Uptec Civil Lines, Allahabad
30
Executing a Java Program
Java Interpreter (java) is used for executing any java program. It accepts bytecode as input and interprets for a particular machine. The Syntax is : java classfilename
Uptec Civil Lines, Allahabad
31
Output of Sample Program
C:\jdk1.3\bin>java test Welcome
C:\jdk1.3\bin>
Variable & its Declaration
A container which can store the specific type of value Syntax for Declaration
DataType variable name;
Uptec Civil Lines, Allahabad
33
Data Types
Primitive
Non Primitive
Number byte,int,long float double
Character char
Array Boolean boolean
Class
Uptec Civil Lines, Allahabad
34
Operators
Arithmetic +, - , * , / ,% Relational <, <,>=,<=,== Logical &&,|| , ! Bitwise <<,>>,>>>
Uptec Civil Lines, Allahabad
35
Sequential Construct
if statement if (condition)
{ statement; statement; } else { statement ; statement; }
Uptec Civil Lines, Allahabad
36
Sequential Construct
if statement if (condition)
{ statement; statement; } else { statement ; statement; } Condition True Condition True
Uptec Civil Lines, Allahabad
37
Sequential Construct
if statement if (condition)
{ statement; statement; } else { statement ; statement; } Condition False
Uptec Civil Lines, Allahabad
38
Loops
While Loop
Protested loops Loop continues till condition remains true Loop terminates as condition becomes false Syntax while (condition) { statement; }
Uptec Civil Lines, Allahabad
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];
Uptec Civil Lines, Allahabad
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 ?
Uptec Civil Lines, Allahabad
43
Thanks End of Day -1
Uptec Civil Lines, Allahabad 44