1. Computer Technology Institute (CTI)
Programming Fundamentals Using Java
Lecture 1
Jawid Ahmad Niazi
Technical Institute of Ghazni
Prepared By: Jawid Ahmad Niazi 1
2. • Java technology is both a programming language and a platform
• The Java programming language is a high-level language that
can be characterized by all of the following
– Simple
– Architecture neutral
– Object oriented
– Portable
Prepared By: Jawid Ahmad Niazi 2
3. • In the Java programming language, all source code is first written in
plain text files ending with the .java extension.
• Those source files are then compiled into .class files by the Java
compiler (javac).
• A .class file does not contain code that is native to your processor;
it instead contains bytecodes-- the machine language of the Java
Virtual Machine.
Prepared By: Jawid Ahmad Niazi 3
4. Prepared By: Jawid Ahmad Niazi 4
• Name the person(s) who developed Java?
• Answer: Java was developed by James Gosling &
Patrick Naughton at Sun Microsystems, Inc. in 1991.
• What was the initial name of Java?
• Answer: Java language was initially called “Oak” and
was renamed “Java” in 1995.
5. • Important features of JAVA.
• Java is a platform - independent language It is highly
reliable
• It is a distributed language
• It is an object oriented language
• What kind of files contain Java source code?
• Answer: The Java source code is saved in files with names the end
with “.java”.
Prepared By: Jawid Ahmad Niazi 5
6. Prepared By: Jawid Ahmad Niazi 6
• What is source code?
• Answer: Source code is the plain text that makes up the part or
all of a computer program.
• What is bytecode?
• Answer: Bytecode is a low-level computer language translation
of Java source code program.
7. Prepared By: Jawid Ahmad Niazi 7
• The Java launcher tool (java) then runs your
application with an instance of the Java Virtual
Machine.
8. Prepared By: Jawid Ahmad Niazi 8
Platform
Independen
8
ce
Java
Program
Java
Compiler
(javac)
Java
Byte Code
Can be
executed
MS-DOS
Windows (X)
UNIX
Any other (O.S.)
Source Code JavaVirtual
Machine
9. Prepared By: Jawid Ahmad Niazi 9
• Because the Java Virtual Machine is available on
many different operating systems, the same .class
files are capable of running on
– Microsoft Windows,
– the Solaris TM Operating System (SolarisOS),
– Linux, or
– MacOS.
10. Prepared By: Jawid Ahmad Niazi 10
What is a Java virtual machine?
Answer: A Java virtual machine(JVM) is a software
system that translates and executes Java bytecode.
Name two types of Java programs?
Answer: We can develop two types of Java
programs
1. Stand-alone application
2. Web applets
11. Prepared By: Jawid Ahmad Niazi 11
• Your first application, HelloWorldApp, will simply
display the greeting "Hello world!". To create this
program, you will:
Create a source file. A source file contains text,
written in the Java programming language, that you and
other programmers can understand. You can use any
text editor to create and edit source files.
Compile the source file into a .class file. The Java
compiler, javac, takes your source file and translates its
text into instructions that the Java Virtual Machine can
understand. The instructions contained within this file
are known as bytecodes.
Run the program. The Java launcher (java) uses the
Java Virtual Machine to run your application.
12. • First, start your editor. You can launch the NotePad editor from
the Start menu by selecting Programs > Accessories >
NotePad. In a new document, type in the following code:
• /**
• * The HelloWorldApp class implements an application that
• * simply displays "Hello World!" to the standard output.
• */
• class HelloWorldApp {
• public static void main(String[] args) {
• //Display "Hello World!"
• System.out.println("Hello World!");
• }
• }
• You can save the file as HelloWorldApp.java
Prepared By: Jawid Ahmad Niazi
13. Prepared By: Jawid Ahmad Niazi
• You can save the file as HelloWorldApp.java
13
14. Prepared By: Jawid Ahmad Niazi 14
• Bring up a shell, or "command," window
• You can do this from the Start menu by choosing MS-DOS
Prompt (Windows 7/8/10) or Command Prompt (Windows
NT/XP), or by choosing Run... and then entering cmd
15. Prepared By: Jawid Ahmad Niazi 15
• To Compile the Program, execute the compiler, javac, specifying
the name of the source file on the command line
C:> javac HelloWorldApp.java
• The java compiler creates a file called HelloWorldApp.class
• To run the program, we must use the Java Interpreter called
Java by,
java HelloWorldApp
• The output is displayed,
Hello World!
16. Lab Assignment
• 1. Write a program to display the following output
• My name is
I am years old
• I study in Technical Institute at Ghazni
Prepared By: Jawid Ahmad Niazi 16