Download Technology, JVM, and Runtime Environment

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Compiler wikipedia , lookup

Java syntax wikipedia , lookup

Object-oriented programming wikipedia , lookup

Scala (programming language) wikipedia , lookup

One-pass compiler wikipedia , lookup

Class (computer programming) wikipedia , lookup

C++ wikipedia , lookup

C Sharp syntax wikipedia , lookup

Interpreter (computing) wikipedia , lookup

Name mangling wikipedia , lookup

Java (programming language) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Java performance wikipedia , lookup

Transcript
CS 1520 Programming Languages for Web Applications
Recitation 05/26/2002
Goals of Java Technology
1.
2.
3.
4.
5.
Easy to use language (object-oriented, create streamlined and clear code)
Provides interpreted environment
Enables users to run more than one thread of activity.
Loads classes dynamically; that is, at the time they are actually needed.
Supports dynamically changing programs during runtime by loading classes from
disparate sources
6. Furnishes better security
Interpreted Environment results in:
1. Speed of development (reduces the compile-link-load-test cycle)
2. Code portability (independent of platforms)
How are these goals fulfilled?
1. JVM (Java Virtual Machine)
2. Garbage collection
3. Code Security
JVM




Provides hardware platforms specifications
Reads compiled byte codes that are platform independent.
Is implemented on hardware or software
Is implemented on a Java technology development tool or a Web browser
The compiler takes Java application source code and generates byte codes. Byte codes are
machine code instructions for the JVM. Every Java technology interpreter, regardless of
whether it is a Java technology development tool or a web browser that can run applets,
has an implementation of JVM.
Any compliant Java technology interpreter must be able to run any program with class
files that conform to the class file format specified in the JVM Specification.
Operation of JAVA TECHNOLOGY RUNTIME ENVIRONMENT (JRE) and how
it enforces code security?
Runtime
Compile
Class loader
Java
Network
Byte Code verifier
TestGreeting.java
javac
Interpreter
Runtime
TestGreeting.class
Hardware
Java software source files are “compiled” in the sense that they are converted into a set of
byte codes from the text format in which you write them. The byte codes are stored in
.class files.
At runtime, the byte codes that make up a Java software program are loaded, checked and
run in an interpreter. The interpreter has two functions: it executes the bytecodes and
makes the appropriate calls to the underlying hardware.
Java Runtime Environment
Has three tasks
1. Loads code (by class loader)
2. Verifies code (by bytecode verifier)
3. Executes code (by runtime interpreter)
Example: Simple java application
TestGreeting.java
1. public class TestGreeting{
2.
public static void main(String[] args){
3.
Greeting hello = new Greeting();
4.
hello.greet();
5.
}
6. }
(Line numbers are not actually typed in the program ….I have them here just for your
understanding)
Greeting.java
1.
public class Greeting{
2.
public void greet(){
3.
System.out.println(“Hi”);
4.
}
5.
}
Due to Line 1 of TestGreeting.java, TestGreeting.class file is created which has
compiled code for the public class TestGreeting. (classname.class)
Line 2 of TestGreeting.java is where the program starts to execute.
Steps:
1. Compiling TestGreeting.java
javac TestGreeting.java
Greeting.java file has been compiled into Greeting.class. This is done
automatically by the compiler because the TestGreeting class uses the Greeting
class.
2. Running an application
java TestGreeting
3. Locating common compile and runtime errors.
Troubleshooting the Compilation
Errors that you might encounter while compiling code -> compile-time errors.
 javac: Command not found
The PATH variable is not set properly to include the javac compiler. The javac
compiler is located in the bin directory below the installed JDK directory.
 Greeting.java: 4: cannot resolve symbol
Symbol
:
method printl (java.lang.String)
Location
:
class java.io.PrintStream
System.out.printl(“hi”)
^
(In case you typed this line incorrectly as System.out.printl(“hi”); you will
encounter above error. The method name should have been println)
 Class and File Naming
If the .java file contains a public class, then it must have the same file name as
that class .For example, the definition of the class in the previous example is:
public class TestGreeting
The name of the source file must be TestGreeting.java otherwise it gives an error.


Runtime Errors
Can’t find class TestGreeting
This means that the class name specified on the command line was spelled
differently than the filename.class file.Java programming language is casesensitive.
Exception in thread “main”
java.lang.NoSuchMethodError: main
This means that the class you told the interpreter to execute does not have a static
main method. There might be a main method but it might not be declared with
static keyword or it might have the wrong parameters declared.