Lecture 1.1 - Introducing Java
Lecture 1.1 - Introducing Java
“Instead of imagining that our main task is to instruct a computer what to do, let
us concentrate rather on explaining to human beings what we want a computer
to do.” - Donald Knuth
• Example:
• Dogs have state (name, color, breed, hungry) and behavior (barking,
fetching, wagging tail)
• Bicycles also have state (current gear, current pedal cadence, current
speed) and behavior (changing gear, changing pedal cadence, applying
brakes)
Importance of OOP
What is OOP
Process-Oriented Model:
This approach characterizes a program as a series of linear steps (that is,
code).
In this model, programs are typically organized around code. This approach
can be thought of as code acting on data.
Procedural languages such as C employ this model to considerable success.
In procedural programming, program is divided into small parts called
functions.
Procedural programming follows top down approach.
In procedural programming, function is more important than data.
Importance of OOP
Why OOP (Process-Oriented Model)
Problems with this approach appear as programs grow larger and more
complex.
As function has complete access to the global variables, it is possible that new
programmer can corrupt the data accidentally by creating functions.
Data is exposed to whole program, so no security for data.
In large program it is very difficult to identify what data is used by which
function.
Difficult to relate with real world objects.
Difficult to create new data types reduces extensibility.
Importance is given to the operation on data rather that the data.
Importance of OOP
Why OOP (Object-Oriented Programming)
It is not possible to code in java without class and object. Even to write a
single hello world program, we need to declare a class.
Java supports encapsulation.
Java supports abstraction.
Java supports inheritance.
Java supports polymorphism.
JVM Architecture
Introduction to JVM
In the Java programming language, all source code is first written in plain text
files ending with the .java extension.
Those source files are then compiled into .class files by the javac compiler.
A .class file does not contain code that is native to your processor; it instead
contains bytecodes—the machine language of the Java Virtual Machine (Java
VM).
The java launcher tool then runs application with an instance of the Java
Virtual Machine.
JVM Architecture
Why Java is Platform Independent
To execute, run the Java VM and include the name of the class which contains
the "main" method as the first command line parameter.
• https://www.cs.mcgill.ca/~rwest/wikispeedia/wpcd/wp/p/Progra
mming_language.htm
• https://www.scriptol.com/programming/history.php
• https://docs.oracle.com/javase/tutorial/