Introduction to Java

 Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995. The language was initially called “OAK” after an “OAK” tree that stood the outside Gosling’s Office but later it gets changed to the JAVA because OAK was trademark used by OAK Technology. The popularity of Java is because of Rich Library, Rich Constructs, Applets.

Java is one of the most accepted languages out of all the languages known today. It is intended to let application “write once, run anywhere” (WORA), means code that runs one machine/platform does not need to be recompiled to run on another.

Buzzwords/Features of Java :

  • Simple: It indicates that developer finds coding easy in Java. It is easily interpreted by users as well
  • Portable
  • Powerful: It has Rich Library
  • Secure and Robust
    •  Java is popular for the security standards and features of safe programming. Enterprise could download any folder using non-trusted programs. Moreover, the application can use these codes securely.
  • Dynamic
    • Types of Memory Allocation Techniques:
      • Static:
        • Compile time: larger lifespan (reduces efficiency)
        • Fixed in Size (Storage Problem)
      • Dynamic:
        • Runtime: Shorter lifespan (increases efficiency)
        • Flexible in size
  • Distributed : 
    • A development stage called distributive calculation involves two or more processors connected to a common network.
    • Java possesses a great networking capability informal interactions’ with java programs help in writing programming instruction such as receiving, sending files.
  • Multi-threaded :  (Multi-tasking + Sharing of Data)
  • True OOPS
    • Encapsulation: (Hiding Non-Essential Details)
    • Abstraction: (Give Essential Details)
    • Inheritance: (Reusability, Extending, Overriding)
    • Polymorphism: (One name multiple forms)
  • Compiled & Interpreted, yet high Performance
  • Platform Independent : 
    • Java works across the platform with ease. It has the capability to run on any platforms with a single uniform code. Application developed on java is held by each java compatible browser.

In above pointers, we tried to give you a brief description on buzzword of JAVA. Now, let’s have a look at some basic concepts of JAVA:

Data Types

Data Types specifies the type of data to be stored and the size of memory to be allocated. It can be classified as :

  • Fundamental Datatype
  • Derived Datatype

Variables In Java

  • These are the temporary memory locations used to store values
  • Here values stored in it can change/vary
  • Some of the Variables naming Conventions followed are:
    • No spaces, no special characters except underscore( _ ) and dollar ($)
    • Variable should start with an alphabet
    • It should not be a Keyword & it is case sensitive
    • Variables should be unique within its scope
    • It should follow camelCase & can contain Unicode characters

Access Specifiers

There are 4 access specifiers in Java. They specify the scope of member data, member functions, class, and interface.

  • Private: Its scope is within class
  • Protected: Its scope is within class and derive class
  • Package*(default) : Its scope is within directory/folder
  • Public: Its scope is anywhere in the class

Classes and Objects

  • Class: A template that describes the kinds of state and behavior that objects of its type support

    • It is a collection of member data/attributes and member functions/methods
    • It is used to create a user define/real-time data type
    • Member data specifies the type of data to be stored
    • Member functions acts as a mediator between user and data
    • It implements Encapsulation and abstraction
  • Object: They are the instance of a class and stores data and invoke methods

Input/Output Procedure In java

  • To take input from user “Scanner” class is used which is introduced with JDK 1.5
  • This “Scanner” class comes from java.util.package
  • To use “Scanner” class in Java program Statement is
    • import java.util.Scanner;
  • To associate Scanner to Keyboard
    • Scanner s = new Scanner(System.in);
  • To accept a word
    • String word = a.next();
  • To accept a line
    • String line = a.nextLine();
  • To accept a character
    • char c = a.nextLine().charAt(0);
  • To accept an integer
    • int num = a.nextInt();
  • To accept a float
    • float fp = a.nextFloat();
  • To accept a double
    • double d = a.nextDoble();

Requirements for Interpretation:

  •  JVM
    • JVM stands for Java Virtual Machine
    • It loads the class files and either interprets the bytecode or just-in-time compiles it to machine code and then possibly optimizes it using dynamic compilation
  • Just-in-time Compiler (JIT)
    • JIT is the part of the Java Virtual Machine (JVM) that is used to increase the speed whenever the bytecode is converted into machine code
    • JIT compiles parts of the bytecode that have similar functionality at the same time, and hence reduces the amount of time needed for compilation
    • It is different for different machines
    • You can consider the following way example to understand

Suppose there is a building with ground and the first floor. The compiler is sitting on the ground floor which welcomes or accepts the .java file and compiles it to .class file (bytecode). Now, this bytecode goes to the Java Virtual Machine that is on the first floor where the JVM do its work.

  • JRE
    • JRE stands for Java Runtime Environment. It contains Java Virtual Machine plus set of classes and interfaces which are loaded to create the environment i.e. the Java Runtime Environment

Software Requirements:

  • JDK: Java Development Kit
    • Compiler —————————— javac
    • Interpreter —————————- java
    • Debugger —————————– jdb
    • Documentation Tool ————— Javadoc
    • To View Applets ——————– appletviewer
    • Java library ————————— Java API (Application Prog. Interface)
  • Editor:
    • Basic: Notepad,Edit,VI
    • IDE:  Integrated Development Environments (Eclipse,NetBeans, WebSphere Studio)

Now, let’s look how a java program get to execute in JRE

From the above diagram one can understand that easily:

Here, source code(.java file) is compiled using javac compiler, which is then converted into Bytecode(.class file) and from Bytecode, it is interpreted using java interpreter to give output (Machine code).

Machine code: Binaries + Machine Dependencies

Byte Code: Machine code + Machine Dependencies

Sample Program:

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

Below is the explanation of all the Keywords used in the above program:

public: It can be called from anywhere.

static: No Object is required to execute main.

void: Does not return any value.

main: Name of the function

String args[]: Command Line Arguments.

 

 

 

 

 

Now let’s check out some of the basic programs a beginner should start with on git repo of P3Lang