Aug 31, 2013

Basic Data Types in Java

Definition of Basic Data Types in Java:

Datatype (data-types) is the name of storage format which store the specific type's and its corresponding range's value.Different data types have been defined by java. These data types are frequently used by programmers. Data types in java are used to specify whether which type of value will be stored in specified variable. A variable is responsible for storing the particular value. But a variable does not store value itself. Variable is just a name for a memory location where a value is to be stored.Java has been defined different types of basic data types. We categorize them broadly into 2 category.

There are defined two types of data types in java-
  • Primitive Data Types
  • Non-Primitive/Reference Data Types

Primitive Data Types:

Primitive means ancient. As its meaning states Primitive Data Types are defined already in the Java API. Programmers can use them as their needs. There are eight types of Primitive Data Type defined in java. Let us take a look of all these eight primitive data types.
All eight primitive data types are as follows-

  • byte
  • short
  • int
  • long
  • float
  • double
  • boolean
  • char 

Data Type-byte

  • Byte data type in java is a 8-bit signed two's compliment integer.
  • Range of byte is from -128 to 127 i.e. minimum value is -128 and maximum value is 127.
  • Its default value is 0.
  • Byte data type in java is responsible to save spaces in large arrays, specifically in integer.
  • Byte data type is 4 times smaller than integer.
  • We can store a value in byte data type as- byte a=101, byte b= -40

Data Type-short

  • Short  data type in java is a 16-bit signed two's compliment integer.
  • Range of short is from -32768 to 32767 i.e. minimum value is -32768 and maximum value is 32767.
  • Short data type is also used to save memory.
  • Short data type is two times smaller than integer.
  • Its default value is 0.
  • We can store a value in short data type as- short a=10000, short b= -15000

Data Type-int:

  • Int data type in java is a 32-bit signed two's compliment integer.
  • Range of Int is from  -2147483648 to 2147483647 i.e. minimum value is -2147483648 and maximum value is 2147483647.
  • Int is specifically used as the default data type for integer values.
  • Its default value is 0.
  • We can initialize an int variable as- int a=100,int b= -2000

Data Type-long:

  • Long data type in java used when int data type is unable to store the value i.e. the value which is out of range of int data type can be stored in long data type.
  • Long data type is 64-bit signed integer.
  • Range of long is from  -9223372036854775808 to  9223372036854775807
  • Its default value is 0.
  • We can use a long type variable as- long a=150000L, long b= -250000L

Data Type-float:

  • Float data type in java used to store the fractional values i.e. the values which have decimal point. for ex- 10.25
  • float data type is  32-bit floating point .
  • Its default value is 0.0f.
  • float data type can not be used to store the currency value.
  • We can use float data type as- float a=25.45f

Data Type-double:

  • Double data type in java is also used to store the floating type values but of high range which can not be stored in float data type.
  • Double data type is 64-bit floating point.
  • It can also not be used to precise the value like currency.
  • Its default value is 0.0d.
  • We can use double data type as- double a=152.6

Data Type-boolean:

  • Boolean data type in java is used to store the logical values .
  • Boolean data type represents only one bit of information.
  • Boolean data type can store only two possible values true or false.
  • All relational operator returns the boolean type value.
  • Its default value is false.
  • We can use it as- boolean b=true

Data Type-char:

  • Char data type in java ,a 16-bit Unicode character is a very important data type..
  • Range of char data type lies between 0 to 65535 i.e. from '\uoooo' to '\uffff'.
  • Char data type is used to store any type of character. Some characters are hard to store in that situation we can make use of escape sequences to store that values.
  • We can store a value in char data type as - char a='A'

Reference Data types:

Reference data types are created by users. Reference data type are used to store the reference of the object i.e. reference data type are used to access the objects. Class,Interface,Array,Enum comes under the category of Reference Data type. A reference variable can store the reference of any reference data type and can refer to that class/interface/array/enum's object.
Default value of reference data type is null.
Example of reference data type in java-

Vehicle veh=new Vehicle();

In above example Vehicle is a class i.e. reference data type and veh is a reference variable of type Vehicle which is storing the reference of the Vehicle class's object.

We are providing a list of datatypes in a tabulated form.

Data types in java program

This is the complete description of Basic Data types in java.
Thank you. 

Aug 30, 2013

What is internal mechanism of Object creation code in java Programming

Internal Mechanism of Object creation code in java

Java:Internal mechanism of java object creating code in java-programming. Let us describe what is the main mechanism behind object creating code in java-programming. I am telling you what happens internally when an object gets created. 

If class name is My_class then object creation code will be-

My_class ob=new My_class();

We know that class is a reference data type in java. So "ob" is called as the reference variable of My_class. We know that assignment operator assigns some value from right hand side to left hand side. Here some value is being assigned to ob variable.
new operator is responsible for creating the object of the java program. We can not fetch address of the object so we assign reference of the object in a reference variable i.e."ob". Now we have the reference of object in "ob" variable by which we can access all non static variable of the My_class.

