0% found this document useful (0 votes)
11 views23 pages

Lecture 2

The document provides an overview of object-oriented programming and Java. It discusses the history of Java, its applications, types including standalone, web, enterprise and mobile. It also covers key Java features such as classes, objects, inheritance and polymorphism. Examples are given of a simple Java program and use of the Scanner class. The execution process of a Java program is explained involving compilation to bytecode and interpretation by the JVM. Finally, it clarifies that Java is both a compiled and interpreted language.

Uploaded by

fahadraufhashmi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
11 views23 pages

Lecture 2

The document provides an overview of object-oriented programming and Java. It discusses the history of Java, its applications, types including standalone, web, enterprise and mobile. It also covers key Java features such as classes, objects, inheritance and polymorphism. Examples are given of a simple Java program and use of the Scanner class. The execution process of a Java program is explained involving compilation to bytecode and interpretation by the JVM. Finally, it clarifies that Java is both a compiled and interpreted language.

Uploaded by

fahadraufhashmi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 23

Object Oriented Programming

(OOP)

Instructor Name: Mr. Kamran Saeed


Department of Software Engineering, NUML Rawalpindi
Contents
2

 Previous lecture overview


 History of Java
 Applications of Java
 Types of Java applications
 Features of Java
 Java is pure OOP language or not?
 Java language
 Java application program example, scanner class
 Execution process of java program
 Java compiler/interpreter
History of Java
3

• 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.

Notice that Java is just a name, not an acronym.


History of Java
5

Initially developed by James Gosling at Sun Microsystems (which is now a


subsidiary of Oracle Corporation) and released in 1995.

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.

Now Java is being used in Windows applications, Web applications, enterprise


applications, mobile applications, cards, etc.

Each new version adds the new features in Java.


Applications of Java
6

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:

• Desktop Applications such as acrobat reader, media player, antivirus,


etc.

• Web Applications such as irctc.co.in, javatpoint.com, etc.

• Enterprise Applications such as banking applications.

• Mobile, Embedded System, Smart Card, Robotics, Games, etc.


Types of Java Applications
7

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

• Standalone applications are also known as desktop applications or window-


based applications.
• Examples of standalone application are Media player, antivirus, etc.
• AWT and Swing are used in Java for creating standalone applications.
• AWT stands for Abstract Window Toolkit. It is one of the original GUI
(Graphical User Interface) libraries in Java, introduced in JDK 1.0. AWT
provides a set of classes for creating and managing graphical user interface
components such as windows, buttons, menus, and dialogs.
Web Application
9

• An application that runs on the server side and creates a dynamic


page is called a web application.

• Currently, ServLet, JSP, Struts, Spring, Hibernate, etc. technologies


are used for creating web applications in Java.
• JSP stands for JavaServer Pages. It is a technology used for
developing dynamic web pages in Java.
Enterprise Application
10

• An application that is distributed in nature, such as banking


applications, etc. is called enterprise application.

• It has advantages of the high-level security, load balancing, and


clustering.

• In Java, EJV (Jakarta Enterprise Beans) is used for creating enterprise


applications.
Mobile Application
11

An application which is created for mobile devices is called a mobile


application.

Currently, Android and Java ME are used for creating mobile


applications.
Features of Java
12

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

Abstraction – Abstraction in object-oriented programming refers to the concept


of hiding implementation details and showing only essential features of an
object, allowing for a clear separation between interface and implementation.

Encapsulation – Binding data and operations of data together in a single unit – A


class adhere this feature

Inheritance and class hierarchy – Reusability and extension of existing classes


Features of Java
13

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.

Class libraries – Built-in language specific classes

Message passing – Objects communicates through invoking methods and sending


data to them. This feature of sending and receiving information among objects
through function parameters is known as Message Passing.

And more portable, platform independent, multithreaded, distributed, dynamic


Java application program example
14

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)

Scanner in = new Scanner(System.in);


Use of Scanner class (Example)
20

import java.util.Scanner; // Numerical data input


public class ScannerDemo1 // byte, short and float can be read
{ // using similar-named functions.
public static void main(String[] args) int age = sc.nextInt();
{ long mobileNo = sc.nextLong();
// Declare the object and initialize with double cgpa = sc.nextDouble();
// predefined standard input object
Scanner sc = new Scanner(System.in); // Print the values to check if the input was correctly obtained.

// String input System.out.println("Name: "+name);


String name = sc.nextLine(); System.out.println("Gender: "+gender);
System.out.println("Age: "+age);
System.out.println("Mobile Number: "+mobileNo);
System.out.println("CGPA: "+cgpa);
}
}
Execution process of java program
21
Java compiler/interpreter
22

Is Java a compiler or interpreter?

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

You might also like