Breaking News

Thursday, 19 May 2016

Java Environment Setup

This Tutorial will guide you how to download and setup JAVA on your machine.

Please follow the following steps to setup the Environment:-


  • You can download the Java version based on your Operating System.
  • Once you downloaded java run the .exe file and install java on your machine.
  • Follow the instructions to set up the path:-


Setting up the permanent path for windows:- 

Assuming you have installed java on C:\Program Files\Java\jdk directory.

1.) Go to my computer properties.


2.) click on advance system settings tab.


3.) Click on the Environment variables.


4.) Click on the new tab for user variable.


5.) Write path in variable name.


6.) Copy the path of bin folder.


7.) Paste the path of bin folder in variable value.


8.) click ok.

Now your permanent path is set. You can now execute any program of java from any device.

Setting Java Path in Linux Operating System.
Setting the path in Linux OS using export tool rather than set. Let's see how to set path in Linux OS:

export PATH=$PATH:/home/jdk1.7.0_79/bin.

Here, we have installed the JDK in the home directory under Root (/home).
Read more ...

Sunday, 15 May 2016

JAVA COMPILE & LINKING PROCESS

Let us suppose we have a program like:-

This is a main method which is stored in a1.java which has two methods m1 and m2. Where m1 is stored in a2.java and m2 is stored in a3.java


 The Compiler will Compile all three files and produce corresponding .class files which consists of BYTECODE unlike C language no linking is done


JVM ARCHITECTURE:-

During execution of program all class files are bought to the RAM by class Loader. The byte code verifies security breaches and check byte code format next the execution engine will convert the byte code into native machine code and this is just in time compiling and it is one of the main reason the java is slow as compared to C Language


Read more ...

Saturday, 14 May 2016

Java Virtual Machine

A Java virtual machine (JVM) is an abstract computing machine that enables a computer to run a Java program.An implementation of JVM specification, interprets compiled Java binary code (called bytecode) for a computer's processor (or "hardware platform") so that it can perform a Java program's instructions.

There are three notions of the JVM: specification, implementation, and instance.

  1. Specification:- The Specification is a document specifies an instruction set, a set of registers, a stack, a "garbage heap," and a method area. where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Sun and other companies. Anybody is free to take that spec and build their own jvm implementation.Think of specification like a blueprint and implementation is like the house you built from it.
  2. An implementation It provides an implementation of a jvm based on jvm specification. Once a Java virtual machine has been implemented for a given platform, any Java program (which, after compilation, is called bytecode) can run on that platform and this implementation is known as JRE(Java Runtime Environment.) JRE includes a Java Virtual Machine implementation together with an implementation of the Java Class Library.
  3. Runtime Instance: It provides an instance of jvm implementation. A Java virtual machine can either interpret the bytecode one instruction at a time (mapping it to a real processor instruction) or the bytecode can be compiled further for the real processor using what is called a just-in-time compiler. Whenever you write java command on the command prompt to run the java class, and instance of JVM is created. Different companies have their own implementations of the JVM runtime from the spec.
The JVM Loads Code, Verifies Code, Executed Code, Provide Runtime Environment and provides definitions for the memory area, class file format, Register set, Garbage-Collected heap, Fatal error reporting etc.

JVM provides definitions for the:-

  • Class Loader:- A class loader is an object that is responsible for loading classes. The class ClassLoader is an abstract class. Given the binary name of a class, a class loader should attempt to locate or generate data that constitutes a definition for the class. A typical strategy is to transform the name into a file name and then read a "class file" of that name from a file system.
  • Method Area:-  When the Java virtual machine loads a type, it uses a class loader to locate the appropriate class file. The class loader reads in the class file--a linear stream of binary data--and passes it to the virtual machine. The virtual machine extracts information about the type from the binary data and stores the information in the method area. Memory for class (static) variables declared in the class is also taken from the method area. It basically stores:-

Type's Information:-
  • Fully qualified name of the type  
  •  Type's superclass fully qualified type name 
  •  The type's modifers such as public, protected, final, abstract, etc. 
  •  An ordered list of the fully qualified names of any direct superinterfaces. 
In addition to Type's Information it also stores:-
  • The Constant pool for the type. 
  •  Methods and Fields Information. 
  •  Classes Static and instance variables, except Constants. 
  •  A reference to Class Loader. 


  • Heap:-In running program whenever a new object is created the memory used is allocated from the heap. Virtual Machine also provides the Garbage Collector to collect the allocated memory when object execution completes.
  • Java Stack:- When a new thread is launched, the Java virtual machine creates a new Java stack for the thread. The Java virtual machine only performs two operations directly on Java Stacks: it pushes and pops frames. Java Stack stores frames.It holds local variables and partial results, and plays a part in method invocation and return. A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.
  • PC Registers:-It contains the address of the java virtual machine instruction currently being executed.
  • Native Method Stack:-  When a thread invokes a native method, it enters a new world in which the structures and security restrictions of the Java virtual machine no longer hamper its freedom. A native method can likely access the runtime data areas of the virtual machine (it depends upon the native method interface), but can also do anything else it wants. It may use registers inside the native processor, allocate memory on any number of native heaps, or use any kind of stack.
  • Execution Engine:-It contains: A virtual Processor, interpreted and Just In Time Compiler (JIT).




Read more ...

Wednesday, 11 May 2016

Introduction

Java Programming Tutorials




INTRODUCTION

Java is a high-level programming language originally developed by James Gosling at Sun Microsystems, which is now a part of Oracle Corporations. 
Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented.  The language has developed much of its syntax from C and C++. Java applications are usually compiled to bytecode (class file) that can run on  any javavirtual machine, which makes developers to write once and run anywhere.
Features of Java:-
1. Java is Simple and Object Oriented:
·         Object Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc.
·         Object Oriented Method combines data and Instructions for processing that data into a self-sufficient ‘object’ that can be used within a program or in other programs.
·         Objects are modeled on real world entities and This enables modeling complex systems of real world into manageable software solutions.

2. Java is Robust and Secure:-
  • Java is built with OOP's Concepts making it a robust programming language.
  • Java has its own automatic garbage collection, which prevents memory leaks and extensive compile-time checking so bugs can be found early; this is repeated at runtime for flexibility and to check consistency.
  • Java's memory allocation model is one of its main defenses against malicious code(e.g. can't cast integers to pointers, so can't forge access).
  • Furthermore, access restriction are enforced(public , private), byte codes are verified, which copes with the thread of a hostile compiler.
3. Java is Architectural Neutral:- Java compiler generates bytecodes, which have nothing to do with a particular computer architecture and easy to interpret on any machine.

4. Java Support Multithreading:-
  • Java allows multiple concurrent threads of execution to be active at once. This means that you could be listening to an audio clip while scrolling the page and in the background downloading an image.
  • Java contains sophisticated synchronization primitives (monitors and condition variables), that are integrated into the language to make them easy to use and robust.
  • The java.lang package provides a thread class that support methods to stat, run, and stop, and check on its status.
5. Java is Dynamic:- Java was designed to adapt to an evolving environment:
  • Even after binaries have been released, they can adapt to a changing environment.
  • Java loads in classes as they are needed, even from across the network.
  • It defers many decisions(like object layout) to runtime, which solves many of the version problems that C++ has.
  • Dynamic linking is the only kind there is.

6. There are many types of Java Programs such as Java Applets, Application, Jar File, Servlet, Swing Application, EJB and many more.



Read more ...
Designed By Published.. Blogger Templates