Java internals

  • Java is a programming language and a platform. Java is a high level, robust, object-oriented and secure programming language.

  • Platform:

    • Any hardware or software environment in which a program runs, is known as a platform.

    • Since Java has a runtime environment (JRE) and API, it is called a platform.

  • Java Platforms / Editions

    • Java SE (Java Standard Edition)

      • It is a Java programming platform.

      • It includes Java programming APIs such as java.lang, java.io, java.net, java.util, java.sql, java.math etc.

      • It includes core topics like OOPs, String, Regex, Exception, Inner classes, Multithreading, I/O Stream, Networking, AWT, Swing, Reflection, Collection, etc.

    • Java EE (Java Enterprise Edition)

      • It is an enterprise platform which is mainly used to develop web and enterprise applications.

      • It is built on the top of the Java SE platform. It includes topics like Servlet, JSP, Web Services, EJB, JPA, etc.

    • Java ME (Java Micro Edition)

      • It is a micro platform which is mainly used to develop mobile applications.

    • JavaFX

      • It is used to develop rich internet applications. It uses a light-weight user interface API.

compiler

JVM

  • JVM (Java Virtual Machine) is an abstract machine.

  • called a virtual machine because it doesn't physically exist. It is a specification that provides a runtime environment in which Java bytecode can be executed

  • can run those programs which are written in other languages and compiled to Java bytecode.

  • platform dependent because the configuration of each OS is different from each other. However, Java is platform independent.

  • There are three notions of the JVM:

    • 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.

    • implementation

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

    • instance.

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

  • JVM performs the following main tasks:

    • Loads code

    • Verifies code

    • Executes code

    • Provides runtime environment

  • JVM provides definitions for the:

    • Memory area

    • Class file format

    • Register set

    • Garbage-collected heap

    • Fatal error reporting etc

Arguments

Byte code

Class Loader

Crashing the JVM

  • Understanding code outside of libraries/apis and IDEs can help prevent or solve problems

  • Examples

    • Try to allocate as much memory as you can.

      • if more than what exists it will crash

    • Try to write data to your hard disk until it is full.

      • If not enough HDD space then fail

    • Try to open as many files as you can

      • Dependent on maximum number of file descriptors for your environment

    • Try to create as many threads as you can. On a Linux system,

      • you can look at /proc/sys/kernel/pid_max and you will see how many processes may be running on your system.

      • How many threads are you allowed to create on your system?

    • Try to modify your own .class files in the filesystem

    • Try to find your own process ID, and then try to kill it by using Runtime.exec (e.g., by calling kill -9 on your process ID)

    • Try to create a class at runtime that only calls System.exit, load that class dynamically via the class loader, then call it.

    • Try to open as many socket connections as possible.

      • On a Unix system, the maximum number of possible socket connections equals the maximum number of file descriptors (often 2,048)

    • Try to hack your system.

      • Download an exploit via code or by using wget. Execute the exploit, and then call shutdown -h as root on a Unix system or shutdown /s as administrator on a Windows system.

    • Run your JVM with -noverify or -Xverify:none, which disables all bytecode verification, and write something that would otherwise not be allowed to run.

    • Try using Unsafe.

      • This backdoor class is used to get access to low-level facilities such as memory management. All the syntax of Java, all the safety of C!

    • Try going native. Write some native code. All the syntax of C, all the safety of C!

JDK

  • acronym for Java Development Kit

  • a software development environment which is used to develop Java applications and applets.

  • physically exists and contains JRE + development tools.

  • JDK contains a

    • private Java Virtual Machine (JVM) and

    • a few other resources such as

    • an interpreter/loader (java)

    • a compiler (javac)

    • an archiver (jar)

    • a documentation generator (Javadoc)

    • jconsole

Multple jdk

JRE

  • acronym for Java Runtime Environment

  • AKA Java RTE

  • set of software tools which are used for developing Java applications.

  • provide the runtime environment

  • implementation of JVM. It physically exists. It contains a set of libraries + other files that JVM uses at runtime

JDK/JRE/JVM

Just In Time Compiler

Linker?????

Last updated