0% found this document useful (0 votes)
1 views

Java Basics

This document provides an overview of Java programming, highlighting its platform-independent and object-oriented features. It explains the purpose of the Java Virtual Machine (JVM), the Java Development Kit (JDK), and how to compile and run Java programs. Key concepts such as the distinction between high-level code and machine code, as well as the advantages of Java, are also discussed.

Uploaded by

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

Java Basics

This document provides an overview of Java programming, highlighting its platform-independent and object-oriented features. It explains the purpose of the Java Virtual Machine (JVM), the Java Development Kit (JDK), and how to compile and run Java programs. Key concepts such as the distinction between high-level code and machine code, as well as the advantages of Java, are also discussed.

Uploaded by

swamiajoba.manju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

What Is a Java

Program?
By
Manjiri Tatke
Objectives
• After completing this lesson, you should be able to:
• Contrast the terms “platform-dependent” and “platform-independent”
• Describe the purpose of the JVM
• Explain the difference between a procedural program and an object-oriented
program
• Describe the purpose of javac and java executables
• Verify the Java version on your system
• Compile and run a Java program from the command line
Topics
• Introduction to computer programs
• Introduction to the Java language
• Verifying the Java development environments
• Running and testing a Java program
Purpose of a Computer Program
• A computer program is a set of instructions that run on a computer or
other digital device.
• At the machine level, the program consists of binary instructions (1s and 0s).
• Machine code
• Most programs are written in high-level code (readable).
• Must be translated to machine code
Translating High-Level Code to
Machine Code

Solaris OS
C Compiler

Solaris OS Binary

Linux
C Compiler
Linux Binary
C Code

Microsoft Windows
C Compiler
Microsoft Windows
Binary
Linked to Platform-Specific Libraries
Project
Libraries
Solaris OS
C Compiler

Solaris OS Binary Solaris OS Executable

Project
Libraries

Linux
C Compiler
Linux Binary Linux Executable

Project
Libraries

Microsoft Windows
Microsoft Windows C Compiler Microsoft Windows
Binary Executable
Platform-Dependent Programs

Solaris OS Executable Solaris OS Workstation

Linux Executable Linux Workstation

Microsoft Windows Microsoft Windows Workstation


Executable
Topics

• Introduction to computer programs


• Introduction to the Java language
• Verifying the Java development environment
• Running and testing a Java program
Key Features of the Java Language
• Some of the features that set Java apart from most other languages
are that:
• It is platform-independent
• It is object-oriented
Java Is Platform-Independent

Java Code

Library Java Compiler


JARs
Java
Bytecode
Java Programs Run In a Java Virtual
Machine
JRE

Solaris OS
Java
Workstation
Bytecode
(.class file)
JRE

Linux
JRE Workstation

Java Virtual
Machine
(JVM)
Microsoft Windows
Workstation
Procedural Programming Languages
1 Step 1
• Many early programming languages followed a
paradigm called Procedural Programming.
• These languages use a sequential pattern of program execution.
• Drawbacks to procedural programming: 2 Step 2

• Difficult to translate real-world use cases


to a sequential pattern
• Difficult to maintain programs 3 Step 3
• Difficult to enhance as needed

4 Step 4

5 Step 5
Java Is an Object-Oriented Language
• Interaction of objects
• No prescribed sequence
• Benefits:
• Modularity
• Information hiding
• Code reuse
• Maintainability
What is Java?
• Java is an Object-Oriented programming language – most of it is free and open
source!
• It is developed in the early 1990s, by James Gosling of Sun Microsystems
• It allows development of software applications.
• It is amongst the preferred choice for developing internet-based applications
Topics

• Introduction to computer programs


• Introduction to the Java language
• Verifying the Java development environment
• Running and testing a Java program
Verifying the Java Development
Environment
1.Download and install the Java Development Kit (JDK) from oracle.com/java.
2.Examine the environment.
3.Compile and run a Java application by using the command line.
JRE versus JDK
• JRE is the “Java Runtime Environment”. It is responsible for creating a Java
Virtual Machine to execute Java class files (that is, run Java programs).
• JDK is the “Java Development Kit”. It contains tools for Development of Java
code (for example: Java Compiler) and execution of Java code (for example:
JRE)
• JDK is a superset of JRE. It allows you to do both – write and run programs.
Examining the Installed JDK: The
Tools

PATH
points
here

Runtime

Compiler
Topics

• Introduction to computer programs


• Introduction to the Java language
• Verifying the Java development environment
• Running and testing a Java program
Compiling and Running a Java
Program
is is
de e c. is
o d a s e
c in c o v tl i le fil by
r
e
c ed le .
ce y ja s u fi . ss d
o u in fi u r b re ss e) cl a te v a
a a d u ja e.
e
s nt v so iled h e la o e c
o
Th c .j
a
h e p T .c tec Th exe he tim
a T m a by t n
co ( ru

.java javac .class java


Compiling a Program
1.Go to the directory where the source code files are stored.
2.Enter the following command for each .java file you want to compile.

• Syntax:

javac <source file>


• Example:

javac SayHello.java
Executing (Testing) a Program
1.Go to the directory where the class files are stored.
2.Enter the following for the class file that contains the main method:

• Syntax:

java <classname>
• Example:
Do not specify .class.

java SayHello
• Output:

Hello World!
Output for a Java Program
• A Java program can output data in many ways. Here are some
examples:
• To a file or database
• To the console
• To a webpage or other user interface
Platform Independence feature of
Java
Unix on Pentium System

Macintosh PowerPC system


.java file
Class Loader
Bytecode verifier PowerPC machine
JIT compiler level instructions
Java compiler

Class file
containing Windows Pentium PC system
Bytecodes
Class Loader
Bytecode Verifier Pentium machine
Class Loader JIT compiler level instructions
Bytecode verifier
JIT compiler
JDK 11: Launch Single-File Source-Code
Programs
Benefits: Circle.java

• Skip the compilation "ceremony". public class Test {


public static void main(String args[]) {
• Run a program with one quick command: double area = Circle.findArea(7.5);
java <source file> System.out.print("Area of circle=" +area);
Requirements: }

• Write the entire program as single source }

file. public class Circle {


• The file may contain any number of public static double findArea(double radius){
classes. return Math.PI * radius * radius;

• The top-most class declares a main }

method. }

Use Cases:
java Circle.java
• Experiment quickly to learn Java.
Area of circle=176.714…
• Write small utility or "shebang" files.
Java Language Features
• Java has advantages due to the following features:
• Completely Object-Oriented
• Simple
• Robust: Strongly typed language
• Security
• Byte code Verifier
• Class Loader
• Security Manager
• Architecture Neutral: Platform independent
• Interpreted and Compiled
• Multithreaded: Concurrent running tasks
• Dynamic
• Memory Management and Garbage Collection
Quiz
• Which of the following is correct? (Choose all that apply.)
a. javac OrderClass
b. java OrderClass
c. javac OrderClass.java
d. java OrderClass.java
Summary
• In this lesson, you should have learned how to:
• Describe the distinction between high-level language and machine code
• Describe what platform-independence means
• Describe how a Java program is compiled and to what format
• Explain what it means to say that Java is an object-oriented language
• Determine the version number of a Java install
• Compile and run a Java program from the command line

You might also like