Introduction to Java Programming

This is a tutorial for Introduction to Java Programming

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

Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, so James Gosling and his team changed the Oak name to Java.


Applications of Java

According to Sun, 3 billion devices run Java. There are many devices where java is currently used. Some of them are as follows:

  1. Desktop Applications such as acrobat reader, media player, antivirus, etc.
  2. Web Applications such as irctc.co.in, javatpoint.com, etc.
  3. Enterprise Applications such as banking applications.
  4. Mobile
  5. Embedded System
  6. Smart Card
  7. Robotics
  8. Games, etc.

Types of Java Applications

There are mainly 4 types of applications that can be created using Java programming:

1) Standalone Application (desktop applications or window-based applications: Media player, antivirus, etc. AWT and Swing are used in Java for creating standalone applications.)

2) Web Application (runs on the server-side and creates a dynamic page: Currently, Servlet, JSP, Struts, Spring, Hibernate, etc. technologies are used for creating web applications in Java.

3) Enterprise Application (distributed in nature, such as banking applications, etc. Features such as high-level security, load balancing, and clustering.)

4) Mobile Application (created for mobile devices: Currently, Android and Java ME are used for creating mobile applications.)


Features of Java Programming

  • Object-Oriented: In Java everything is an Object. Java can be easily extended since it is based on the Object model.
  • Platform independent: Unlike many other programming languages, including C and C++ when Java is compiled, it is not compiled into platform-specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.
  • Simple : Java is designed to be easy to learn. If you understand the basic concept of OOP, Java would be easy to master.
  • Secure: With Java’s secure feature it enables us to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.
  • Architectural- neutral: Java compiler generates an architecture-neutral object file format which makes the compiled code to be executable on many processors, with the presence Java runtime system.
  • Portable: being architectural neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler and Java are written in ANSI C with a clean portability boundary which is a POSIX subset.
  • Robust: Java makes an effort to eliminate error-prone situations by emphasizing mainly on compile-time error checking and runtime checking.
  • Multi-threaded : With Java’s multithreaded feature it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications.
  • Interpreted: Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and a lightweight process.
  • High Performance: With the use of Just-In-Time compilers Java enables high performance.
  • Distributed: Java is designed for the distributed environment of the internet.
  • Dynamic: Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry an extensive amount of run-time information that can be used to verify and resolve access to objects on run-time.

The Java Platform

One thing that distinguished Java from some other languages is its ability to run the same compiled code across multiple operating systems. Compilation creates bytecode out of the source code. Source code is written and stored in files with the extension of .Java, and after compiling a file with a “.class” extension is created which contains the bytecode instructions.

When the code is run by the user, it is processed by the Java virtual machine (JVM). The JVM is essentially an interpreter for the bytecode. At execution time the JVM translates the compiled bytecode into machine language which can then be executed by the hardware. There are different versions of the JVM which are compatible with various operating systems, allowing the same code to be executed on different platforms. This makes little difference to the end-user, however, it greatly reduces the effort needed to develop cross-platform applications on the part of the developer.

JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn’t physically exist. It is a specification that provides a runtime environment in which Java byte code can be executed. It can also run those programs which are written in other languages and compiled to Java byte code.

JRE is an acronym for Java Runtime Environment. It is also written as Java RTE. The Java Runtime Environment is a set of software tools that are used for developing Java applications. It is used to provide the runtime environment. It is the implementation of JVM. It physically exists. It contains a set of libraries + other files that JVM uses at runtime.

JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software development environment that is used to develop Java applications and applets. It physically exists. It contains JRE + development tools.


This is a tutorial for Introduction to Java Programming


What is Java Bytecode?

Java bytecode is the instruction set for the Java Virtual Machine. It acts similar to an assembler which is an alias representation of a C++ code. As soon as a Java program is compiled, Java bytecode is generated. In more apt terms, Java bytecode is the machine code in the form of a. class file. With the help of Java bytecode, we achieve platform independence in Java.

How does it work?

When we write a program in Java, firstly, the compiler compiles that program, and bytecode is generated for that piece of code. When we wish to run this .class file on any other platform, we can do so. After the first compilation, the bytecode generated is now run by the Java Virtual Machine and not the processor into consideration. This essentially means that we only need to have basic Java installed on any platform that we want to run our code on. Resources required to run the bytecode are made available from the Java Virtual Machine, which calls the processor to allocate the required resources. JVM’s are stack-based so they stack implementation to read the codes.

Advantages of Java Bytecode

Platform independence is one of the sole reasons for which James Gosling started the formation of Java and it is this implementation of the bytecode which helps us to achieve this. Hence bytecode is a very important component of any Java program.The set of instructions for the JVM may differ from system to system, but all can interpret the bytecode. A point to keep in mind is that bytecodes are non-runnable codes and rely on the availability of an interpreter to execute and thus the JVM comes into play.

Bytecode Interpretation

The execution engine decodes the bytecode and performs the actions necessary to implement each instruction. Its interface is quite simple, consisting of a single function that takes a Context as an argument, and executes the method whose frame is on top of the Context’s call stack.

Since Jupiter’s design delegates much of the executive responsibility for other parts of the system, not much remains to be done by the Execution Engine itself. The current interpreter implementation divides the functionality into three modules, which are shown along with the ExecutionEngine interface. These modules are each responsible for implementing a portion of the Execution Engine functionality:

  • The opcodeSpec module defines each of the Java opcodes in terms of Jupiter’s base interfaces. It takes the form of a header file that is included (with #include) in the interpreter module. It is designed to be used by any ExecutionEngine, be it an interpreter or a JIT compiler.
  • The InterpreterSupport module provides functionality that is independent of the particular interpreter implementation, such as the stack-unwinding algorithm for exception handling.
  • The Interpreter module implements the ExecutionEngine interface, making use of the opcodeSpec and Interpreter Support modules as necessary.

This was a tutorial for Introduction to Java Programming

More tutorials in Introduction to Java Programming

Visit the Offical Java Website

The content uploaded on this website is for reference purposes only. Please do it yourself first.