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 …

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 Not Applicable System Code

Large Program Highly Efficient for Not Easy to System Program Learn Business Application
Uptec Civil Lines, Allahabad

System Program

Structured Programming
A language is said to be structured if it supports the following construct
Sequential Selection

Uptec Civil Lines, Allahabad 5

Shortcomings of Structured Programming
Not Efficient for Handling of Complex Programs in terms of –
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

Mechanism that binds code and data together.

Uptec Civil Lines, Allahabad


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

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


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


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


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

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


Platform Independence
Before discussing Platform Independence we have to understand the Compilation of any Program in High Level language

Uptec Civil Lines, Allahabad


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


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


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 21 effect outsideUptec Civil Lines,System . of the Allahabad

Platform Indepedence in Java

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


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 Continued … application & Uptec Civil Lines, Allahabad applet. 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


Sample of Java Program File Name (
class test { public static void main ( String args[]) { System.out.println(“Welcome”); } }
Uptec Civil Lines, Allahabad 28

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

Explanation of Sample Program

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


Output of Sample Program
C:\jdk1.3\bin>java test Welcome


Variable & its Declaration
A container which can store the specific type of value Syntax for Declaration
DataType variable name;

Uptec Civil Lines, Allahabad


Data Types


Non Primitive

Number byte,int,long float double

Character char

Boolean boolean



Uptec Civil Lines, Allahabad


Arithmetic +, - , * , / ,% Relational <, <,>=,<=,== Logical &&,|| , ! Bitwise <<,>>,>>>
Uptec Civil Lines, Allahabad 35

Sequential Construct
if statement if (condition)
{ statement; statement; } { statement ; statement; } else

Uptec Civil Lines, Allahabad


Sequential Construct
if statement if (condition)
{ statement; statement; } { statement ; statement; } else Condition True Condition True

Uptec Civil Lines, Allahabad


Sequential Construct
if statement if (condition)
{ statement; statement; } { statement ; statement; } else Condition False

Uptec Civil Lines, Allahabad


While Loop
Protested loops Loop continues till condition remains true Loop terminates as condition becomes false Syntax while (condition) { statement; }

Uptec Civil Lines, Allahabad


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

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


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


Therefore , we have covered Genesis of Java Java Features Object Oriented Pradaigm Java Overview Queries ?

Uptec Civil Lines, Allahabad


Thanks End of Day -1
Uptec Civil Lines, Allahabad 44

Sign up to vote on this title
UsefulNot useful