QA's approach 2 Java - Basic Java Funda's

                           Fundamentals of learning Java

Overview of the Java platform

Java is both a programming language and a platform for running compiled Java code. This platform consists mainly of the JVM, but also includes an execution environment that supports the JVM's execution on the underlying (native) platform. The JVM includes several components for loading, verifying, and executing Java code. Figure below shows how a Java program executes on this platform.


The JVM provides a classloader, a bytecode verifier, and an interpreter/just-in-time compiler for loading, verifying, and executing a class file.

At the top of the diagram is a series of program class files, and one of these class files is denoted as the main class file. A Java program consists of at least the main class file, which is the first class file to be loaded, verified, and executed.

The JVM delegates class loading to its classloader component. Classloaders load class files from various sources, such as file systems, networks, and archive files. They insulate the JVM from the intricacies of class loading.

A loaded class file is stored in memory and represented as an object created from the Class class. Once loaded, the bytecode verifier verifies the various bytecode instructions to ensure that they are valid and won't compromise security.

If the class file's bytecodes are not valid, the JVM terminates. Otherwise, its interpreter component interprets the bytecode one instruction at a time. Interpretation identifies bytecode instructions and executes equivalent native instructions.

Some bytecode instruction sequences execute more frequently than others. When the interpreter detects this situation, the JVM's just-in-time (JIT) compiler compiles the bytecode sequence to native code for faster execution.

During execution, the interpreter typically encounters a request to execute another class file's bytecode (belonging to the program or to a library). When this happens, the classloader loads the class file and the bytecode verifier verifies the loaded class file's bytecode before it's executed. Also during execution, bytecode instructions might request that the JVM open a file, display something on the screen, make a sound, or perform another task requiring cooperation with the native platform. The JVM responds by using its Java Native Interface (JNI) bridge technology to interact with the native platform to perform the task.
The standard class library

Java includes a large runtime library of class files, which store compiled classes and other types
To understand import completely, you have to realize that Java organizes classes into packages . By default, if you use a class name in your program, the compiler looks for this class in two places: in the package you are currently creating (which may be the default package that has no name), and in the special package java.lang. For example, suppose you write: String s = "Welcome to Coriolis"; This defines a string variable named s. 

In Java, strings are objects, and the String object is part of the special system package java.lang. Therefore, you could write: java.lang.String s = "Welcome to Coriolis"; These two statements are equivalent. Suppose you want to use classes from a different package, however. For example, you might want to use the Socket class from the java.net package. You could write: java.net.Socket sock; It gets tiresome to keep specifying this lengthy prefix in front of the class name, however. That's where import helps you. By specifying an import, you can tell the compiler that you will be using classes from another package. 

You can import a specific class like this: import java.net.Socket; You can also import an entire package, and gain access to all the classes in that package. Simply place a star at the end of the package name, like this: import java.net.*; You read earlier that a class is a cookie cutter that creates objects. You've also read that all Java programs are objects. This leads to a chicken -and-egg problem: What creates the first object in your program? The answer is that you do. In a conventional Java program, one class will have a static function named main. When a function is static, it is really part of the class and not part of the individual objects in the class. That means that static functions exist even before you create any objects. Java calls the main function in your object. This is your chance to create a new object or to do any other processing that is required. Very simple programs can do all their work in the main function

Execute the program
Two steps were involved to execute the program. The javac command compiles the Java source code into an intermediate representation, called byte codes, and saves them in class files. The java command launches a virtual machine that loads the class files and executes the byte codes.


Java Environment Variables CLASS PATH VS PATH


Class Path points to -->libraries folder

Required for compiler & JVM related only i.e required for java related applications only.

How to retrieve existing class path -- use %classpath%

echo %classpath%

How to Set/append classpath to existing classpath variable

set classpath=%classpath%;new path to set

Environmental variable Path points to -- Bin folder

To access & launch the binaries of application in command prompt from other folders & specific to all application, even non java


                             J2SE VS JDK

Java -- 3 editions
J2SE -- Specification(contains list of concepts, rules & regulations)
Its IMPLEMENTATION -- STANDALONE S/W -> JDK(Compilation & Execution)

J2EE--> Specifications(contains list of concepts, rules & regulations)
INTERNET & ENTERPRISE APPLICATIONS
IMPLEMENTATION -- SERVER S/W->TOMCAT(only can execute, hence requires JDK for compilation)

JME--> Specifications(contains list of concepts, rules & regulations)

All the above 3 are specifications - set of rules & regulations for developing java programs
JDK is the implementation s/w or programs for compiling & executing J2SE based programs
llly tomcat is an implementation s/w for J2SE based applications

J2SE is like a user guide followed by End User to understand & work with the application, similarly
J2SE is a specification followed by java programmers for developing java program, which can be compiled & executed using jdk.




Each Edition of Java has its own Platform, the platform supported for J2SE doesn't support J2EE. As each of them have its won specifications, they have their own implementations to support for compilation & execution.

Comments

Popular posts from this blog

QA's approach 2 Java - Understanding Static context

Selenium 4 absolute beginners - How to create Batch execution file

Technologies - Log4J - Create Log4j Configuration File - Where ? How ? What ?