The document provides an overview of the Java Runtime Environment (JRE), which is part of the Java Development Kit (JDK) and enables Java programs to run on various operating systems. It details the components of the JRE, including the ClassLoader, bytecode verifier, and interpreter, as well as the structure of a Java program, including sections such as documentation, package declaration, import statements, interface, class definition, and methods. Additionally, it explains the importance of the main method as the entry point for Java program execution.
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 ratings0% found this document useful (0 votes)
19 views27 pages
The Java Environment
The document provides an overview of the Java Runtime Environment (JRE), which is part of the Java Development Kit (JDK) and enables Java programs to run on various operating systems. It details the components of the JRE, including the ClassLoader, bytecode verifier, and interpreter, as well as the structure of a Java program, including sections such as documentation, package declaration, import statements, interface, class definition, and methods. Additionally, it explains the importance of the main method as the entry point for Java program execution.
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/ 27
The Java Environment
• The Java Environment
• Java Source File -Structure – Compilation What is JRE? • part of the Java Development Kit (JDK) • JRE acts as a layer on the top of the operating system. • provides the class libraries and other resources that a specific Java program needs to run. • The JRE is one of three interrelated components for developing and running Java programs. • The other two components are as follows: 1. Java Development Kit (JDK) – a set of tools for developing Java applications. – Developers choose JDKs by Java version and by package or edition— Java Enterprise Edition (Java EE), Java Special Edition (Java SE), or Java Mobile Edition (Java ME). – Every JDK always includes a compatible JRE, because running a Java program is part of the process of developing a Java program. 2. Java Virtual Machine (JVM) – executes live Java applications. • The JRE combines Java code created using the JDK with the necessary libraries required to run it on a JVM and then creates an instance of the JVM that executes the resulting program. • JVMs are available for multiple operating systems, and programs created with the JRE will run on all of them. • In this way, the Java Runtime Environment is what enables a Java program to run in any operating system without modification. How does JRE work? • The JDK and JRE interact with one another to create a sustainable runtime environment that enables the seamless execution of Java-based applications in virtually any operating system. • The following make up the JRE runtime architecture: • ClassLoader – The Java ClassLoader dynamically loads all classes necessary to run a Java program. – Since Java classes are only loaded into memory when they're required, the JRE uses ClassLoaders to automate this process on demand. • Bytecode verifier – The bytecode verifier ensures the format and accuracy of Java code before it passes to the interpreter. – In the event that code violates system integrity or access rights, the class will be considered corrupted and won't be loaded. • Interpreter – After the bytecode successfully loads, the Java interpreter creates an instance of the JVM that allows the Java program to be executed natively on the underlying machine. public class Demo //class definition { public static void main(String args[]) { void display() { System.out.println("Welcome to java"); } //statements } } Compile java program javac Hello.java
Run java program
java Hello Demo.java Demo.class • Subsystem of JVM that is used to load class files.
• Checks the code fragments for illegal code
that can violate access rights to objects.
• Read bytecode stream then execute the
instructions. Documentation Section • The documentation section is an important section but optional for a Java program. • It includes basic information about a Java program. • The information includes the author's name, date of creation, version, program name, company name, and description of the program. • It improves the readability of the program. • Whatever we write in the documentation section, the Java compiler ignores the statements during the execution of the program. • To write the statements in the documentation section, we use comments. • The comments may be single-line, multi-line, and documentation comments. Single-line Comment: • It starts with a pair of forwarding slash (//). For example: //First Java Program Multi-line Comment: • It starts with a /* and ends with */. For example: /*It is an example of multiline comment*/ Documentation Comment: • It starts with the delimiter (/**) and ends with */. /**It is an example of documentation comment*/ Package Declaration • The package declaration is optional. • It is placed just after the documentation section. • Use the keyword package to declare the package name. package oops; • Note that there can be only one package statement in a Java program. • It must be defined before any class and interface declaration. • It is necessary because a Java class can be placed in different packages and directories based on the module they are used. • For all these classes package belongs to a single parent directory. Import Statements • The package contains the many predefined classes and interfaces. • If we want to use any class of a particular package, we need to import that class. • The import statement represents the class stored in the other package. • Use the import keyword to import the class. • It is written before the class declaration and after the package statement. • We use the import statement in two ways, – either import a specific class – import all classes of a particular package. • In a Java program, we can use multiple import statements. Interface Section • It is an optional section. • Use the interface keyword to create an interface. • An interface is a slightly different from the class. • It contains only constants and method declarations. • Another difference is that it cannot be instantiated. • We can use interface in classes by using the implements keyword. • An interface can also be used with other interfaces by using the extends keyword. interface car { void start(); void stop(); } Class Definition • It is vital part of a Java program. • Without the class, we cannot create any Java program. • A Java program may conation more than one class definition. • Use the class keyword to define the class. • The class is a blueprint of a Java program. • It contains information about user-defined methods, variables, and constants. • Every Java program has at least one class that contains the main() method. class Student //class definition { } Class Variables and Constants • In a Java program, the variables and constants are defined just after the class definition. • The variables and constants store values of the parameters. • It is used during the execution of the program. • Decide and define the scope of variables by using the modifiers 🡪defines the life of the variables. class Student //class definition { String sname; //variable int id; double percentage; } Main Method Class • It is essential for all Java programs. • Because the execution of all Java programs starts from the main() method. • In other words, it is an entry point of the class. • It must be inside the class. • Inside the main method, we create objects and call the methods. public static void main(String args[]) { } Methods and behavior • A method is a block of code which only runs when it is called. • You can pass data, known as parameters, into a method. • Methods are used to perform certain actions, and they are also known as functions. modifier returnType nameOfMethod (Parameter List)