Sunday, 26 May 2013

How to print stars in right-triangle using JAVA??

Code to print stars in Right-Triangle using JAVA:
package basics;
public class Stars {
public static void main(String[] args) {
for(int i=1;i<=5;i++)
for(int j=1;j<=i;j++)

Output for the above Code: 


Tags: ,,

Tuesday, 30 April 2013

ARRAYs in Java

Arrays are a collection of similar objects.. 
For eg: Collection of X number of Integer Objects or Y number of Character Objects


  1. Single-Dimensional array (1D array)
  2. Multi-Dimensional array (nD array)




Coding on arrays will be explained in following posts

Saturday, 23 March 2013

What is a Class and Object??

A class is a template or blueprint from which objects are created.. Example of a class: Cars, Employee, Shapes etc.

class class-Name
//variables /methods/constructors

Relationship between Classes:
Classes share 3 types of relationship between each other. 
  • Dependance(uses-a)
  • Aggregation(has-a)
  • Inheritance(is-a)

An object is an instance of a class. The relationship is such that many objects can be created using one class. Each object has its own data but its underlying structure (i.e., the type of data it stores, its behaviors) are defined by the class.

Tags: ,,

Wednesday, 13 March 2013

Java Virtual Machine


A Java virtual machine (JVM), an implementation of the Java Virtual Machine 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. Java was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. A Java virtual machine makes this possible because it is aware of the specific instruction lengths and other particularities of the platform. Java is also called as WORA-Write Once Run Anywhere because of JVM's work. 

Working of a Compiler and JVM in JAVA:

  1. The java codes being written using notepad is saved as .java file 
  2. It is then compiled using the command javac
  3. If the compilation is successful .class file is created as a result of compilation. It contains the bytecodes
  4. The bytecodes should be converted into a machine code that a machine can understand 
  5. The JVM thus converts the bytecode into machine code and makes the file as platform independent executable file
  6. The executable file can be run on any platform such as Windows, Macintosh etc..
Though Compiler and JVM helps in making the java code platform independent, both Compiler and JVM are not platform independent. It must be downloaded according to your Operating System.

Components of JVM:
JVM comprises of 5 major components. They are:
  • Class Loader
  • ByteCode Verifier
  • Garbage Collector
  • Security Manager
  • Execution Engine

Class Loader
The class loader loads the .class file into the JVM. Class Loader is similar to Namespaces. Primarily class loader objects are created and then each class is loaded in steps. Classes loaded into 2 different objects cannot interact with each other. 

Bytecode Verifier:
The JVM verifies all bytecode before it is executed. This verification consists primarily of three types of checks:

  • Branches are always to valid locations
  • Data is always initialized and references are always type-safe
  • Access to private or package private data and methods is rigidly controlled.

Garbage Collector:
Garbage Collector is an application program that runs in JVM. Java does not allow deleting the objects tat are once created. The object that hang around unused leads to Memory Leakage and to avoid this Garbage Collector is used. GC uses Mark and Sweep methodology.

Security Manager:
Security Manager provide certain restrictions to the applications and applets. 

  1. For Application: No restrictions by default. 
  2. For Applet: Applets cannot access local drive and local network drive.

Execution Engine:
It is responsible for converting bytecode into a machine code. 

Tags: ,,

Tuesday, 12 March 2013

How was Java named??

Am email sent by James Gosling to tell How the name JAVA came into existence.. [ TRGN3746UZGA]

A Mail from Gosling

The Birth of Java!!

The Members - Team Green Project
Sun Microsystem's Green Project team in 1990, which was headed by James Gosling, wanted to develop a special software that could wield Consumer Electronic Devices. They explored many programming languages and finally concluded that C++ (which used object oriented programming technique) may be satisfying their needs. But during the initial development phase they found it was not platform-independent and faced many problems. They wanted a new language that would be platform-independent and hence developed the descendant of C++. It had similar syntax to C++ with portable features enabled. They named it as "OAK" inspired by an Oak Tree that was seen from their cubicle. The team validated their new language OAK to control house-hold appliances using touch-sensitive remote in 1991. The World Wide Web on the internet renovated the text-based internet into graphic-rich user-friendly internet. At this juncture the team proposed the idea of developing Web Applets (tiny programs) using OAK that could run on all systems connected to internet. The team then introduced HotJava (a web browser to locate and run applets on internet). HotJava demonstrated the power of OAK and made it crowd-pleasing on the internet. In 1995, an issue raised stating there existed a programming language named OAK. So the team arranged for a meeting with a Naming Consultant and concluded the name as "JAVA" (which is not a acronym). Many popular companies including Microsoft and Netscape Navigator promulgated their strong support to JAVA.