3. 3
Course Instructions
Hardware:
Faculty’s lab computers: A USB flash drive. Your own computer: Must be able to
run NetBeans or Eclipse IDE or Android Studio or IntelliJ.
Software:
Description IDE
A free, open-source IDE that runs on most modern operating systems. NetBeans is
commonly used for developing most types of Java applications, but not for Android apps.
NetBeans
A free, open-source IDE that runs on most modern operating systems. Eclipse is
commonly used for developing most types of Java applications, but not for Android apps.
Eclipse
The Community Edition of this IDE is a free, open-source IDE that runs on most modern
operating systems.
IntelliJ
An IDE specifically designed for Android development that’s based on IntelliJ IDEA and
backed by Google.
Android Studio
4. Java Programming Language Slide 4
An Introduction to Java
Programming
Lecture 1: An Introduction To Java Programming
5. Java Programming Language
Outline
Basic programming concepts
Program
Programming languages
Low-level language
High-level language
Java programming Language
Overview of Java
Bytecode & Java Virtual Machine
Characteristics of Java
A Simple Java Program
JDK, JRE & API
Install and configure the JDK
Developing Java Program using Notepad
Install the Eclipse IDE
Slide 5
6. Java Programming Language
Basic Programming Concepts
Program
A program is a set of instructions that tells a computer what to do in
order to perform a specific task.
Programming Language
A programming language is a formal language designed to
communicate instructions to a computer.
Slide 6
7. Java Programming Language
Basic Programming Concepts (continued)
Slide 7
Programming
Languages
Machine
Language
Assembly
Language
High-Level
Language
Low-Level
Language
8. Java Programming Language
Basic Programming Concepts (continued)
Machine Language (low level language)
It is the only language that is directly understood by the computer, and it does
not need to be translated. All instructions use binary notation and are
written as a sequence of 1s and 0s.
For example, here’s a weekly wages equation that multiply hours by an hourly
rate and stores the result in wages:
Machine language are cumbersome for humans. This is why assembly
languages come in.
Slide 8
100100 010001
100110 010010
100010 010011
wages = rate * hours
=
9. Java Programming Language
Basic Programming Concepts (continued)
Assembly Language (low level language)
An assembly language is the first step to improve programming structure and
make machine language more readable by humans. An assembly language
consists of a set of symbols and letters called a mnemonic codes.
A translator is required to translate the assembly language to machine
language. This translator program is called the assembler
The following section of an assembly-language to calculate a weekly wages
equation also multiply hours by an hourly rate and stores the result in
wages:
Slide 9
LOAD rate
MULT hours
STOR wages
wages = rate * hours
=
10. Java Programming Language
Basic Programming Concepts (continued)
High level language
A high-level language is very similar to human languages and has a set of
grammar rules that are used to make instructions more easily.
High-level languages are the languages most often used by programmers to
write programs. ( C++, Fortran, Pascal, Visual Basic, Java and Python)
A program written in a high-level language must be translated into machine
code for execution. This can be done using another programming tool called
an interpreter or a compiler.
Slide 10
wages = rate * hours
11. Java Programming Language
Java Programming Language
Java
In 1995, Sun Microsystems released a new programming language called
Java. Today, Java is owned by Oracle and is one of the most widely used
programming languages in the world. (James Gosling is the father of Java)
Java is a full-fledged and powerful language that can be used in many ways. It
comes in three editions:
Java Standard Edition (Java SE) to develop client-side applications. The
applications can run on desktop.
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.
Slide 11
12. Java Programming Language
Java Programming Language (continued)
Java
A key goal of Java is to be able to write programs that will run on
a great variety of computer systems and computer-controlled
devices. This is sometimes called “write once, run anywhere.”
Java applications are typically compiled to bytecode that can run
on any Java virtual machine (JVM) regardless of the underlying
computer architecture.
Slide 12
13. Java Programming Language
Java Programming Language (continued)
Bytecode & Java Virtual Machine
To run a Java program on a computer, the program must first be translated
into a platform-independent format called bytecode and then interpreted
into a particular machine language.
To make Java programs machine independent, the designers of the Java
language introduced a hypothetical computer called the Java Virtual
Machine (JVM).
Bytecode is the machine language for the JVM.
Slide 13
14. Java Programming Language
Java Programming Language (continued)
Java Source-Code
compiler
Java bytecode
Win
Mac
Unix
JVM
Interpreter
JVM
Interpreter
JVM
Interpreter
Slide 14
Welcome.java Welcome.class
15. Java Programming Language
Characteristics of Java
Java Is Simple
Java Is Portable “write once, run anywhere”
Java Is general-purpose programming language
Java Is Object-Oriented structure
Java Is Secure
Slide 15
16. Java Programming Language
A Simple Java Program
Slide 16
public class Welcome {
public static void main(String[] args)
{
System.out.println("Welcome to
Java");
}
}
Welcome to
Java
Class Name
Star with main method
Execute Statement
Statement Terminator
Output
// This is your first program
17. Java Programming Language
JDK, JRE & API
Java Development Kit (JDK)
The Java Development Kit (JDK) includes a compiler, a runtime environment,
and other tools that you can use to develop Java applications.
Java runtime environment (JRE)
It has all of the components necessary to run bytecode including a JVM. Since
JREs are available for most operating systems, Java bytecode can be run on
most operating systems.
Application program interface (API)
It also known as library, contains predefined classes and interfaces for
developing Java programs. You can view the latest Java API documentation
at https://docs.oracle.com/en/java/javase/16/
Slide 17
JDK
JRE
JVM
18. Java Programming Language
Before We Begin
1. Java Development Kit (JDK) Installation
JDK 16.1 for Windows is available from
https://www.oracle.com/java/technologies/javase-jdk16-downloads.html
2. Setting the PATH Environment Variable
Slide 18
19. Java Programming Language
Creating, Compiling & Executing a Java Program
When you develop a Java application, you typically use a code
editor to work with the source code for the application. Files
that contain source code have the .java extension.
The Java compiler translates Java source code into a platform-
independent format known as Java bytecode. Files that contain
Java bytecode have the .class extension.
A Java virtual machine (JVM) includes a Java interpreter that
executes Java bytecode. Most modern implementations of the
JVM have replaced the Java interpreter with a just-in-time
compiler (JIT compiler).
A JIT compiler is similar to an interpreter in some ways, but it
improves performance significantly.
Slide 19
20. Java Programming Language
Programming errors
Programming errors can be categorized into three types:
syntax errors, runtime errors, and logic errors.
Syntax errors or compile errors (Result from errors in code
construction).
Runtime errors (Errors that cause a program to terminate
abnormally. They occur while a program is running if the
environment detects an operation that is impossible to carry
out).
Logic errors (They occur when a program does not perform the
way it was intended to).
Slide 20
22. Java Programming Language
Compiling and Running Java from Eclipse
Java Integrated Development Environments (IDEs)
There are many Java integrated development environments that you can
use for Java programming. (NetBeans, Eclipse and IntelliJ)
https://www.eclipse.org/downloads/
Slide 22