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

Computer Science Faculty: Nangarhar University

This document provides an overview of Java programming including: - Java is an object-oriented programming language created by Sun Microsystems. - It discusses how to download and configure the Java Development Kit (JDK). - The key differences between Java and C++ and how Java uses a virtual machine to execute programs platform independently. - It explains compiling, interpreting, and the structure of a basic Java program including the main method.

Uploaded by

Nasir khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Computer Science Faculty: Nangarhar University

This document provides an overview of Java programming including: - Java is an object-oriented programming language created by Sun Microsystems. - It discusses how to download and configure the Java Development Kit (JDK). - The key differences between Java and C++ and how Java uses a virtual machine to execute programs platform independently. - It explains compiling, interpreting, and the structure of a basic Java program including the main method.

Uploaded by

Nasir khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Nangarhar University

Computer Science Faculty


Software Engineering Department
Advance Object Oriented
Programming
Semester :4
Credit Hours: 03
Java Introduction

Date: 02/11/2019
Prepared by: Amin Gul Zakhil
Contents

• What is Java?
• How to Get Java
• Compare Java and C++
• Compiling and Interpreting Applications
• The JDK Directory Structure
• A First Java Program
What is Java

• A programming language specifies the words and symbols that we


can use to write a program
• A programming language employs a set of rules that dictate how the
words and symbols can be put together to form valid program
statements
• The Java programming language was created by Sun Microsystems,
Inc.
• It was introduced in 1995 and it's popularity has grown quickly since
How to get and configure Java

• Java.sun.com go to download and select Java SE;


• Select JDK and download it.
• Configure the path variable with the specific java bin path
• That’s it!
History of Java

"Java, whose original name was Oak, was developed as a part of the Green
project at Sun. It was started in December '90 by Patrick Naughton, Mike
Sheridan and James Gosling and was chartered to spend time trying to figure
out what would be the "next wave" of computing and how we might catch it.
They came to the conclusion that at least one of the waves was going to be the
convergence of digitally controlled consumer devices and computers. "
Compiling and Interpreting java

• Executing program
• Computer can only execute the code in binary form
• A program written in high-level language is called a source program or source
code.
• Because a computer cannot understand a source program, a source program
must be translated into machine code for execution.
• A translation can be done using another programming tool called interpreter
or compiler
Compiling and Interpreting java

• What is a compiler
• A compiler translate the entire code into a machine-code file to any
intermediate code, and that file is then executed.
Compiling and Interpreting java

• What is an interpreter
• An interpreter read one statement from the source code, translate it to
machine code or virtual machine code, and then execute it right away.
How Java works?
How Java works?

• Java's platform independence is achieved by the use of the Java


Virtual Machine
• A Java program consists of one or more files with a .java extension
• these are plain old text files
• When a Java program is compiled the .java files are fed to a compiler
which produces a .class file for each .java file
• The .class file contains Java bytecode.
• Bytecode is like machine language, but it is intended for the Java
Virtual Machine not a specific chip such as a Pentium or PowerPC chip
How Java works?

• To run a Java program the bytecode in a .class file is fed to an


interpreter which converts the byte code to machine.
• Some people refer to the interpreter as "The Java Virtual Machine"
(JVM)
• The interpreter is platform specific because it takes the platform
independent bytecode and produces machine language instructions
for a particular chip
• So a Java program could be run an any type of computer that has a
JVM written for it.
How java program execute
Java program structure

• In the Java programming language:


• A program is made up of one or more classes
• A class contains one or more methods
• A method contains program statements

• These terms will be explored in detail throughout the course


• A Java application always contains a method called main
Compare Java & C++
Compare Java & C++
Difference between JVM, JRE & JDK
JVM

• JVM-> Java Virtual Machine


• It provide runtime environment in which java bytecode can be
executed
• Tasks of JVM
• Load the code
• Verifies the code
• Execute the code
• Provide runtime environment
• JVM is a platform dependent i.e for each software and hardware we
have different JVM configuration.
JRE

• JRE-> Java Runtime Environment


• JRE-> JVM+ Set of libraries
• It is the implementation of JVM
• To run any java code the JRE is the minimum requirement.
• So JRE is a set of libraries that a JVM is using at runtime.
• JRE physically exists.
• JRE is platform dependent.
JDK

• JRE-> Java Development Kit


• JRE-> JRE+ Development tools
• JDK is a full featured software development kit.
• JRE
• JVM+ Libraries
• Development tools
• Debugger+Compiler+JavaDoc
• JDK is a complete package for software development.
Practical Purpose
A First Java Program

/**
* A simple program
*/

public class HelloWorld


{
public static void main(String[] args)
{
System.out.println("HELLO CS307!");
}
}
…Java Program Structure

// comments about the class


public class MyProgram
{
class header

class body

Comments can be placed almost anywhere


}
…Java Program Structure

// comments about the class


public class MyProgram
{

// comments about the method


public static void main (String[] args)
{
method header
method body
}

}
Comments

• Comments in a program are called inline documentation


• They should be included to explain the purpose of the program and
describe processing steps
• They do not affect how a program works
• Java comments can take three forms:
// this comment runs to the end of the line

/* this comment runs to the terminating


symbol, even across line breaks */

/** this is a javadoc comment */


References
• http://www.javatpoints.com
• http://www.tutorialspoint.com/java

You might also like