Tag: Java Tutorial

  • Java Virtual Machine (JVM), Difference JDK, JRE & JVM

    Java Virtual Machine (JVM), Difference JDK, JRE & JVM

    Previously we had begin with Java Tutorial beginners guide featuring – What is Java , features of Java Programming Language , Java editors and different Java editions and Java Application Types . Now on Java tutorial we begin with the section 2 that is about JVM – Java Virtual Machine . And also about the difference between JDK Vs JRE Vs JVM including other aspects of Java Virtual Machine .

    Guys, to deep dive in java, let’s have a look how it works internally..


    A role of Java virtual machine (short form as JVM) is to execute Java bytecode. We can state that JVM is the component of the Java software platform where code execution happens. Right now over 5.5 billion computer are in the market which are  JVM-enabled. JVM lives inside our PC/computer and byte code is the language for JVM. With the introduction of JVM, job of compiler becomes very easy as it only generate byte code for JVM rather than generating different machine code for each m/c which is the reason why java language is platform independent.

    A JVM executes programs containing Java bytecode instructions and are generally  implemented to run on existing operating system (windows etc). A JVM provides a run-time environment which enables features such as exception handling which in turns provides debugging capability for every software exception. A JVM is a part of Java Class Library (some inbuilt java classes in the form of bytecode) to provide basic functions to developer while doing coding in Java. These libraries with the JVM together named as Java Runtime Environment (JRE).

    JVMs are compatible and available for almost all hardware and software platforms. Due to this feature of using the same bytecode for all JVMs on all platforms makes Java to be known as a write once and run anywhere language. This clearly describe that JVM is a crucial component of the Java language. Java bytecode is an machine language which is typically compiled from Java (or from other programming languages).

    HotSpot is the most used JVM which is written in the C++ programming language. JVM doesn’t understand Java code due to which we require java compiler that compiles source code and create .class file. This .class file is composed of byte code which JVM can understand. There are two main components of JVM – heap memory and garbage collector. We will discuss about both in detail in the upcoming discussion.

    How JVM works

    Now moving on with the Java tutorial section , we will see working of Java Virtual machine ie, how JVM works exactly.

    Look at the pictorial format that explains the working of JVM.

    • After reading .class file, class loader save the corresponding byte code in the method area. Generally all JVMs have only one method area which is shared across classes which holds information related to each .class file.
    • Heap is an integral part of JVM memory in which the objects actually rests. JVM produces the Class object for each .class file.
    • Unlike Heap, Stack is used for storing temporary variables.
    • PC-Registers used to keep exact information of all instructions (which instruction is executing and which is going to be executed).
    • A native method used to access the runtime data of the JVM (java virtual machine). Native Method interface enables java code to call by the native applications (programs that are specific to the hardware and OS).
    • We will cover Garbage collection in the upcoming article

     

    JVM Vs JRE Vs JDK

    Now let’s sort out the difference between JVM ,JRE and JDK . How does these differ from each other – JVM Vs JRE Vs JDK .

    JRE ( Java Runtime Environment )

    Java Runtime Environment is within which the java virtual machine actually runs. JRE contains Java virtual Machine and other files except development tools (debugger and compiler). So developer can run the source code in JRE but he/she cannot develop and compile the code.

    JVM ( Java Virtual Machine )

    As per above discussion, JVM runs the program by using libraries and files provided by Java Runtime Environment.

    JDK ( Java Development Kit )

    Java Development Kit can be considered as the super-set of JRE.  JDK includes all features that JRE has and over and above it contains development tools such like compiler, debugger etc.

    Now we have discussed about what is JVM ( Java Virtual Machine ) and how JVM works . Also in depth we have discussed about the difference between JVM Vs JRE Vs JDK.

    On the third session of Java Programming Tutorials we will discuss about the Java Basic Syntax and Java Environment Setup .

  • Java Tutorial – Introduction to Java Programming Beginner’s Guide

    Java Tutorial – Introduction to Java Programming Beginner’s Guide

    We already draw your attention about basic of programming for all upcoming programmers through Introduction to Programming Languages : Programming Tutorials . Now we begin with our Java Tutorial Officially from here .

    Where to begin this Java Tutorial From , i was wondering . Then thought to give you a basic introduction about Java. It is not mandatory to read the introduction section unless and until you have got interest to know about the beginning of java programming , i mean evolution of java programming language etc .

    History bores some , while History excites some . So the choice is yours . Here we go with Introduction to Java Programming Beginner’s Guide .

    Introduction To Java – Beginning with History of Java Tutorial 

    In 90s, Sun Microsystems Inc. (US) has developed a new language to build software for various electronic devices that could be controlled remotely. This language is known as JAVA today. Its first draft was developed by James Gosling and his team members. They named it JAVA after ‘JAVA ISLAND’ – from where coffee was exported to the whole world. In mid 90s  Naughton and Jonathan Payne developed this further under the name WebRunner (Java based Web browser) later renamed as HotJava.

    HotJava as a browser had all the features of implementing applets (programs that run dynamically on Web browser). After officially announcing JAVA and HotJava announced by Sun at Sunworld Conference, Netscape Inc. also incorporated support of support in its browser (named Netscape Navigator). Sun Microsystems Inc later acquired by Oracle Corporation. Soon after Microsoft also incorporated support of Java in their Internet Explorer. Java became very popular due to its simple way of programming, compiling and debugging. Right now more than 3 billion devices run java.

    Enough of History…

    Other conventional languages are generally designed to be compiled machine language Or they are interpreted from source code at runtime. Java language first get compiled to  bytecode and this bytecode runs by a Java Virtual Machine(JVM).

    So, Java is a class-based, concurrent, object-oriented computer language designed to let application developerswrite once, run anywhere”. This means that if the given line of code successfully runs on one machine, there is not need to recompile it to run on another machines. Java code is compiled as a class file which can run on any Java virtual machine irrespective of computer architecture.As information technology word is very dynamic, everybody was looking for very scalable language and due to its robustness, Java has become one of the most popular and programmer friendly language. Java is very flexible and can be enhanced as per the requirements to develop different kind of client-server web applications (or desktop applications) with having high volume of users. Java has more inhouse libraries and plugins than any other programming language.

    Java is one of the most developer friendly and most in demand programming language . It is specially design to serve client-server web applications with having huge number of users. Most of the syntax in java is derived from C and C++ with more in-build features (libraries).

    What is Java ?

    On Java tutorial the most important section begins from here . Yes first let’s know What is Java ?

    Features of Java Programming Language

    Here is the pictorial description of features of java programming language given below and it is very well detailed in the section of uses of java programming language .

    Uses of Java Programming Language

    Guys you are here to learn Java programming language with our easy Java Tutorial right ? But do you know the uses of java programming language .There are many reasons and usage of Java programming language. Some major points are listed below . In one section very soon we will also throw light on scope of Java programmer .

    • The Java programs are portable in a network (platform independent). The code written by programmer is compiled into bytecode. This bytecode can run anywhere in a network (server or client) with JVM which interprets the bytecode into computer understandable code. The JVM have an optional JIT compiler which compiles the given bytecode into m/c readable code.
    • Programs written in java language are robust. Java programs is different from other languages e.g. C++ as it contain no references to data external to other object(s). The JVM ensure integrity by applying a number of checks on each object.
    • Java is object-oriented language where objects are thought of as “nouns” with which we relate to. A method of a class renders object’s behaviors.
    • As compared to other languages java is relatively easy to learn and easy to write, specifically for developer with background in C. Also finding errors is very easy in java.
    • Java language is designed to work on distributed computing which means all programs in Java are same as sending and receiving data from a file.
    • Java supports multi-threaded environment which help user to write program to perform several tasks simultaneously.

    Now let’s know more on Java Tutorial .

    Java editors

    As Java is getting very popular among the developers, many IDEs (Integrated Development Environments) have been developed to help programming in writing code effectively and quickly. Following are some very popular java IDEs

    • Very old yet effective tool to write java program is Notepad . Developers working Windows machine can take the help of simple text editor like Notepad or TextPad. They can use java command for compiling and running java code e.g. java etc.
    • Netbeans is also quite popular Java IDE. It is available as an open-source and free bundle at https://www.netbeans.org/index.html.
    • Last but very popular IDE is Eclipse. This IDE is getting developed and maintained by the eclipse open-source community. Users can download Eclipse IDE at https://www.eclipse.org/.

    Java Editions

    The Journey of Java is continuously getting matured  with time in both functionality and reachability to all services. The Java platform has mainly three different Java editions which are defined below:

    Here is the Java editions list –

    J2SE(Java 2 Service Edition) is first edition of Java which was developed for writing applets  and other Java-based applications based on applets.

    J2EE(Java 2 Enterprise Edition) is the second edition of Java architecture for developing multi-tier enterprise applications. The basic development in J2EE was JSP pages with access to all J2EE components, including JavaBeans and servlets. These JSP pages at the end compiled into servlets and have all the benefits of server-side Java applications.

    JavaFX is a inbuilt Java library which helps users to build Rich Internet Applications. Multiple platforms can run this applications consistently using this library. These developed application JavaFX can run on various type of electronic devices such as Desktop Computers, TVs,  Mobile Phones, Tablets, etc.

    J2ME(Java 2 Micro Edition) is the third edition of Java architecture with the help of which programmers use java programming language to develop programs for mobile wireless information devices such as cellular phones and personal digital assistants devices.There are many devices where Java application are getting used. Some of them are:

    1. Web Applications such as irctc.co.in etc.
    2. Desktop Applications such as video players, document readers, media player, antivirus applications etc.
    3. Enterprise Applications such as financial applications.
    4. Mobile applications
    5. Million of Games

    Type of Java applications

    Next important section of our Java Tutorial is about Types of Java Applications .There are basically four types of Java applications which are explained below:

    Standalone Applications

    A standalone application is a program which is installed in your PC and runs only on your computer. In case you want to use this application, you need to explicitly install it into your m/c.

    Applets

    An applet are compatible with Internet can share information over it. These are to be executed on the client machine which should have Java-Compatible web browser like Internet Explorer or Mozilla. Applets themselves are Java programs which reside on server side. Applet can be implemented by embedding it into an HTML page (image or sound file) and they cannot be executed alone. To run applet one should need to access an HTML page which has embedded applet. Whenever web browser downloads respective HTML page, it also downloads the installable file. This file contains Applet which executes it on the local machine.

    Web Applications

    As the name suggest, Web applications run on the Web Server over the internet. Web applications can be accessed with the help of web clients (web browsers). Whenever user open any web page by specifying the URL (Universal Resource Locator), he/she actually access some web application.

    The main components of a web application in Java are Java Servlets, Java Server Pages (JSP) and HTML.

    Java Servlets are server side Java programs which send the result (also called response) to the client side java program. JSP pages can be thought client side java program which are combination of HTML and Java Code. The Web Server then converts the JSP pages into Java Servlets before execution of the program.

    User access the web application by specifying the URL and the respective URL corresponds to an HTML page. This desired HTML page is returned by the server when the user send request. In case the respective URL corresponds to the Servlet or JSP then it is executed on the Server side and the corresponding response will be returned to the client for rendering.

    Distributed Applications

    Java application is composed of different components (or Java programs). These Java components run on different machines and can easily communicate with each other. To be more specific we can say that Java Objects on one machine can use methods of the Java Objects from another machine. This make Java more suitable for distributed processing in the language.

    Our Next section on Java Tutorial will be Java Virtual Machine (JVM), Difference JDK, JRE & JVM .