Lecture 2
Lecture 2
(OOP)
• James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java
language project in June 1991.
• The small team of sun engineers called Green Team.
• Initially designed for small, embedded systems (we did not install software)
in electronic appliances.
• Firstly, it was called "Greentalk" by James Gosling, and the file extension
was .gt.
• After that, it was called Oak and was developed as a part of the Green
project.
History of Java
4
Why Oak? Oak is a symbol of strength and chosen as a national tree of many
countries like the U.S.A., France, Germany, Romania, etc.
In 1995, Oak was renamed as "Java" because it was already a trademark by Oak
Technologies.
Java is an island of Indonesia where the first coffee was produced (called java
coffee). It is a kind of espresso bean. Java name was chosen by James Gosling
while having coffee near his office.
In 1995, Time magazine called Java one of the Ten Best Products of 1995.
JDK 1.0 released in(January 23, 1996). After the first release of Java, there have
been many additional features added to the language.
According to Sun, more than 3 billion devices run Java. There are many
devices where Java is currently used. Some of them are as follows:
There are mainly 4 types of applications that can be created using Java
programming:
• Standalone Application
• Web Application
• Enterprise Application
• Mobile Application
Standalone Application
8
Class definitions – Basic building blocks OOP and a single entity which has data
and operations on data together
Objects – The instances of a class which are used in real functionality – its
variables and operations
Polymorphism – Multiple definitions for a single name - functions with same name
with different functionality; saves time in investing many function names Operator
and Function overloading
Generic classes – Class definitions for unspecified data. They are known as container
classes. They are flexible and reusable.
package Simple
{
class Simple
{
public static void main(String args[])
{
System.out.println("Hello Java");
}
}
} Output Hello Java
Java program example
15
Java program example
16
Java program example
17
public:
public keyword is an access modifier which represents visibility, it means it is visible to
all.
To call by JVM from anywhere.
This makes the main method public that means that we can call the method from
outside the class.
static:
static is a keyword, if we declare any method as static, it is known as static method.
The core advantage of static method is that there is no need to create object to invoke
the static method.
The main method is executed by the JVM, so it doesn't require to create object to invoke
the main method. So it saves memory.
Without existing object also JVM has to call this method.
Java program example
18
void:
void is the return type of the method, it means it doesn't return any value.
Main method won’t return anything to JVM.
main:
It is the method name. This is the entry point method from which the JVM can run your program.
This is the name which is configured inside JVM and searched by JVM as a starting point for an
application with a particular signature only.
String[] args:
Used for command line arguments that are passed as strings.
It is the parameter to the main Method.
Here we are defining a String array to pass arguments at command line. args is the variable name
of the String array. It can be changed to anything such as String [] a.
Scanner class
19
The Scanner class is mainly used to get the user input, and it belongs to the java.util
package.
In order to use the Scanner class, you can create an object of the class and use any of
the Scanner class methods.
Scanner class allows user to take input from console. System.in is passed as a
parameter in Scanner class.
It tells the java compiler that system input will be provided through console(keyboard)
Java is a compiled programming language, but rather than compile straight to executable
machine code, it compiles to an intermediate binary form called JVM byte code. The byte code is
then compiled and/or interpreted to run the program.
Just-In-Time (JIT) compilation is a technique used in Java and other programming languages to
improve the performance of bytecode execution.
Why Java is compiler and interpreter?
Java compiler compiles the source code into bytecode. JVM i.e. Java virtual machine is an
interpreter which interprets the byte code. Bytecode make Java a platform independent
language
23
THANK YOU