Java Basics, History and Latest Terminologies – Complete Guide. Java is a programming language that is widely used. Java is one of the most commonly used programming languages in the world. For many years, Java has been one of the most popular programming languages.
- Java is an object-oriented programming language. It is not regarded true object-oriented, though, because it supports basic data types (like int, char, etc)
- First, the Java code is compiled into byte code (machine-independent code). Then, independent of the underlying architecture, the byte code executes on the Java Virtual Machine (JVM).
- The syntax of Java is comparable to that of C/C++. However, Java does not provide low-level programming features such as pointers. In addition, Java programmes are always expressed as classes and objects.
- Java is used in a wide range of applications, including mobile apps (Android is Java-based), desktop apps, online apps, client-server apps, corporate apps, and many others.
- When compared to C++, Java codes are more maintainable since Java does not enable numerous things that, if used wrong, might lead to bad/inefficient programming. Non-primitives, for example, are always references in Java. As a result, we can’t send big objects to methods as we can in C++; instead, we must give references in Java. Another example is that because there are no pointers, incorrect memory access is impossible.
- When compared to Python, Java is somewhere in the middle of C++ and Python. Java applications are often quicker than Python counterparts and slower than C++ counterparts. Java, like C++, performs static type checking; however, Python does not.
The Basics of Java
In 1991, James Gosling founded Sun Microsystems Inc, which was eventually bought by Oracle Corporation. It’s a straightforward programming language. Java makes programming easy to write, compile, and debug. It aids in the development of reusable code and modular programmes.
Java is a class-based, object-oriented programming language with a focus on minimising implementation dependencies. A compiled general-purpose programming language designed for developers to write once and execute anywhere. All systems that support Java can run Java code. Java programmes are compiled into byte code that may be executed on any Java Virtual Machine. Java’s syntax is comparable to that of C/C++.
The history of Java is fascinating. It is a programming language that was first introduced in 1991. The Java language was created in 1991 by a group of Sun developers known as the Green team, which included James Gosling, Mike Sheridan, and Patrick Naughton. Sun Microsystems introduced Java 1.0, the first public implementation, in 1996. It offers no-cost run-times on a variety of platforms. Arthur Van Hoff rewrote the Java1.0 compiler in Java to ensure full adherence to its standards. With the release of Java 2, new versions included many settings for various systems.
Sun Microsystems approached the ISO standards organisation in 1997 and later standardised Java, but it quickly dropped out. Sun used to make most of their Java implementations accessible for free, despite the fact that they were proprietary software. Java brought substantial money for Sun by selling licences for specific products like the Java Enterprise System.
Sun released much of their Java virtual machine as free, open-source software on November 13, 2006. Sun completed the process on May 8, 2007, by making all of its JVM core code accessible under open-source distribution agreements.
Simple, resilient, secure, high speed, portable, multi-threaded, interpreted, dynamic, and other concepts guided the development of Java. James Gosling, sometimes known as the Father of Java, created Java in 1995. Java is being employed in mobile devices, internet programming, gaming, e-business, and other applications.
Why JAVA named as Java programming language ?
The crew chose to rename it after OAK, and suggested words were Silk, Jolt, revolutionary, DNA, dynamic, and others. These names were all simple to pronounce and spell, yet they all intended to capture the essence of technology.
According to James Gosling, Java was one of the top options, along with Silk, and because it was a distinctive name, most people chose it.
Java is the name of an Indonesian island where the first coffee (also known as java coffee) was grown. And while sipping coffee near his office, James Gosling came up with this moniker. It’s worth noting that Java is only a name, not an acronym.
Terminology in Java
Before studying Java, you should be familiar with the following terminologies.
- Java Virtual Machine (JVM): The JVM stands for Java Virtual Machine. A program’s execution is divided into three stages. They write the software, compile it, and run it.
- A java programmer, like you and me, creates a programme.
- The JAVAC compiler, which is a major Java compiler provided in the Java development kit, is used to compile the code (JDK). It accepts a Java application as input and outputs bytecode.
- During the program’s Running phase, JVM runs the bytecode generated by the compiler.
We now know that the Java Virtual Machine’s job is to execute the bytecode generated by the compiler. Although each operating system has its own JVM, the output they provide after bytecode execution is consistent across all of them. Java is recognised as a platform-independent language for this reason.
- Bytecode in the Development Process: As previously stated, the JDK’s Javac compiler translates java source code into bytecode that can be run by the JVM. The compiler saves it as a.class file. A disassembler such as javap can be used to inspect the bytecode.
- Java Development Kit (JDK): When we learn about bytecode and JVM, we use the name JDK. As the name implies, it is a comprehensive Java development kit that contains everything from the compiler to the Java Runtime Environment (JRE), debuggers, and documentation. In order to design, build, and run the java application, we must first install JDK on our computer.
- JRE (Java Runtime Environment): JDK comes with JRE. The JRE installation on our PCs allows us to run the Java application, but we are unable to build it. A browser, JVM, applet support, and plugins are all included in JRE. JRE is required for a computer to run a Java programme.
- Garbage Collector: Programmers in Java are unable to remove objects. JVM features a software named Garbage Collector that can discard or recollect that memory. Garbage Collectors provide the ability to recover things that have not been referenced.
- As a result, Java makes a programmer’s life easier by managing memory management. However, programmers should be cautious when employing things that have been around for a long period in their code. Garbage is unable to reclaim the memory of things that have been referenced.
- ClassPath: The classpath is the location in which the Java runtime and compiler seek for.class files to load. JDK comes with a lot of libraries by default. External libraries should be added to the classpath if you wish to use them.
Java’s Primary / Main Characteristics
- Platform Independence: The compiler turns source code to bytecode, which is subsequently executed by the JVM. This bytecode can execute on any platform, including Windows, Linux, and macOS, implying that we may create a programme on Windows and run it on Linux, and vice versa. Although each operating system has its own JVM, the output delivered by all OSs following bytecode execution is the same. This is why java is said to as a platform-independent language.
- Object-Oriented Programming Language: Object-oriented programming is a method of organising a programme in terms of a collection of objects, each of which represents an instance of the class.
Object-Oriented programming has four key concepts
- Simple: Because it lacks sophisticated features like as pointers, operator overloading, multiple inheritances, and explicit memory allocation, Java is one of the simplest languages.
- Robust: The Java programming language is robust, which implies it is dependable. It is designed in such a manner that it prioritises error detection as early as possible; as a result, the java compiler can find faults that are difficult to detect in other programming languages. Garbage collection, Exception Handling, and memory allocation are the major aspects of java that make it robust.
- Secure: Because we don’t have pointers in Java, we can’t access out-of-bound arrays; if we do, we get an ArrayIndexOutOfBoundException. As a result, certain security issues in Java, such as stack corruption and buffer overflow, are hard to exploit.
- Distributed: The java programming language allows us to develop distributed applications. Java distributed applications are built using Remote Method Invocation and Enterprise Java Beans. The java programmes may be readily disseminated over one or more computers that are linked together via the internet.
- Multithreading: Multithreading is supported by Java. It is a Java feature that permits the execution of two or more portions of a programme at the same time to maximise CPU usage.
- Java code developed on one system may be executed on another machine, as we all know. Java is portable due to its platform-independent characteristic, which allows its platform-independent bytecode to be run on any platform.
- High Performance: The Java architecture is designed to decrease overhead during runtime, and at times, java utilises a Just In Time (JIT) compiler, which builds code only when it is called, allowing applications to run quicker.
- Dynamic flexibility: Because Java is totally object-oriented, we may add classes, new methods to existing classes, and even create new classes using sub-classes. Native methods, which are functions written in other languages such as C and C++, are also supported by Java.
- Sandbox Execution: With the aid of a bytecode verifier, Java programmes run in a distinct environment that allows users to run their applications without harming the underlying system. The job of the bytecode verifier is to examine the code for any violations. This adds an extra layer of security.
- Write Once, Run Anywhere: As previously mentioned, a Java application creates a ‘.class’ file that corresponds to our application(program) but includes binary code. Because bytecode is not dependent on any machine architecture, it provides architecture-neutral convenience. It is for this reason that java is widely employed in the entrepreneurial IT business throughout the world.
- The power of compilation and interpretation: Most languages are either compiled or interpreted with a specific goal in mind. However, because the Java compiler translates source code to bytecode, and the JVM executes this bytecode to machine OS-dependent executable code, java incorporates considerable power.
- Comments: Comments are used to clarify code and are analogous to comments in Java, C, and C++. The comment items are ignored by compilers and are not executed. A single line or more lines can be used for comments.
Comment in a single line
/ Comment on a single line
Comments on multiple lines
/* Comments on many lines*/
- import java.io.*: This allows you to import all of the io package’s classes. The Java io package contains a collection of input and output streams that may be used to read and write data to files or other input and output sources.
- class: The data and procedures that will be utilised in the application are stored in the class. The class’s behaviour is defined by its methods. There is only one method in the GFG class. The main programme is written in Java.
- void that is static The static keyword indicates that this function may be accessed without having to instantiate the class.
- void: The term void indicates that this procedure will return nothing. Our application’s entry point is the main() function.
- System.in: This is the standard input stream for reading characters from a keyboard or other standard input device.
- System.out: This is the standard output stream for displaying a program’s output on an output device such as a computer screen.
- println(): In Java, this method is also used to print text to the console. The text is printed on the console, and the cursor goes to the beginning of the following line. The following line is where the printing begins.
Everything in Java, including the main method, is represented as an object in a Class.