What java is and how it works

How Does Java Work? A Concise Guide

How does Java work?

If you’re new to programming and new to the concept of what a software program is, let’s start there. According to Techopedia , “A software program is commonly defined as a set of instructions, or a set of modules or procedures, that allow for a certain type of computer operation.” A program’s instructions can be written in several languages including, of course, Java. But how exactly does Java work?

How Java Works (in a nutshell)

Java works by first compiling the source code into bytecode. Then, the bytecode can be compiled into machine code with the Java Virtual Machine (JVM). Java’s bytecode can run on any device with the JVM which is why Java is known as a “write once, run anywhere” language.

Of course, this is a slightly simplified version of how Java works. There’s actually much more to it. On a technical level, when writing a simple “Hello World” program with Java, the data makes several stops before it ends up as text on a screen. A more thorough explanation is given, almost comically, by my fellow University student; Sohail Ahmed Ansari .

Читайте также:  Sublime css color plugin

Sohail's explanation of how Java works.

Sohail actually goes one step further and explains not just how Java programs work, but how software programs work as a whole as they interact with the Operating System (OS). The latter part of his explanation is true of all programs. However, in order to truly understand how Java works and why it’s unique, let’s first take a look at how another language works.

How C++ works

When Java was created in 1995, it was modeled after C++. There are some similarities in these languages and some differences. Of course, the syntax is different. However, the main difference lies in how the code is executed. Unlike Java, which is compiled into bytecode, which can then run on any device that has the JVM, C++ is compiled directly into machine code. This is why Java is famously known to be “Write once, run anywhere.”

When a program written in C++ is compiled, that compiled code can only run that environment. In order for the same program to run on another environment, the source code must be transferred to that environment and then compiled. This is one of the advantages that Java has over other languages. Let’s take a look at Java’s JVM and see what makes it so special.

The JVM and Machine Code

We’ve already established that C++ only runs on the environment in which it was compiled. The Java Virtual Machine provides the runtime environment needed for Java to work on virtually any computer. Once the Java program is compiled into bytecode, it can then be interpreted into machine code through the JVM.

How Java works by converting high-level code (Java source code) into bytecode, and then to low-level machine code with the JVM.

This works in such a way because most computers have their own machine code. Machine code, if you’re not already familiar, is code that only the computer can understand. It’s different from high to mid-level code that we use to actually write a program. Machine code is also referred to as assembly or low-level code. The lower the level, the closer the code is to actual instructions for the processor. The higher it is, the closer it is to something humans can understand.

Object-Oriented Programming

Up until now, I’ve described how Java works behind the scenes. However, it’s also important to understand how Java works on the front end. Java is known to be a general-purpose, Object-Oriented Programming (OOP) language. General-purpose simply refers to Java’s vast capability. There’s isn’t much you can’t do with Java. Object-oriented on the other hand refers to the fact that virtually everything in Java is an object.

I won’t dive too deeply into OOP here. However, I’ll briefly describe in basic terms what an object is. An object in OOP is like an object in real life. This can refer to a person, place, or thing. Just as I have two arms and two legs which you might refer to characteristics, if I were an object in a program, these would be referred to as data types. Also, just as I’m capable of doing things in real life, the object that represents me in the program can also do things. These actions are types of operations, also known as functions. Objects have states (attributes or characteristics), behaviors (functions), and identities (the name of the object).

Java Classes, Methods, and Variables

When writing a new program in Java, you must declare a class name. As a beginner, this is all you need to know. However, after you master the fundamentals of variables and methods, you’ll have to take a deeper look at OOP, classes, and some of the more advanced topics. For now, I’ll tell you that classes are essentially objects. Or rather, they’re the blueprint for the objects which houses everything that define it. The variables refer to the state of the object and the methods refer to the behavior.

As you’re starting out learning Java, you will likely only use one object: the main class. However, after you learn the fundamentals and reach OOP, you will have multiple classes interacting with each other. Remember, the method of an object refers to its behavior. Therefore, when objects interact with each other, they’re simply calling said object’s method for such behavior.

Источник

What is Java and How it works? An Overview and Its Use Cases

Java is a high-level, class-based, object-oriented programming language.
It is a simple programming language. Java makes writing, compiling,and debugging programming easy. It helps to create reusable code and modular programs.

Java is a designed to have as few implementation dependencies as possible A general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual Machine. The syntax of Java is similar to c/c++.

History

James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991.[23] Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time.

java is a programming language created in 1991. James Gosling, Mike Sheridan, and Patrick Naughton, a team of Sun engineers known as the Green team initiated the Java language in 1991. Sun Microsystems released its first public implementation in 1996 as Java 1.0. It provides no-cost -run-times on popular platforms. Java1.0 compiler was re-written in Java by Arthur Van Hoff to strictly comply with its specifications. With the arrival of Java 2, new versions had multiple configurations built for different types of platforms.

Java is used for

  • GUI applications
  • Web servers and applications servers
  • Middleware applications
  • Web applications
  • Mobile applications
  • Embedded systems
  • Enterprise applications
  • It is used for developing Android Apps
  • Helps you to create Enterprise Software
  • Wide range of Mobile java Applications
  • Scientific Computing Applications
  • Use for Big Data Analytics
  • Java Programming of Hardware devices
  • Used for Server-Side Technologies like Apache, JBoss, GlassFish, etc.

Official Website of java

Founder Company

latest version of java

Java Features

Here are some important Java features:

  • It is a High Performance programming languages
  • It is one of the easy-to-use programming languages to learn.
  • java is Object-Oriented programming languages.
  • Write code once and run it on almost any computing platform.
  • Java is platform-independent. Some programs developed in one machine can be executed in another machine.
  • It is a Secure programming languages
  • It is designed for building object-oriented applications.
  • It is a multithreaded language with automatic memory management.
  • It is created for the distributed environment of the Internet.
  • Facilitates distributed computing as its network-centric.

Advantage of java

  • Simple and easy to learn.
  • Object-oriented programming language.
  • Multithreading is supported by Java.
  • Platform agnostic language.
  • Secure platform.

Components Of Java

JDK is a software development environment used for making applets and Java applications. The full form of JDK is Java Development Kit. Java developers can use it on Windows, macOS, Solaris, and Linux. JDK helps them to code and run Java programs.

JVM is an engine that provides a runtime environment to drive the Java Code or applications. It converts Java bytecode into machine language. JVM is a part of the Java Run Environment (JRE). In other programming languages, the compiler produces machine code for a particular system.

JRE is a piece of software that is designed to run other software. It contains the class libraries, loader class, and JVM. In simple terms, if you want to run a Java program, you need JRE. If you are not a programmer, you don’t need to install JDK, but just JRE to run Java programs.

Alternative of java

  • C Language
  • Go
  • Python
  • Scala
  • Kotlin
  • JavaScript
  • Java EE

Terminology of Java

The following terms are common in Java application development in Oracle Database environment:

  • Classes
  • Objects
  • Interfaces
  • Encapsulation
  • Inheritance
  • Polymorphism

Architecture of Java

It integrates the process of interpretation and compilation. Java Architecture explains each and every step of how a program is compiled and executed.

Java Architecture can be explained by using the following steps:

  • There is a process of compilation and interpretation in Java.
  • Java compiler converts the Java code into byte code.
  • After that, the JVM converts the byte code into machine code.
  • The machine code is then executed by the machine.

Hello world example

The traditional Hello world program can be written in Java as:

Источник

Оцените статью