Object Oriented
Programming
Text Books
• The Complete Reference Java 2 by Herbert
Schildt
Grading Criteria
Quiz 10%
Assignment 10%
Mid Exam 30%
Final Exam 50%
CLASSROOM ETIQUETTE:
Arrive at class on time
Do be prepared for class
Most classes will begin on time and end on time. If
you need to know about schedule or assignment
changes, kindly ask about them from the class
representative. If you have a real need to leave
the class early, just leave quietly.
Do put cell phones away and on vibrate…Texting
should not be going on in class
Do stay AWAKE and be attentive
Topics To be Covered Today
What is a Program?
Evolution of Programming Languages
Why Java
Java History
Versions of Java
Features of Java
Java Procedure
What is a Program?
A computer program (also a software program, or just
a program) is a sequence of instructions written to
perform a specified task for a computer.
The Evolution of Programming
Languages
Machine language: 1940’s
Assembly language: early 1950’s
Higher-level languages: late 1950’s
◦ Fortran: scientific computation
◦ Cobol: business data processing
◦ Lisp: symbolic computation
Today: thousands of programming languages
https://statisticstimes.com/tech/top-computer-lang
uages.php
http://www.howtogeek.com/94917/the-evolution-of-computer-programming-
languages-infographic/
Machine Languages
Comprised of 1s and 0s
The “native” language of a computer
Difficult to program – one misplaced 1 or 0 will
cause the program to fail.
Example of code:
1110100010101 111010101110
10111010110100 10100011110111
Assembly Languages
Assembly languages are a step towards easier
programming.
Assembly languages are comprised of a set of
elemental commands which are tied to a
specific processor.
Assembly language code needs to be translated
to machine language before the computer
processes it.
Example:
ADD 1001010, 1011010
High-Level Languages
High-level languages represent a giant leap
towards easier programming.
The syntax of HL languages is similar to English.
Example:
Student_name = first_name + last_name
Interpreter – Executes high level language programs without
compilation.
Historically, we divide HL languages into two
groups:
◦ Procedural languages
◦ Object-Oriented languages (OOP)
What is Programming?
When we say “programming” we are actually
referring to the science of transforming our
intentions in a high-level programming language.
What are we doing in this course?
Learn programming in a high-level programming
language.
We will study Object-Oriented Programming
using ‘Java’, a popular high-level object-oriented
programming language.
Why Java?
It’s the current “hot” language
Java mean Cup of coffee
It’s almost entirely object-oriented
It has a vast library of predefined objects and
operations
It’s more platform independent
◦ this makes it great for Web programming
It’s more secure
It isn’t C++
Java History
Java
◦ was created in 1991
◦ by James Gosling et al. of Sun Microsystems.
◦ Initially called Oak, in honor of the tree outside
Gosling's window, its name was changed to Java
because there was already a language called Oak.
Java History contd. . . . .
The term Java actual refers to more than just a particular
language like C or Pascal. Java encompasses several
parts, including :
A high level language � the Java language is a high level one that
at a glance looks very similar to C and C++ but offers many unique
features of its own.
Java bytecode - a compiler, such as Sun's javac, transforms the
Java language source code to bytecode that runs in the JVM.
Java Virtual Machine (JVM) a program, such as Sun's java, that
runs on a given platform and takes the bytecode programs as input
and interprets them just as if it were a physical processor executing
machine code.
Java History contd. . . . .
Sun provides a set of programming tools such as
javac, java and others in a bundle that it calls a Java
Software Development Kit for each version of the
language and for different platforms such as Windows,
Linux, etc..
Sun also provides a runtime bundle with just the JVM
when the programming tools are not needed.
Versions of Java
Since its introduction, Sun has released a new
version of the Java language every two years or so.
These new versions brought enhancements, new
capabilities and fixes to bugs.
Until recently, the versions were numbered 1.x,
where x reached up till 4. (Intermediate revisions
were labeled with a third number - 1.x.y - as in
1.4.2.)
The next version, however, is called Java 5.0 rather
than Java 1.5.
Versions of Java
JDK 1.0 (January 23, 1996)
JDK 1.1 (February 19, 1997)
J2SE 1.2 (December 8, 1998)
J2SE 1.3 (May 8, 2000)
J2SE 1.4 (February 6, 2002)
J2SE 5.0 (September 30, 2004)
Versions of Java
Java SE 6 (December 11, 2006)
◦ Java SE 6 Update 10(Released October 15, 2008 )
◦ Java SE 6 Update 11(Released December 3, 2008)
◦ Java SE 6 Update 12
◦ Java SE 6 Update 14(Released May 28, 2009)
◦ Java SE 6 Update 16(Released August 11, 2009)
◦ Java SE 6 Update 17(Released November 4, 2009)
◦ Java SE 6 Update 18(Released January 13, 2010)
◦ Java SE 6 Update 19(Released March 30, 2010)
◦ Java SE 6 Update 20(Released April 15, 2010)
◦ Java SE 6 Update 21(Released July 7, 2010)
Versions of Java
Java SE 7.0
◦ Java 7 is a major update to Java (July 2011)
Java SE 8.0
◦ Java 8 is a major update to Java 7 (March 2014)
Java SE 9.0
◦ Java 9 is a major update to Java 8 (September 2017)
…….
……..
https://en.wikipedia.org/wiki/Java_version_history
Features of Java
Simple
◦ syntax is based on C++
◦ removed many confusing and/or rarely-used features
e.g., explicit pointers, operator overloading etc.
◦ No need to remove unreferenced objects because
there is Automatic Garbage Collection in java
object-oriented
◦ Code of the java Language is Written into the classes
and Objects So this feature of java is most Popular
because it also Supports Code Reusability,
Maintainability etc.
Features of Java
Java is platform Independent
◦ With Java, you can compile source code on Windows
and the compiled code (bytecode to be precise) can be
executed (interpreted) on any platform running a JVM.
So yes you need a JVM but the JVM can run any
compiled code, the compiled code is platform
independent
Java vs C++
C/C++ is not platform independent, because
when we compile C/C++ source code, it will
generate binary code which can be understood by
current OS only. When we move this source code
to other platform and then compile C/C++ binary
code, the binary code generated cannot be
understood by this new platform
Features of Java
Portable
◦ We may carry the java bytecode to any platform
Secure
◦ Java Programs run inside virtual machine sandbox
Features of Java
Java is Multi-Threaded. ... A
single Java program can have many different
threads executing independently and
continuously. Three Java applets on the same
page can run together with each getting equal
time from the CPU
Features of Java
interpreted and high-performance – Java
programs are compiled into an intermediate
representation – bytecode:
◦ can be later interpreted by any JVM
◦ can be also translated into the native machine code for
efficiency.
Features of Java
dynamic – The linking of data and methods to
where they are located, is done at run-time.
◦ New classes can be loaded while a program is running.
Linking is done on the fly.
◦ Even if libraries are recompiled, there is no need to
recompile code that uses classes in those libraries.
This differs from C++, which uses static binding.
Java Procedure
The essential steps to create and run Java
programs go as follows:
◦ Create a Java source code file
◦ Compile the source code
◦ Run the compiled code in a Java Virtual Machine.
Steps for creating and running a Java
program
Java Procedure Detail
You create the code with a text editor (for example
notepad) and save it to a file with the ".java" suffix.
All Java source code files must end with this type
name.
The first part of the name must match the class
name in the source code.
In the figure the class name is Test so you must
therefore save it to the file name Test.java.
Java Procedure Detail
With the javac program, you compile this file as
follows:
C:> javac Test.java
This creates a bytecode file (or files if the code file
included more than one class) that ends with the
".class" type appended.
◦ Here the output is Test.class.
◦ The bytecode consists of the instructions for the Java
Virtual Machine (JVM or just VM).
Java Procedure Detail
The JVM is an interpreter program that emulates a
processor that executes the bytecode instructions
just as if it were a hardware processor executing
native machine code instructions.
◦ The Java bytecode can then run on any platform in which
the JVM is available and the program should perform the
same.
◦ This Write Once, Run Anywhere (WORA) approach is a
key goal of the Java language.
Another Example with Bytecode
Representation
Test.java
Compile it with
> javac Test.java
Command used for
reading bytecode file
Bytecode
Representation
Programming Tools
◦ Integrated Development Environment (IDE) - graphical user
interface programming environments (often called GUI Builders)
are elaborate, programs that allow you to interactively build
graphical interfaces, edit the code, execute and run the applets
and applications all within the IDE system. Example Java IDEs
include:
NetBeans
Borland JBuilder
Eclipse
Dr Java
Programming Tools
Questions?