Object Oriented Programming
CS F213
J. Jennifer Ranjani
email: [email protected]
BITS Pilani
Pilani Campus
Prescribed Books
Text Books:
T1. Java: The Complete Reference, Herbert Schildt,
McGraw Hill Education, Tenth Edition, 2017.
T2. Object Oriented Design & Patterns, Cay Horstmann,
John Wiley & Sons, Second Edition, 2005.
Reference Book:
R1. JavaTM Design Patterns – A Tutorial, James W. Cooper,
Addison-Wesley, 2000.
BITS Pilani, Pilani Campus
Evaluation Scheme
Nature of
Weightage component
Component Duration Date & Time
(%) (Close Book/
Open Book)
Quiz-1 30 Min 10% (Feb 08 – Feb 12) TBA
Quiz-2 30 Min 10% (Mar 29 – Apr 2) TBA
Lab Test 75 mins 20% (Apr 10 – Apr 17) TBA
Mid Semester
90 mins 25%
Will be announced TBA
Exam by AUGSD
Comprehensive As announced in
120 Min 35% Open Book
Exam the Timetable
During scheduled class hour, To be announced later
BITS Pilani, Pilani Campus
Java – an Introduction
BITS Pilani
Pilani Campus
What is Java?
• Programming language and a platform
• Platform: Hardware or software environment in which a
program runs
• Java has its own runtime environment (JRE) and API
BITS Pilani, Pilani Campus
How Java impacted the
Internet?
• Security: Java confines an application to the Java
execution environment and prevent it from accessing
other parts of the computer.
• Portability: Allows same application to be downloaded
and executed by a variety of CPU, OS and Browser
without the necessity to have different versions for
different computers.
BITS Pilani, Pilani Campus
Bytecode: Java’s Magic
• Output of a Java compiler is not an executable code but
a bytecode.
• Bytecode – highly optimized set of instructions to be
executed by the Java’s run time system – JVM.
• JVM is the interpreter for bytecode
• JVM helps to solve the security and portability issues.
BITS Pilani, Pilani Campus
Java is compiled and
interpreted
Hardware and
Programmer
Operating System
Source Code Byte Code
Text Editor Compiler Interpreter
.java file .class file
javac
BITS Pilani, Pilani Campus
Portability
BITS Pilani, Pilani Campus
Where is Java used?
Acc. To Sun, 3 billion devices run Java
• Desktop applications
• Acrobat reader, media player, antivirus etc.
• Web applications
• Enterprise applications
• Mobile
• Embedded System
• Smart card
• Robotics
• Games etc.
BITS Pilani, Pilani Campus
Java Platforms / Editions
• Java SE (Standard Edition)
• Programming platform
• Java EE (Enterprise Edition)
• Web and enterprise applications
• Java ME (Micro Edition)
• Mobile applications
• JavaFx
• Rich internet applications. Uses light weight user interface APIs.
BITS Pilani, Pilani Campus
History of Java
• James Gosling, Mike Sheridan, Patrick Naughton
initiated the project in June 1991 (Green Team).
• Originally designed for small embedded systems
• “Greentalk” with file extension .gt
• Oak – symbol of strength and national tree of countries
like U.S., France, Germany, Romania etc.
• Suggested names: Dynamic, Revolutionary, Silk, Jolt,
DNA etc
• Java is named after an island in Indonesia where first coffee was produced
• Java is a name not an acronym
• JDK 1.0 was released in Jan 23, 1996.
BITS Pilani, Pilani Campus
Java Version History
• JDK Alpha and Beta (1995)
• JDK 1.0 (23rd Jan, 1996)
• JDK 1.1 (19th Feb, 1997)
• J2SE 1.2 (8th Dec, 1998)
• J2SE 1.3 (8th May, 2000)
• J2SE 1.4 (6th Feb, 2002)
• J2SE 5.0 (30th Sep, 2004)
• Java SE 6 (11th Dec, 2006)
• Java SE 7 (28th July, 2011)
• Java SE 8 (18th March, 2014)
• Java SE 9 (21st Sep, 2017)
• Java SE 10 (20th March, 2018)
BITS Pilani, Pilani Campus
JDK
• JVM – provides runtime
environment for bytecode
execution; loads, verifies,
executes code
• JRE – contains libraries
and files used by JVM
• JDK – JVM, java, javac,
jar, Javadoc etc. for
complete java application
development.
BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus
Features of Java
Java Buzzwords
BITS Pilani, Pilani Campus
Features of Java
• Simple
• Syntax based on C++
• Removed confusing and rarely used features like pointers, operator overloading
etc.,
• Automatic garbage collection
• Object Oriented
• Object, Class, Inheritance, Polymorphism, Abstraction, Encapsulation
• Platform Independent
• Compiler converts Java code to bytecode
• Bytecode is platform independent
• Write Once and Run Anywhere
BITS Pilani, Pilani Campus
Platform Independence
(Recall)
BITS Pilani, Pilani Campus
Features of Java
• Secured
• Robust
• Strong memory management, secure due to lack of pointers, automatic garbage
collection, exception handling and type checking
BITS Pilani, Pilani Campus
Features of Java
• Architecture-neutral and Portable
• Size of primitive types is fixed i.e., 4 bytes for both 32 and 64 bit architectures
• Porting the java system to any new platform involves writing an interpreter.
• The interpreter will figure out what the equivalent machine dependent code to run
BITS Pilani, Pilani Campus
Features of Java
• High Performance
• Bytecode is close to native code
• It is an interpreted language hence slower than C, C++
• Distributed
• Enables access to files by calling methods from any machine on the internet
• RMI, EJB
• Multi-threaded
• Thread is like a separate program executing concurrently
• Doesn’t occupy memory for each thread
• Multimedia, Web applications etc
• Dynamic
• Small fragments of bytecode may be dynamically updated at run time.
• Also supports functions from native languages i.e. C and C++
BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus
Comparison with C++
Comparison Index C++ Java
Platform- Platform-dependent. Platform-independent.
independent
Mainly used for System programming. Application
programming.
Goto Yes No
Multiple inheritance C++ supports Java doesn't support
multiple inheritance. multiple inheritance
through class. It can
be achieved
by interfaces in java.
Operator Yes No
Overloading
Pointers C++ Java supports pointer
supports pointers. You internally. But you
can write pointer can't write the pointer
program in C++. program in java.
BITS Pilani, Pilani Campus
Comparison Index C++ Java
Compiler and C++ uses compiler Java uses compiler
Interpreter only. and interpreter both.
Java source code is
converted into byte
code at compilation
time. The interpreter
executes this byte
code at run time and
produces output.
Call by Value and C++ supports both Java supports call by
Call by reference call by value and call value only.
by reference.
Structure and C++ supports Java doesn't support
Union structures and unions. structures and unions.
BITS Pilani, Pilani Campus
Comparison Index C++ Java
Thread Support C++ doesn't have Java has built-
built-in support for in thread support.
threads. It relies on
third-party libraries
for thread support.
Virtual Keyword C++ supports virtual Java has no virtual
keyword so that we keyword. Non-static
can decide whether or methods are virtual
not override a by default.
function.
unsigned right shift C++ doesn't support Supports unsigned
>>> >>> operator. right shift >>>
operator that fills zero
at the top for the
negative numbers.
For positive numbers,
it works same like >>
operator.
BITS Pilani, Pilani Campus
Queries asked during the
lecture
Why is the execution of a program using a interpreter slower
than the compiler?
• Unlike the compiler, interpreter does not generate an
intermediate machine code.
• Executing a machine code will be faster as no further
translation is not necessary for the instructions.
• But, the interpreter takes some time to translate the
high-level source code into machine understandable
instructions.
• Compilers do their work once and before the program is
executing, they have time for code optimization
• Interpreters have to trade time trying to optimize with possible
return on execution.
BITS Pilani, Pilani Campus