Here we are telling each term used in object creating code in java programming.

What is Object in java programming (object oriented programming)?

Objects in Java:An object oriented programming language

Definition of an Object:

An object in java programming is an instance of a class. Object is the implementation of the concept given by the class. Whenever an object is created all the non static member of the class gets activated. Object in java programming is responsible for allocating memory to all non static member of the class.
When object of the class is created , a context is created into heap memory area. In this heap memory all the non static member gets memory. The size of the context in heap is decided according to the members(if there are 2 integer variable in the class and 2 float variable then size of the context will be 16 bytes).
Here is a demonstration of how a member gets memory in the heap memory area(HMA). Discussing back to the object, Basically object is used to access/call non static members of the class. Without creating object we are unable to use members of the class, but indirectly it is possible. This indirect technique of calling/accessing non static members of the class will be discussed in later posts.

Why we can't access/call non static member of the class without creating object:

We can't access/call non static members of the class without creating object because each member of the class needs memory to execute. This memory is allocated to them as object is created. So unless we create the object of  the class, we can't use these members.

How to create an Object In java:

We can  create an object by using "new" operator.


class name <reference variable>=new constructor_name();


If name of class is My_class then-

My_class ob=new My_class();

Code written above corresponds to create the object the My_class Class. Now question arises what behind the creation of object of My_class Class. We will know about scene behind this in Internal mechanism of Object creation code.

Aug 26, 2013

Compilation of Java Program

Compilation of Java Program

Compilation of Java program is necessary before its execution. Javac is the compiler of java which compiles the source code of java program and JVM is the interpreter which generates machine code from the compiled source code. Compiling a java program we need a compiler known as JAVAC. See how to compile a java program in java programming. Compilation of a java program contains following steps-

1-Type your java program in a text editor.

2-Save it with the name of class with .java extension in your java program.
3-Now open command prompt and go to directory in which your java program has been saved.
4-Set the path of javac using set path=”path”
5-Type javac and enter file name with .java extension and press enter.
6-If your program is error free it will generate one or more .class file.
7-Type java and then file name without any extension and press enter.

Now you will see output.

For example if your java program is saved with name. then you have to follow following steps-
  •   Javac (press Enter).
  •  Java Test (press Enter).

Let us see how to compile the java program:-

We are providing some images of compiling java program that are as follows-

  • Writing source code in an editor.
  •  Compiling java program.
  •  Executing java program

Following above steps you can execute your java program successfully.

Create a java program:

Compile program via common prompt:

Program execution (Program output):

Program output after compilation

For further reading please follow Internal Mechanism behind Java Compiler.

Java compiler references:-

Aug 20, 2013

Java Virtual Machine (JVM): JVM in Java Programming

JVM: Acronym of JVM(Java Virtual machine). JVM is the main part of java .To Know more about JVM in java programming, read this post and see related articles. Step by step java programming tutorial.

Java Virtual Machine(JVM), the powerful tool of java has made java unbeatable in the programming language's industry. JVM,In short Java Virtual Machine is also known as JVM. Unlike other language java has different way to execute the program. Every language needs a compiler to compile the source code. Java also has compiler to compile the source code but instead of compiler it also has an interpreter to interpret the compiled code.

JVM (Java Virtual Machine) : What is JVM-

Concept behind this approach is that unlike other language java is a platform independent language i.e. program written on java can be executed on any platform. Now question arises how it is possible.
Code written on java first compiled by java compiler and converted in to a middle level code which can only be understood by java interpreter named JVM. Now this middle level code also named as byte code is converted into machine code for further processing.
When a general compiler compiles the source code,it gets directly converted into machine code which can only be understood only by the platform on which it was compiled. But in java,code is processed in two phases, first creation of byte code and then its interpretation. Produced byte code is understandable by all platform with the help of JVM. Because all operating system have inbuilt JVM.
Now we can say JVM is the backbone of java. Here discussion of JVM gets over. Later we will learn many new concepts in details.

Java Virtual Machine(JVM) References:-

Thank You
Java References:-

Aug 19, 2013

Introduction to java programming language

Introduction to java programming language. Step by step explanation of java programming introduction. Here we explaining introduction and basic concepts of java programming.

Java has been defined by many authors. Most of java authors have been written much content in their posts. Readers of java can get sufficient information from those sites but they cannot know actual internal mechanism of java in those posts.

I will tell learners the reality and internal working of java in my blog. Java is a programming language made by James gosling and his team. Java was created only for electronic consumable devices but later on it grew its size and now it is divided into 3 broad fields…

1. J2SE
2. J2ME
3. J2EE

Initially core idea behind java development was to develop a language which can be used for the programming of the chips. Java developers want to handle machines by the use of remotes. They did it along with development of the area of java too.

Java is the most secure, most reliable and most powerful language which can provide a broad range of usages. Java is the platform independent language so it’s a most commonly used language in industries. We will discuss how java is platform independent later….
Thank You
Java References:-