Pages

Content of this Website is not optimized for Mobile📵. It is recommended that the Website be viewed on a Laptop💻 or Desktop🖳🖥.

Introduction to Java

Introduction to Java



Java is a high level, Object-Oriented modern programming language designed in the early 1990s by Sun Microsystems, and currently owned by Oracle.


Java is Platform Independent, which means that you only need to write the program once to be able to run it on a number of different platforms!

Java is portablerobust, and dynamic, with the ability to fit the needs of virtually any type of application.

  • Java guarantees that you'll be able to Write Once, Run Anywhere.
  • Features of Java



    Apart from being a Platform/System independent language, there are other reasons too for the immense popularity of this language. Some of its features are:

    1. Simple: Java is a simple programming language. All, the difficult concepts of C and C++ have been omitted in Java. For example, the concept of pointers-which is very difficult for both learners and programmers has been completely eliminated from Java.

    2. Object-Oriented: Java is an object, oriented programming language. This means Java programs use objects and classes. What is an object? An object is anything that really exists in the world and can be distinguished from others. Everything that we see physically will come into this definition, for example, every human being, a book, a tree, and so on.

    3. Distributed: Information is distributed on various computers on a network. Using Java, we can write programs, which capture information and distribute it to the clients. This is possible because Java can handle the protocols like TCP/IP and UDP.

    4. Robust: Robust means strong. Java programs are strong and they don't crash easily. There are two reasons for this. Firstly, Java has got excellent inbuilt exception handling features. An exception is an error that occurs at run time. If an exception occurs, the program terminates abruptly giving rise to problems like loss of data. Overcoming such problems is called exception handling. This means that even though an exception occurs in a Java program, no harm will happen.

    Another reason, why Java is robust lies in its memory management features. User needs not-allocate or deallocate the memory in Java. Everything will be taken care of by JVM only.

    5. Secure: Security problems like eavesdropping, tampering, impersonation, and virus threats can be eliminated or minimized by using Java on the Internet.

    6. System/Platform Independence: Java's byte code is not machine-dependent. It can be run on any machine with any processor and any operating system.

    On compilation, Java program is compiled into bytecode. This bytecode is platform-independent and can be run on any machine, plus this bytecode format also provides security. Any machine with Java Runtime Environment can run Java Programs.


    7. Portability: If a program yields the same result on every machine, then that program is called portable. Java programs are portable. This is the result of Java's System independence nature.

    8. Interpreted: Java programs are compiled to generate the byte code. This byte code can be downloaded and interpreted by the interpreter in JVM. If we take any other language, only an interpreter or a compiler is used to execute the programs. But in Java, we use both compiler and interpreter for the execution.

    9. Architectural Neutral: Compiler generates bytecodes, which have nothing to do with particular computer architecture, hence a Java program is easy to interpret on any machine.

    10. High Performance: The-problem with the interpreter inside the JVM is that it is slow. Because of this, Java programs used to run slow. To overcome this problem, along with the interpreter, JavaSoft people have introduced the JIT (Just In Time) compiler, which enhances the speed of execution. So now in JVM, both interpreter and JIT compiler work together to run the program.

    11. Multithreaded: A thread represents an individual process to execute a group of statements. JVM uses several threads to execute different blocks of code. Creating multiple threads is called 'multithreaded'.

    Java multithreading feature makes it possible to write a program that can do many tasks simultaneously. The benefit of multithreading is that it utilizes the same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along.

    12. Scalability: Java platform can be implemented on a wide range of computers with varying levels of resources from embedded devices to mainframe computers. This is possible because Java is compact and platform-independent.

    13. Dynamic: Before the development of Java, the only static text used to be displayed in the browser. But when James Gosling demonstrated an animated atomic molecule where the rays are moving and stretching, the viewers were dumbstruck. This animation was done using an applet program, which are dynamically interacting programs on the Internet.

    How Java Code Executes



    The execution of a Java application code involves three main steps:

    1. Creating the Program:

    Java programs are written using a text editor or an Integrated Development Environment (IDE) like IntelliJ IDEA, Eclipse, or NetBeans. The source code is saved with a .java extension.

    2. Compiling the Program:

    The Java compiler (javac) converts the source code into bytecode, which is stored in a .class file. This bytecode is platform-independent and can be executed on any machine with a JVM.

    How-Java-Code-Executes

    How Java Code Executes

    3. Running the Program:

    The JVM executes the compiled bytecode, translating it into machine code specific to the operating system and hardware.

    public class HelloWorld {
        public static void main(String[] args)
        {
            System.out.println("Hello, World!");
        }
    }

    Essential Java Terminologies You Need to Know


    Before learning Java, one must be familiar with these common terms of Java.

    1. Java Virtual Machine(JVM):

    The JVM is an integral part of the Java platform, responsible for executing Java bytecode. It ensures that the output of Java programs is consistent across different platforms.
    • Writing a program is done by a java programmer like you and me.
    • The compilation is done by the JAVAC compiler which is a primary Java compiler included in the Java development kit (JDK). It takes the Java program as input and generates bytecode as output.
    • In the Running phase of a program, JVM executes the bytecode generated by the compiler.
    Now, we understood that the function of Java Virtual Machine is to execute the bytecode produced by the compiler. Every Operating System has a different JVM but the output they produce after the execution of bytecode is the same across all the operating systems. This is why Java is known as a platform-independent language.

    2. Bytecode:

    Bytecode is the intermediate representation of Java code, generated by the Java compiler. It is platform-independent and can be executed by the JVM.

    3. Java Development Kit (JDK):

    It is a complete Java Development Kit that includes everything including compiler, Java Runtime Environment (JRE), java debuggers, java docs, etc.

    For the program to execute in java, we need to install JDK on our computer in order to create, compile and run the java program.

    4. Java Runtime Environment (JRE):

    JDK includes JRE. JRE installation on our computers allows the java program to run, however, we cannot compile it. JRE includes a browser, JVM, applet support, and plugins. 

    For running the java program, a computer needs JRE.

    5. ClassPath:

    The Classpath is the file path where the java runtime and Java compiler look for .class files to load. By default, JDK provides many libraries. If you want to include external libraries they should be added to the classpath.

    Basically everything in java is represented in Class as an object including the main function.

    What are the Differences between JDK, JRE, and JVM?


    Java Development Kit (JDK): The Java Development Kit (JDK) is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), and other tools needed in Java development.



    Java Runtime Environment (JRE): The Java Runtime Environment provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files.

    Java Virtual Machine (JVM): 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 JRE(Java Run Environment). It stands for Java Virtual Machine.

    No comments:

    Post a Comment

    Kings Classes: Quick Links!