-
Notifications
You must be signed in to change notification settings - Fork 1
JVM Class Loader SubSystem
Java Programming Language
- Java is an object-oriented programming language that includes the following features.
- Platform Independence - Java applications are compiled into bytecode which is stored in class files and loaded in a JVM. Since applications run in a JVM, they can be run on many different operating systems and devices. Object-Oriented - Java is an object-oriented language that take many of the features of C and C++ and improves upon them.
- Automatic Garbage Collection - Java automatically allocates and deallocates memory so programs are not burdened with that task.
- Rich Standard Library - Java includes a vast number of premade objects that can be used to perform such tasks as input/output, networking, and date manipulation.
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages and compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required of a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.
Hotspot JVM: ArchitectureImage
The main components of the JVM include the classloader, the runtime data areas, and the execution engine.
The Java Classloader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine.
When the JVM is started, three class loaders are used:
- Bootstrap class loader
jre/lib/rt.jar
- Extensions class loader
jre/lib/ext/nashron.jar
- System class loader
project/lib/buildpath.jar
The bootstrap class loader loads the core Java libraries located in the <JAVA_HOME>/jre/lib
directory. This class loader, which is part of the core JVM, is written in native code.
The extensions class loader loads the code in the extensions directories (<JAVA_HOME>/jre/lib/ext
, or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.
The system class loader loads code found on java.class.path, which maps to the CLASSPATH environment variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.
System.out.println("JVM ClassLoader's");
/* Bootstrap Class Loader – It loads JDK internal classes, typically loads rt.jar"
* and other core classes for example java.lang.* package classes.
*/
System.out.println("Core Java libraries HashMap « "
+ java.util.HashMap.class.getClassLoader());
/* Extensions Class Loader – It loads classes from the JDK extensions directory,
* usually $JAVA_HOME/lib/ext directory.
* C:\Program Files (x86)\Java\jdk1.7.0_80\jre\lib\ext\dnsns.jar
*/
System.out.println("Extension libraries DNSNameService « "
+ sun.net.spi.nameservice.dns.DNSNameService.class.getClassLoader());
/* System Class Loader – It loads classes from the current classpath that can be
* set while invoking a program using -cp or -classpath command line options.
*/
System.out.println("Build|Class Path libraries this class « "
+ ClassLoaderTest.class.getClassLoader());
While you can write applications entirely in Java, there are situations where Java alone does not meet the needs of your application. Programmers use the JNI to write Java native methods to handle those situations when an application cannot be written entirely in Java.
Currently, VMs from different vendors offer different native method interfaces. These different interfaces force programmers to produce, maintain, and distribute multiple versions of native method libraries on a given platform.
some of the existing native method interfaces, such as:
- JDK 1.0 native method interface
- Netscape’s Java Runtime Interface
- Microsoft’s Raw Native Interface and Java/COM interface
Example form AWT - MyCanvas.java:
import java.awt.*;
public class MyCanvas extends Canvas {
static {
System.loadLibrary("mylib");
}
public native void paint(Graphics g);
}
In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behavior.
Method signature: It consists of method name and parameter list (number/type/order of the parameters). methodName(parametersList y)
. An instance method in a subclass with the same signature
and return type
as an instance method in the super-class overrides the super-class's method.
Java OOP concepts
Class - Collection of a common features of a group of object [static/instance Fields, blocks and Methods]
Object - Instance of a class (instance fields)
Abstraction - Process of hiding complex info and providing required info like API, Marker Interfaces ...
Encapsulation(Security) - Class Binding up with data members(fields) and member functions.
Inheritance (Reusability by placing common code in single class)
1. Multilevel - {A -> B -> C} 2. Multiple - Diamond problem {A <- (B) -> C} [Java not supports] 3. Cyclic {A <-> B} [Java not supports]
* Is-A Relation - Class A extends B
* Hash-A Relation - Class A { B obj = new B(); } - (Composition/Aggregation)
Polymorphism (Flexibility) 1. Compile-Time Overloading 2. Runtime Overriding [Greek - "many forms"]
int[] arr = {1,2,3}; int arrLength = arr.length; // Fixed length of sequential blocks to hold same data type
String str = "Yash"; int strLength = str.length(); // Immutable Object value can't be changed.
List<?> collections = new ArrayList<String>(); int collectionGroupSize = collections.size();
Map<?, ?> mapEntry = new HashMap<String, String>();
Set<?> keySet = mapEntry.keySet(); // Set of Key's
Set<?> entrySet = mapEntry.entrySet(); // Set of Entries [Key, Value]
// Immutable Objects once created they can't be modified. final class Integer/String/Employee
Integer val = Integer.valueOf("100"); String str2 = String.valueOf(100); // Immutable classes
final class Employee { // All Wrapper classes, java.util.UUID, java.io.File ...
private final String empName; // Field as Final(values can be assigned only once) Only getter functions.
public Employee(String name) { this.empName = name; }
}
Native Java Code for Hashtable.h
, Hashtable.cpp
SQL API
.
You can check your current JDK and JRE versions on your command prompt respectively,
- JDK
javac -version [C:\Program Files\Java\jdk1.8.0_121\bin]
o/p:javac 1.8.0_121
- JRE
java -version
[C:\Program Files\Java\jdk1.8.0_121\bin]
o/P:java version "1.8.0_102"
JAVA_HOME - Must be set to JDK otherwise maven projects leads to compilation error. [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
C:\Softwares\OpenJDK\
, 7-zip
Fatal error compiling: invalid target release: JRE and JDK must be of same version
1.8.0.XXX
Disable TLS 1.0 and 1.1
security-libs/javax.net.ssl
: TLS 1.0 and 1.1 are versions of the TLS protocol that are no longer considered secure and have been superseded by more secure and modern versions (TLS 1.2 and 1.3).
Core Java
-
Java Programming Language Basics
- Object, Class, Encapsulation, Interface, Inheritance, Polymorphism (Method Overloading, Overriding)
- JVM Architecture, Memory Areas
- JVM Class Loader SubSystem
- Core Java Interview Questions & Programs
- Interview Concepts
Stack Posts
- Comparable vs Comparator
- Collections and Arrays
-
String, StringBuffer, and StringBuilder
- String reverse
- Remove single char
- File data to String
- Unicode equality check Spacing entities
- split(String regex, int limit)
- Longest String of an array
-
Object Serialization
- Interface's Serializable vs Externalizable
- Transient Keyword
-
implements Runnable
vsextends Thread
- JSON
- Files,
Logging API
- Append text to Existing file
- Counting number of words in a file
- Properties
- Properties with reference key