0% found this document useful (0 votes)
13 views32 pages

Introduction to Java Programming Basics

The document introduces Java, a popular programming language created in 1995, highlighting its characteristics, development environment, and the differences between Java and JavaScript. It explains the roles of JDK, JRE, and JVM in Java programming and outlines the typical phases of Java program development. The document also emphasizes Java's versatility, security, and community support, making it a preferred choice for various applications.

Uploaded by

duroof4821277
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views32 pages

Introduction to Java Programming Basics

The document introduces Java, a popular programming language created in 1995, highlighting its characteristics, development environment, and the differences between Java and JavaScript. It explains the roles of JDK, JRE, and JVM in Java programming and outlines the typical phases of Java program development. The document also emphasizes Java's versatility, security, and community support, making it a preferred choice for various applications.

Uploaded by

duroof4821277
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introducing Java

By Muhammad Abbas
Week #: 01 Lecture #: 01-03

1
Objectives
• To understand basics of Java
• To learn Characteristics of Java
• To understand Java Environment (JRE, JDK, JVM)
needed for development
• To write first Java Program

2
1. Introduction to Java
• Java is a popular programming language, created
in 1995.

• It is owned by Oracle, and more than 3 billion


devices run Java.

– Mobile applications (specially Android apps)


– Desktop applications
– Web applications
– Web servers and application servers
– Games
– Database connection
– And much, much more!

3
1. Introduction to Java (Why Use Java?)

• Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
• It is one of the most popular programming languages in the world
• It has a large demand in the current job market
• It is easy to learn and simple to use
• It is open-source and free
• It is secure, fast and powerful
• It has huge community support (tens of millions of developers)

• Java is an object-oriented language which gives a clear structure to


programs and allows code to be reused, lowering development costs

• As Java is close to C++ and C#, it makes it easy for programmers to switch
to Java or vice versa

4
1. Introduction to Java
• Java is a programming language (Technology) based on OOP.

• It was first developed by James Gosling at Sun Microsystems,


which is now part of Oracle Corporation.

• It was released in 1995 as a part of Sun Microsystems' Java


platform.

• The language has developed much of its


syntax from C and C++.

5
1. History of Java

• Java was developed by James Gosling, who is


known as the father of Java, in 1995.

• James Gosling and his team members started


the project in the early '90s.

6
1. History of Java

• Java was created at Sun Microsystems, Inc., where James


Gosling led a team of researchers to create a new language
that would allow consumer electronic devices to
communicate with each other. Work on the language began in
1991, and before long the team's focus changed to a new
niche, the World Wide Web.

7
1. History of Java
• Originally for intelligent consumer-electronic devices

• Then used for creating Web pages with dynamic content

• Now also used to:


• Develop large-scale enterprise applications
• Provide applications for consumer devices (cell phones, etc.)

8
1. Java Is Not JavaScript!
• Java is a programming language. You write programs in it and
compile them.

• JavaScript is embedded in a web page and run by Internet


Explorer or Firefox

• Java applets are programs that run in a web browser


• Java Server Pages (JSP) is a server-side programming
technology that enables the creation of dynamic, platform-
independent methods for building Web-based applications

9
1. With C++ and most compiled languages

Your Program
Source Code

If x = 5 then…

Compiler For Windows PC Compiler For Mac

1011 0011 0011 1111

PC with Windows Mac


10
1. Java Virtual Machine
Your Program
Source Code

If x = 5 then…

Java Compiler

ByteCode

Windows JVM Mac JVM

1011 0011 0011 1111

PC with Windows Mac 11


1. Typical Java Development Environment

• Java programs normally undergo five phases


– Edit
• Programmer writes program (and stores program on disk)
– Compile
• Compiler creates bytecodes from program
– Load
• Class loader stores bytecodes in memory
– Verify
• Bytecode Verifier confirms bytecodes do not violate security restrictions
– Execute
• JVM translates bytecodes into machine language

