• Home
  • Blog
  • Courses
  • Become an Instructor
  • About Us
  • Contact Us
  • Register
Have any question?

(+91) 9487526428
manojhails@gmail.com
RegisterLogin
Mind Feed
  • Home
  • Blog
  • Courses
  • Become an Instructor
  • About Us
  • Contact Us
  • Register

Programming Languages

Graphical Illustrations of Programming Concepts
  • Home
  • All courses
  • Programming Languages
  • Java for Beginners Step by Step Guide
CoursesProgramming LanguagesJava for Beginners Step by Step Guide
  • Introduction to java

    The aim of Java is to write programs that runs on variety of computer systems and computer controlled devices. This is often called as "Write once run anywhere". This Session explains Java's typical development environment.

    2
    • Lecture1.1
      Fundamentals – Memory, Data and Data Types in Java
    • Lecture1.2
      How to Compile Java Program
  • Your First Java Program

    In this session we will write a simple Java program, understand memory concepts, use arithmetic operations, use input and output statements, etc.

    1
    • Lecture2.1
      Program: “Print a line of text”

    How to Compile Java Program

    Java program shall be created, compiled, and executed in two different ways. One is the traditional way of using text editors like Notepad, Notepad++, TextEdit, EditPlus, etc., and compiling on the terminal window.

    The second way is using IDE (Integrated Development Environment) like Eclipse, NetBeans, IntelliJ Idea, etc.

    I will be using NetBeans IDE throughout this course as it is owned by oracle – the same company which owns Java.

    Benefits of Using IDEs for Compiling Java Program

    • Most IDE’s are open source software – means they are free.
    • Organization: It is very easy to organize files using IDE.
    • Efficiency: You can code, compile and execute programs in IDEs much faster. 
    • Debugger: Debugger instantly reports your program errors even before compiling. This helps the programmer to save much time.
    • Intelligence: IDEs assist in suggesting keywords like functions, variables, class hierarchy., then and there to the programmers. For example, whenever you call a function, its arguments are automatically suggested for you.
    • Collaboration: IDE’s helps colleagues to work together on large projects.

    Java Development Process

    The Java development (create, compile and execute) process has 5 phases.

      1. Edit
      2. Compile
      3. Load
      4. Verify
      5. Execute

    Phase 1: Creating a Program

    This phase has the following process:

      1. Java program is typed in a text editor and saved on the computer hard drive. The file must be saved with a .java extension. This is an indication to the compiler that this file contains a java program.
      2. This program typed on a text editor is known as source code. 
      3. For Example, let us type a java code in a file and name it HelloWorld.java
      4. There are two types of text editors: Conventional text editors such as Notepad, TextEdit, etc., and modern IDE’s such as NetBeans, Eclipse, etc.

    Note: We use NetBeans IDE throughout this course.

    Java Compilation Process - Edit
    Java Development Environment – Edit

    Phase 2: Compiling a Java Program

    In this phase, we compile a java program into ByteCodes

      1. For this, we need to call the java compiler called javac. (javac is the name of the java compiler).
      2. Now the question is how to call this java compiler?
      3. If you are running your Java program on Command Prompt such as Windows Command Prompt or Terminal in Mac or Shell in Linux, you need to type the following command to compile.
        javac filename.java [Example: javac HelloWorld.java]
      4. If you are using any IDE’s like Eclipse, NetBeans, IntelliJ Idea, etc., you can just click on the Build/Make/Run buttons to compile the program easily. This invokes the javac command for you.
      5. If your program has no errors, it will be compiled successfully. This creates a .class file called filename.class. [in our example, HelloWorld.class]
      6. This .class is the compiled version of your program, aka ByteCode.
    Java Compilation Process - Compile
    Java Development Environment – Phase 2 – Compile

    Phase 3: Loading a Program in to Memory

    A Note on JVM

    Java Virtual Machine

    • The ByteCode (.class file) is architecture-neutral and can be run on any machine that has the JVM – Java Virtual Machine.
    • A JVM is a program that gets installed with the SDK (Java Software Development Kit) in your machine. This JVM interprets the Java bytecode.
    • This is the primary advantage of Java. Java ByteCode can run on a variety of hardware platforms and operating systems.
    • JVM translates the bytecode line by line into machine-understandable instructions.
    • Here memory refers to RAM (Random Access Memory).
    • JVM is a very complex software that has many parts. One such part is the class Loader. The JVM’s class loader takes the .class (bytecode) files containing the program’s bytecodes and transfers them to primary memory (RAM).
    • Note: The .class files can be loaded from your hard disk or from any network.
    Java Compilation Process - loading a program in to memory
    Java Development Environment – Phase 3 – Load

    Phase 4 - Bytecode Verification

    • Another part of the JVM software is the bytecode verifier, which examines the bytecodes to ensure that they are valid and do not violate java’s security restrictions.
    • Sometimes the bytecode arriving from the network may have viruses that may harm your computer.
    Java Development Environment - Verify
    Java Development Environment – Phase 4 – verify

    Phase 5 - Execution

    • The word Execution means that your program is actually running on your machine (computer).
    • The JVM executes the bytecodes on your machine, thus performing the actions specified by the program.
    Java Development Environment - Execute
    Java Development Environment – Phase 5 – Execute

    Summary

    The java compilation process actually happens in phases.

    • The source code is translated into bytecode by the java compiler.
    • The bytecode is translated into machine-understandable code by the JVM across platforms.
    A Note on JIT-Compiler
    • What is an Interpreter?
      • An Interpreter executes one line of code at a time and translates it into machine code.
      • Early versions of JVM simply interpret the bytecodes which are very slow.
    • What is a compiler?
      • A compiler executes the entire program into machine-understandable code which is much faster.
    • Just in time Compiler (JIT)
      • Java uses a combination of the interpreter and a just-in-time compiler.
      • JVM scans the entire bytecode and analyses the frequently used bytecodes.
      • The JIT-Compiler translates these frequently used bytecodes into machine codes.
      • When these bytecodes appear again in the program, the faster machine code executes.
    Prev Fundamentals – Memory, Data and Data Types in Java
    Next Program: “Print a line of text”

    Leave A Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    • Programming Languages

    Latest Courses

    Java for Beginners Step by Step Guide

    Java for Beginners Step by Step Guide

    Free

    (+91) 9487526428

    manojhails@gmail.com

    COMPANY

    • Home
    • Blog
    • About Us
    • Contact Us

    LINKS

    • Courses
    • Become an Instructor
    • Terms and Conditions
    • Privacy Policy
    • Return & Refund Policy

    RECOMMEND

    • ZOOM Tutorials

    SUPPORT

    • My account
    • Profile
    • Register
    • Members

    Developed By Manoj A by Mind Feed

    Become an instructor?

    Join thousand of instructors and earn money hassle free!

    Get started now

    Login with your site account

    Continue with Facebook
    Continue with Google
    Lost your password?

    Not a member yet? Register now

    Register a new account

    Continue with Facebook
    Continue with Google

    Are you a member? Login now

    Modal title

    Message modal