0% found this document useful (0 votes)
68 views12 pages

CHAPT1

The document discusses some key characteristics of Java: 1. Java is platform independent so the same program can run on any correctly implemented Java system. 2. Java is object-oriented and structured in terms of classes that group data with operations on that data, and new classes can be constructed by extending existing ones. 3. Java is designed as a core language plus a rich collection of commonly available packages.

Uploaded by

isayashpbende26
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)
68 views12 pages

CHAPT1

The document discusses some key characteristics of Java: 1. Java is platform independent so the same program can run on any correctly implemented Java system. 2. Java is object-oriented and structured in terms of classes that group data with operations on that data, and new classes can be constructed by extending existing ones. 3. Java is designed as a core language plus a rich collection of commonly available packages.

Uploaded by

isayashpbende26
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/ 12

Some Salient Characteristics of Java

• Java is platform independent: the same program can


run on any correctly implemented Java system
• Java is object-oriented:
• Structured in terms of classes, which group data with
operations on that data
• Can construct new classes by extending existing ones
• Java designed as
• A core language plus
• A rich collection of commonly available packages
• Java can be embedded in Web pages

Appendix A: Introduction to Java 3


Unicode System

Unicode is a universal international standard character encoding that is capable of representing


most of the world's written languages.
Why java uses Unicode System?
Before Unicode, there were many language standards:
Before Unicode, there were many language standards:

•ASCII (American Standard Code for Information Interchange) for the United States.
•ISO 8859-1 for Western European Language.
•KOI-8 for Russian.
•GB18030 and BIG-5 for chinese, and so on.

Problem

This caused two problems:


1.A particular code value corresponds to different letters in the various language standards.
2.The encodings for languages with large character sets have variable length.Some common characters
are encoded as single bytes, other require two or more byte.

Solution
To solve these problems, a new language standard was developed i.e. Unicode System.
In unicode, character holds 2 byte, so java also uses 2 byte for characters.
Compiling and Executing a Java Program

Appendix A: Introduction to Java 5


JVM (Java Virtual Machine) Architecture
Java Virtual Machine

Internal Architecture of JVM


JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.

JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).

What is JVM
It is:

1. A specification where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Oracle and
other companies.

2. An implementation Its implementation is known as JRE (Java Runtime Environment).

3. Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is created.

What it does
The JVM performs following operation:
o Loads code
o Verifies code
o Executes code
o Provides runtime environment
JVM provides definitions for the:
o Memory area
o Class file format
o Register set
o Garbage-collected heap
o Fatal error reporting etc.
JVM Architecture
Let's understand the internal architecture of JVM. It contains classloader, memory area, execution engine etc.

1) Classloader
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java
program, it is loaded first by the classloader. There are three built-in classloaders in Java.

1. Bootstrap ClassLoader: This is the first classloader which is the super class of Extension
classloader. It loads the rt.jar file which contains all class files of Java Standard Edition like
java.lang package classes, java.net package classes, java.util package classes, java.io package
classes, java.sql package classes etc.

2. Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of
System classloader. It loades the jar files located inside $JAVA_HOME/jre/lib/ext directory.

3. System/Application ClassLoader: This is the child classloader of Extension classloader. It


loads the classfiles from classpath. By default, classpath is set to current directory. You can
change the classpath using "-cp" or "-classpath" switch. It is also known as Application
classloader.
These are the internal classloaders provided by Java. If you want to create your own classloader,
you need to extend the ClassLoader class.
2) Class(Method) Area
Class(Method) Area stores per-class structures such as the runtime constant pool, field and method data, the code for methods.

3) Heap
It is the runtime data area in which objects are allocated.

4) Stack
Java Stack stores frames. It holds local variables and partial results, and plays a part in method invocation and return.

Each thread has a private JVM stack, created at the same time as thread.

A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.

5) Program Counter Register


PC (program counter) register contains the address of the Java virtual machine instruction currently being executed.

6) Native Method Stack


It contains all the native methods used in the application.

7) Execution Engine
It contains:

1. A virtual processor

2. Interpreter: Read bytecode stream then execute the instructions.

3. Just-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces
the amount of time needed for compilation. Here, the term "compiler" refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a
specific CPU.

8) Java Native Interface


Java Native Interface (JNI) is a framework which provides an interface to communicate with another application written in another language like C, C++, Assembly etc. Java uses
JNI framework to send output to the Console or interact with OS libraries.
Classes and Objects
• The class is the unit of programming
• A Java program is a collection of classes
• Each class definition (usually) in its own .java file
• The file name must match the class name
• A class describes objects (instances)
• Describes their common characteristics: is a blueprint
• Thus all the instances have these same characteristics
• These characteristics are:
• Data fields for each object
• Methods (operations) that do work on the objects

Appendix A: Introduction to Java 9


Grouping Classes: The Java API
• API = Application Programming Interface
• Java = small core + extensive collection of packages
• A package consists of some related Java classes:
• Swing: a GUI (graphical user interface) package
• AWT: Application Window Toolkit (more GUI)
• util: utility data structures (important to CS 187!)
• The import statement tells the compiler to make available classes and
methods of another package
• A main method indicates where to begin executing a class (if it is
designed to be run as a program)
Appendix A: Introduction to Java 10
A Little Example of import and main
import javax.swing.*;
// all classes from javax.swing
public class HelloWorld { // starts a class
public static void main (String[] args) {
// starts a main method
// in: array of String; out: none (void)
}
}
• public = can be seen from any package
• static = not “part of” an object
Appendix A: Introduction to Java 11
import java.util.Scanner;
class Input {
public static void main(String[] args) {

Scanner input = new Scanner(System.in);

// Getting float input


System.out.print("Enter float: ");
float myFloat = input.nextFloat();
System.out.println("Float entered = " + myFloat);

// Getting double input


System.out.print("Enter double: ");
double myDouble = input.nextDouble();
System.out.println("Double entered = " + myDouble);

// Getting String input


System.out.print("Enter text: ");
String myString = input.next();
System.out.println("Text entered = " + myString);
}
}

You might also like