12
Fig. 1.1 | Typical Java development environment.

13
1. Why Java?
Java is a powerful and versatile programming
language for developing software running on
mobile devices, desktop computers, and servers.

– Internet programming language.


– write it once and run it anywhere.
– General purpose programming language.

14
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed (multiple networked computers)
• Java Is Interpreted (executed line by line by the JVM)
• Java Is Robust (handles errors gracefully)
• Java Is Secure
• Java Is Architecture-Neutral (run on any hardware or operating system)
• Java Is Portable
• Java's Performance
• Java Is Multithreaded (concurrent execution, multiple tasks simultaneously)
• Java Is Dynamic

15
Java Editions
• Java Standard Edition (Java SE) to develop client-side
standalone applications or applets.

• Java Enterprise Edition (Java EE) to develop server-side


applications, such as Java servlets, JavaServer Pages
(JSP), and JavaServer Faces (JSF).

• Java Micro Edition (Java ME) to develop applications


for mobile devices, such as cell phones.

16
Programming in Java
• For executing any Java program, you need to

 Download the JDK and install it.


 set path of the jdk/bin directory.
 create the java program
 compile and run the java program

17
JDK, JRE & JVM
• JVM: Java Virtual Machine is an abstract machine. It is an
interpreter. It is a specification that provides a runtime
environment in which Java bytecode can be executed.

• JRE: Java Runtime Environment. It implements the JVM


where Java programs run on. It physically exists. It contains
a set of libraries + other files that JVM uses at runtime.

• JDK: It's the full-featured Software Development Kit for


Java, including JRE, and the compilers and tools (like Java
Debugger) to create and compile programs.

18
What is JVM (Java Virtual Machine)?
• When you run the Java program, Java
compiler first compiles your Java code to
bytecode. Then, the JVM translates bytecode
into native machine code(CPU executes directly).

23
What is JVM (Java Virtual Machine)?
• Java is platform-independent because it runs
on the Java Virtual Machine (JVM), not
directly on the computer's hardware.

• Since JVM ​executes the Java bytecode which


is platform-independent, Java is platform-
independent.

24
What is JRE (Java Runtime Environment)?
• JRE is a software package that provides Java
class libraries, JVM, and other components
that are required to run Java applications.

• JRE is the superset of JVM.

25
What is JDK (Java Development Kit)?
• software development kit required to develop
applications in Java.
• When you download JDK, JRE is also
downloaded with it…

• The JDK includes development tools like compilers, JavaDoc, and the Java
Debugger. JavaDoc creates documentation from code comments, while
the Debugger helps find errors, inspect variables, and track program
execution.

26
JDK vs JRE vs JVM
• JDK is for development purposes whereas JRE is
for running the java programs.

• JDK and JRE both contain JVM so that we can


run our Java program.

• JVM is the heart of Java programming language


and provides platform independence.

27
Working Flow Of Java Program (JDK, JRE & JVM)

28
Does Java supports compiler and
interpreter?

If Yes, than How?

29
why java use both compiler and interpreter

• Java can be considered both a compiled and an


interpreted language because its source code is
first compiled into a binary byte-code.

• This byte-code runs on the Java Virtual Machine


(JVM), which is usually a software-based
interpreter.

30
What is Byte Code?

31
.java VS .class
Java file:
– The actual Java source file is written by a Java
programmer.
– Human readable
– Before compilation.

Class file:
– A Java class file is a file containing Java bytecode that
can be executed on the Java Virtual Machine (JVM).
– After compilation.
– Intended for the machine to execute.
32
Code Compilation

33
First Java Program

class Simple
{
public static void main(String args[])
{
[Link]("Hello Java");
}
}

34
Executing Java Program
• Save the file with name Simple and .java extension in D drive.
• Compile the program

• d:
• set path=C:\Program
Files\Java\jdk1.6.0_23\bin
• javac [Link]

• Execute the program


• java Simple

35
END…

36

You might also like