You are on page 1of 56

Unit 1

Unit 1: Introduction to Java


(2 Hrs)

1 Prepared by: Shiva Bhat


tarai
Objective

Discuss the background of development of
Java

Explain with java buzzwords summed up by
Java committee.

2 Prepared by: Shiva Bhat


tarai
Outline


Definition and History of Java

The internet and Java’s Place in IT

Applications and Applets

Java Virtual Machine (JVM)

Byte code – not an executable code

Procedure – oriented vs. object – oriented
programming

3 Prepared by: Shiva Bhat


tarai
Outline


Compiling and Running a simple program

Setting up your computer for Java Environment
Writing a program

Compiling, Interpreting and Running the
program

Handling common Errors

4 Prepared by: Shiva Bhat


tarai
History


Conceived by James Gosling, Patrick Noughton,
Christ Warth, Ed Frank and Mike Sheridan at
Sun Microsystem Inc. in 1991.

Initially called “Oak” but late renamed as Java
in 1995.

5 Prepared by: Shiva Bhat


tarai
Java’s Lineage


Related to C++, which is the direct descendant
of C.

Much characters are inherited from both two
language i.e., C and C++.

Syntax, derived from C and object oriented
concept from C++.

Since, a language is designed to solve the
fundamental problem of the preceding
language could not solve, Java is no exception.

6 Prepared by: Shiva Bhat


tarai
Java: Platform independent

7 Prepared by: Shiva Bhat


tarai
Java: Platform independent

8 Prepared by: Shiva Bhat


tarai
Java: Platform independent

9 Prepared by: Shiva Bhat


tarai
Java: Platform independent

10 Prepared by: Shiva Bhat


tarai
Java: Platform Independent

A computing platform from oracle that helps to


run and develop applications.
Platform consists of an execution engine, a
compiler and a set of libraries.
Platform independent, No need to develop
separate applications for different platform.
Also called Write once, Run Anywhere (WORA)
Designed to run object program on any platform

11 Prepared by: Shiva Bhat


tarai
Java: Platform Independent

The program is written once, the source


program is compiled into a special type of
object code, know as bytecode.
Bytecode is then run on any computer with the
Java Virtual Machine (JVM).
Java Virtual Machine is a software that
interprets Java bytecode.

12 Prepared by: Shiva Bhat


tarai
Bytecode and Java Virtual Machine (JVM)

Bytecode, a set of instruction that can executed


by the Java run time system called the Java
Virtual Machine (JVM).
JVM, an interpreter for the bytecode, that is
installed for each platform, where java program
runs.
Although the details of JVM differs from
machine to machine all of them interprets same
bytecode.

13 Prepared by: Shiva Bhat


tarai
Bytecode and Java Virtual Machine (JVM)

This helps in creating portable program which


can be run on variety of CPUs.
Execution of Java program is under the control
of JVM, so it makes the program secure and
ensures that no side effect outside the system
are generated.
Safety is enhanced by the features provided by
the language itself.
Bytecode makes Java run time system faster to
execute the program.

14 Prepared by: Shiva Bhat


tarai
How Java Changed the Internet

At the time of development of Java, WWW


emerged and become a language of the
internet.
Since internet consists of various types of
computers, operating under different operating
systems and CPUs.
It is necessary to run the same program on all
these environment and Java had the capability
to run on the various platforms, thus offering
portability.

15 Prepared by: Shiva Bhat


tarai
How Java Changed the Internet

In network, two board categories of object are


transmitted between server and client.
First category is the passive information and
second on is dynamic, self executing programs.
Such a dynamic program is generated by the
server, however it is active on the client
computer.

16 Prepared by: Shiva Bhat


tarai
Applications and Applets

Two types of programs can be created in Java.


Applications
Program which runs on the computer under the operating system of the
computer.
Applets
An application which is developed to be transmitted over the internet and
executed by a Java compatible web browser.
Intelligent program, which means it can react to the user input.

17 Prepared by: Shiva Bhat


tarai
Servlets: Java on the Server side

Your task.

18 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Features of Java
Simple
Platform independent
Secure and portable
Object-oriented
Robust
Multi-threaded

19 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Features of Java
Architectural Neutral
Compiled and interpreted
Distributed
Dynamic

20 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Simple
Designed to be easy to learn and effective to use.
Comparing with other languages, not difficult to master and
provides a small number of clearly defined ways to
accomplish a given task.
User familiar with C and C++, finds easy to master Java, since
it is inherits the syntax of C and C++ and object oriented
features of C++.

21 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Secure and portable


Downloading programs, risk the possibility of infecting our
system with virus.
Similarly other programs may exist which may gather private
information, such as credit card numbers, bank account
numbers, passwords etc.
Java provides a security against both these attack by
providing a firewall between the network applications and
user’s personal computer.

22 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Secure and portable


Java also satisfies the need of generating portable executable
code.
Both these aspects of security and portability are addressed
by Java because output generated by Java compiler is not an
executable code, but bytecode.

23 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Object-oriented
Not designed to be source code compatible with any other
language.
“Everything is an object” paradigm.
Object model in java is simple and easy to extend.

24 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Robust
Ability to create robust program.
Strictly or strong typed language and restricts the
programmer in few key areas.
Checks the program code at compile time as well as at run
time.
Unlike C/C++, manages memory allocation and deallocation
on its own.
Deallocation of memory is automatic, also provide object
oriented exception handling.

25 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Multi-threaded
Designed to meet the real world requirement of creating
interactive networked programs.
Supports multi-threading, that allows us to write program the
can do many this simultaneously.

