Refresher course of Java for Testers and beginners – Introduction

Refresher course of Java for Testers and beginners – Introduction

Java is a very popular language and there are many reasons for that. A few listed here as:

  1. Platform Independent
  2. Object Oriented
  3. Strong Open Source community

Installations –

To start with the course you’ll need to install JAVA and any of your preferred editor(Eclipse IDE in this case). Follow below URL’s to download and install on your m/c

  1. Java SE Downloads –
  2. Eclipse –
    2nd Option Enterprise

Setting up PATH & CLASSPATH –

Omce you have JAVA installed on your m/c, you’ll need to set up 2 environment variables in your PC. This can be done either by configuring them on My Computer -> Advanced System Settings, or via adding them in a batch script every time you launch java or any other related application.

• PATH – The PATH environment variable specifies a set of directories where executable programs are located.
• The PATH environment variable is set to the bin folder of JDK installation.

CLASSPATH – The CLASSPATH environment variable specifies the class path on a given system.
• A class path is a list of locations that are searched for classes when the Java Virtual Machine attempts to locate a referenced class.
• The CLASSPATH must include the current directory in order to run Java programs from the command line with the java command.
• The Classpath environment variable is set to the class files folder of Java program.

Try on command line – Once you have setup JAVA correctly on your m/c then open command prompt and try below command.

java –version

This should return the current java version installed and configured on PATH variable. If this returns the latest version that you have just installed then you are all set.

Run command java –version to check whether java is correctly setup

Whats JVM, JDK & JRE

JVM stands for Java Virtual Machine.
• The JVM provides a platform-independent way of executing Java code.
• In Java, the Java complier translates the Java source code into an intermediate code know as byte code.
• The JVM interprets the byte code into the machine code depending upon the underlying operating system and hardware combination.

JRE (Java Runtime Environment)
• JRE contains JVM, class libraries, and other supporting files.
• If you want to run any java program, you need to have JRE installed in the system.
• The JVM runs the Java program using the class libraries and other supporting files provided in JRE

JDK (Java Development Kit)
• JDK contains tools to develop and run Java program.
• The various components of JDK are:
• Java Compiler
• Java Interpreter
• Java Documentation
• And More…

Why Java is Platform Independent?

Java is a high level programming language meaning a program written in Java language cannot be run on any machine directly. First, it needs to be translated into that particular machine language. Java compiler (javac) does this thing, by converting java source code(.java file) and translating it into machine code (byte code or .class file).

You can understand the execution flow by below sequence of events –

Java Virtual Machine (JVM) is a virtual machine that resides in the real machine (your PC) and the machine language for JVM is byte code. This makes it easier for compiler as it has to generate byte code for JVM rather than different machine code for each type of machine. JVM executes the byte code generated by compiler and produce output. JVM is the one that makes java platform independent. So, now we understood that the primary function of JVM is to execute the byte code produced by compiler. Each operating system has different JVM, however the output they produce after execution of byte code is same across all operating systems. Which means that the byte code generated on Windows can be run on Mac OS and vice versa. That is why we call java as platform independent language. The same thing can be seen in the diagram below:

Platform Independence in JAVA
  1. Programming Basics – by the help of sample program & showcase –
    • Documentation
    • Package
    • Import
    • Interface
    • Class
    • Main Method
First JAVA Program
  1. Try above program in Eclipse and compile and run in command prompt also. Just to see how it works in command prompt.
  2. Java Source Files
    • There can be only one public class per source file.
    • If there is a public class in a file, then, the filename must match the class name.
    • If the class is part of a package, the package statement must be the first line in the code.
    • The import statements must lie between the package statement and the class definition statement.
    • The package and import statements apply to all classes within the source code file.
    • A source file can have more that one nonpublic class.

Please follow and like us:
Pin Share

Leave a Reply

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