Oop Lecture 02
Oop Lecture 02
Programming Language
The OOP approach binds the data and functions that work
on it together.
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language
project in June 1991.
Initially designed for small, embedded systems in electronic appliances like set-
top boxes.
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
6
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.
There are mainly 4 types of applications that can be created using Java
programming:
• Standalone Application
• Web Application
• Enterprise Application
• Mobile Application
Standalone Application
10
• AWT(Abstract Windows Toolkit) and Swing are GUI toolkits in Java for
creating standalone applications.
Web Application
11
• JavaFX
Java SE (Java Standard Edition)
15
It includes core topics like OOPs, String, Regex, Exception, Inner classes,
Multithreading, I/O Stream, Networking, AWT, Swing, Reflection,
Java EE (Java Enterprise Edition)
16
Many java versions have been released till now. The current stable release of
Java is Java SE 10.
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 Mar 2014)
Java SE 9 (21st Sep 2017) Java SE 10 (20th Mar 2018)
Features of Java
20
Class definitions – Basic building blocks of OOP and a single entity that has data
and operations performed on data together
Objects – The instances of a class which are used in real functionality – its
variables and operations
Abstraction – Specifying what to do but not how to do it; a flexible feature for
having an overall view of an object’s functionality.
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.
1. Application Program
Programs that are written to carry out certain tasks on local computer
depends on your logic like solving equations, reading and writing files.
The application programs can be executed using two steps
2. Applet Program
*Applets are small Java programs developed for Internet applications. An applet
can be shared which is located in a distant computer via the Internet and
executed on a local computer using a Java-capable browser.
3. Jar file
*JAR files are commonly used for distributing standalone Java applications,
libraries, or components
*simplifies distribution, installation, and execution of Java Applications
4. Servlet
*A server-side component that extends the functionality of the webserver to
generate dynamic web content on the web browser.
Java program example
25
5. Swing Application
Uses Javax.swing package and creates Graphical UserInterfaces
System.out.println("Hello, world!");
}
}
Java application program example
30
package Simple;
System.out.println("Hello, world!");
}
}
Java application program example
31
package Simple
{
public class Simple
{
public static void main(String args[])
{
System.out.println("Hello Java");
}
}
} Output Hello Java
Java program example
32
Java program example
33
Java program example
34
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.
Java program example
35
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
36
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)
• https://www.javatpoint.com/java-tutorial
• https://simplesnippets.tech/execution-process-of-java-
program-in-detail-working-of-just-it-time-compiler-jit-in-
detail/
• https://www.javatpoint.com/Scanner-class
• Lecture Credits: Dr. Nouman Noor and Dr. Samia Ijaz for there
support in slide preparation.
41
THANK YOU