26 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Architecture Neutral
Upgrading of OS, processor upgrades and changes in the core
system resources can be the factor that causes malfunction of
program that was running successfully at a later point of time.
Java and JVM has been designed in such a way so as to
attempt to overcome this situation, which would enable the
programs to run in-spite of environmental changes.

27 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Compiled and interpreted


The Java source code with the extension java is compiled to
create bytecode with extension class.
The bytecode is interpreted by any system that have Java
virtual machine.

28 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Distributed
Java handles TCP/IP protocols.
Accessing a resources using URL is similar to accessing a file.
Has a package called Remote Method Invocation (RMI), which
brings a very high level of abstraction to client/server
programming.

29 Prepared by: Shiva Bhat


tarai
The Java Buzzwords

Dynamic
Programs have the capability to carry sufficient amount of run
time type information.
The information can be use to verify and resolve accesses to
the object at run time.

30 Prepared by: Shiva Bhat


tarai
Procedural Programming

31 Prepared by: Shiva Bhat


tarai
Procedural Programming


Also called procedure oriented programming.

Program in this approach is a list of
instructions that follows step-by-step
approach.

Each instruction tells the computer to do
something.

Instruction can be like

Get some input

Add these number

Divide by seven

Display the output
32 Prepared by: Shiva Bhat
tarai
Procedural Programming

Example of procedural programming: C, Pascal,


FORTARN etc.
Enforces the top-down design model.
Programmer can create list of instructions to
write a program.
Small programs don’t need any principle or
paradigm, however difficulty arises when
program become large.

33 Prepared by: Shiva Bhat


tarai
Procedural Programming

Larger programs are broken into function


(subprogram, subroutine, or procedure), further
extended by grouping number of functions into
a large entity called a module.
Procedural programming that involves functions
and module to make large program more
comprehensible is the structured programming.

34 Prepared by: Shiva Bhat


tarai
Structured Programming

35 Prepared by: Shiva Bhat


tarai
Structured Programming

Subset of procedural programming, also called


modular programming.
Code are divided into function or procedure and
placed separately for reusable purpose.
Procedure or function are called (invoked),
introducing parameters.
Defined function or set of similar functions is
coded in a separate module or sub-module, so
that it can be reused in other program.

36 Prepared by: Shiva Bhat


tarai
Structured Programming

Characteristics of structured programming


Emphasis on doing things i.e., algorithms.
Large programs are divided into smaller known as functions.
Most of the functions share global data.
Data move openly around the system from function to
function.

37 Prepared by: Shiva Bhat


tarai
Structured Programming

Problem of structured programming


Complexity of managing large projects.
Unrestricted access to global data.
Difficulty in real-world modeling.
Difficult to create New data types.

38 Prepared by: Shiva Bhat


tarai
Object oriented Programming

39 Prepared by: Shiva Bhat


tarai
Object Oriented Programming

Programming technique in which programs are


written on the basis of objects.
Follows bottom-up approach.
Fundamental idea of OOP is to combine both
data and the functions that operate on that
data, into a single unit. Such unit is called an
object.
This paradigm is based on: Class and object.

40 Prepared by: Shiva Bhat


tarai
Object Oriented Programming

Class
A blueprint of an object which defines all the common
properties of objects.
A class is used to define multiple object within a program.
Object
a self-contained entity that consists of data and functions, and
functions is used to access the data within the object.
Object is an instance of a class.

41 Prepared by: Shiva Bhat


tarai
Object Oriented Programming

If you want to read the data in an object, you


must call a member function in the object. It
will access the data and return the value to you.
OOP consists number of object, that
communicates with each other by calling one
another member functions.
Example of OOP languages are C++, Java, PHP,
Objective-C, Ruby, Python, JavaScript.

42 Prepared by: Shiva Bhat


tarai
Procedural vs Object Oriented
Programming

43 Prepared by: Shiva Bhat


tarai
Procedural vs Object Oriented
Programming

44 Prepared by: Shiva Bhat


tarai
JDK (Java Development KIT) Editions

Java Standard Edition (J2SE)


Can be used to develop client-side standalone applications or
applets.
Java Enterprise Edition (J2EE)
Can be used to develop server-side applications such as java
servlets and java server pages.
Java Micro Edition (J2ME)
Can be used to develop applications for mobile devices.
Note: J2SE is used for this course.

45 Prepared by: Shiva Bhat


tarai
Java IDE Tools

Borland Jbuilder
NetBeans, Open source by Sun (oracle)
Eclipse, Open source by IBM
Oracle JDeveloper

46 Prepared by: Shiva Bhat


tarai
Simple Java Program

47 Prepared by: Shiva Bhat


tarai
Creating and Editing Using NotePad

48 Prepared by: Shiva Bhat


tarai
Creating Compiling and Running Program

49 Prepared by: Shiva Bhat


tarai
Tracing a program Execution

50 Prepared by: Shiva Bhat


tarai
Trace a Program Execution

51 Prepared by: Shiva Bhat


tarai
Trace a Program Execution

52 Prepared by: Shiva Bhat


tarai
Anatomy of a program


To compile
javac HelloWorld.java

To run
java HelloWorld

53 Prepared by: Shiva Bhat


tarai
Writing a Program


To compile
javac UseArgument.java

To run
java UseArgument shiva

54 Prepared by: Shiva Bhat


tarai
Assignment - 1

What are the features of JAVA?


Why java is called platform neutral language
Why java is called strong typed language?
What is JVM? How does it works
What is bytecode? Explain its importance
What is use of parenthesis?
Describe the basic structure of Java Program.

55 Prepared by: Shiva Bhat


tarai
Assignment - 1

Difference between POP and OOP.


What are the advantage and disadvantage of
OOP.
.class file is called machine independent code
Why?

56 Prepared by: Shiva Bhat


tarai

You might also like