Java
Programming Language
Instructor Name: Syed Shahzad Hassan
Department of Computer Science, HITEC University Taxila - Pakistan
Contents
2
Previous lecture overview
History of Java
Applications of Java
Types of Java applications, platform/editions, version history
Features of Java
Java is pure OOP language or not?
Java language, types of java programs
Java application program example, scanner class
Execution process of java program
Java compiler/interpreter
Assignment
Last Lecture overview
3
• The study of programming languages
• Introduction to programming paradigm
• Programming Language types
• Unstructured programming languages
• Procedural programming languages
• Structured programming languages
• Object Oriented programming (OOP) languages
• Building blocks of OOP
• Why OOP?
• Features of OOP
Last Lecture overview
4
The invention of the object oriented technology eliminates
the issues faced because of procedure oriented approach.
The OOP approach binds the data and functions that work
on it together.
The principle of data hiding helps the programmer to build
secure programs.
History of Java
5
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 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.
Notice that Java is just a name, not an acronym.
History of Java
7
Initially developed by James Gosling at Sun Mircosystems (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
8
According to Sun, more than 3 billion devices run Java. Some of
the Java Applications are as follows:
• Desktop Applications such as acrobat reader, media player,
antivirus, etc.
• Web Applications such as [Link], [Link], etc.
• Enterprise Applications such as banking applications.
• Mobile, Embedded System, Smart Card, Robotics, Games,
etc.
Types of Java Applications
9
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
• Standalone applications are also known as desktop applications or
window-based applications.
• Examples of standalone application are Media player, antivirus, etc.
• AWT(Abstract Windows Toolkit) and Swing are GUI toolkits in Java for
creating standalone applications.
Web Application
11
• 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.
Enterprise Application
12
• 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
13
An application which is created for mobile devices is called a mobile
application.
Currently, Android and Java ME are used for creating mobile
applications.
Java Platforms / Editions
14
There are 4 platforms or editions of Java:
• Java SE (Java Standard Edition)
• Java EE (Java Enterprise Edition)
• Java ME (Java Micro Edition)
• JavaFX
Java SE (Java Standard Edition)
15
It is the core Java programming platform.
It provides basic functionalities and libraries for application
development.
It includes Java programming APIs such as [Link], [Link], [Link],
[Link], [Link], [Link] etc.
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
It is an enterprise platform which is mainly used to develop web and
enterprise applications.
It is built on the top of the Java SE platform.
It includes topics like Servlet, JSP, Web Services, etc.
Java ME (Java Micro Edition)
17
It is a micro platform which is mainly used to develop mobile
applications.
Java FX
18
•JavaFX is a set of libraries and tools for creating rich client
applications with modern graphical user interfaces, multimedia
content, and visual effects.
•It is built on top of Java SE and provides additional APIs
specifically tailored for developing desktop applications with
enhanced GUI capabilities.
•JavaFX applications can include features such as animations,
multimedia playback, 3D graphics, and more.
Java Version History
19
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.
Encapsulation – Binding data and operations of data together in a single unit – A
class adheres to this feature
Inheritance and class hierarchy – Reusability and extension of existing classes
Features of Java
21
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 Language
22
o Java is pure object oriented programming language and a
platform.
o Java is a high level, robust, object-oriented and secure
programming language.
o Any hardware or software environment in which a program runs, is
known as a platform. Since Java has a runtime environment (JRE)
and API, it is called a platform.
o Platform independent language
Types of java programs
23
There are 5 types of Java programs –
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
*Compile source code to generate Byte code using Javac compiler.
*Execute the byte code program using Java interpreter.
Java program example
24
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 [Link] package and creates Graphical UserInterfaces
6. EJB (Enterprise Java Beans)
EJB components run on application servers, are accessed via the
client-server model, where clients communicate with EJB components
to build complex enterprise applications, including web applications.
Traditional Programming Paradigm
Java programming model
Java compiler/interpreter
28
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.
This bytecode is platform-independent and can be executed on
any system that has a Java Virtual Machine (JVM).
The byte code is then interpreted and executed by the JVM.
Why Java is compiler and interpreter?
Bytecode make Java a platform independent language
Java application program example
29
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, world!");
}
}
Java application program example
30
package Simple;
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, world!");
}
}
Java application program example
31
package Simple
{
public class Simple
{
public static void main(String args[])
{
[Link]("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 [Link]
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. [Link] is passed as a
parameter in Scanner class.
It tells the java compiler that system input will be provided through console(keyboard)
Scanner input = new Scanner([Link]);
Use of Scanner class (Example)
37
Use of Scanner class (Example)
38
import [Link]; // 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 = [Link]();
{ long mobileNo = [Link]();
// Declare the object and initialize with double cgpa = [Link]();
// predefined standard input object
Scanner sc = new Scanner([Link]); // Print the values to check if the input was correctly obtained.
// String input [Link]("Name: "+name);
String name = [Link](); [Link]("Gender: "+gender);
[Link]("Age: "+age);
// Character input [Link]("Mobile Number: "+mobileNo);
char gender = [Link]().charAt(0); [Link]("CGPA: "+cgpa);
}
}
Execution process of java program
39
References & Credits
40
• [Link]
• [Link]
program-in-detail-working-of-just-it-time-compiler-jit-in-
detail/
• [Link]
• Lecture Credits: Dr. Nouman Noor and Dr. Samia Ijaz for there
support in slide preparation.
41
THANK YOU