Saturday 8 November 2014

About JAVA


Where does java has come from?
In the history of programming languages B led to C, C with some additional features has become C++ and C++ with some more additional features shaped Java. Java is the mix of best programming elements in all programming languages.
What is the need to learn Java?
The answer for this question comes from java's unique features it offers.
Java is being used in internet extensively because of it's platform independence. Byte code is the reason for this.
Why would developers choose java as their choice?

Overview of JAVA


As we all know java is object-oriented.
What do you mean by Object-oriented?
Well, Object-oriented means, everything we deal with, in java is basically an object.
When we get into the later topics you will understand the power of objects.
What is an Object?
Object is an instance of class. In objected oriented programming languages as in java this concept is mainly taken from the concept real world concepts. For example in the world we may have several cars(BMW, suzuki, audi..) but we represent the whole cars as a single class and when we come to any particular car brand we assign a brand name for that. This is similar Class and Object paradigms in JAVA.

Hello World

Let's start with world's former program HelloWorld.
Have a look at the following code.

Data types and Variables


Java has 8 simple data types: byte, short, int, long, char, float, double, and boolean.
These can be categorized in to four groups
Integers: byte(8 bit), short(16 bit), int(32 bit) and long(64 bit)
Floating point numbers: float(32 bit) and double(64 bit)
Characters: char( range is 0-255)
Boolean Values: boolean( either true or false)
Now let us take another example to get complete picture about variables. 

Arrays

One dimensional arrays

 As we have seen earlier simple variables stores single value. If we want to store multiple values of same type in single variable we can use arrays.
Structure
int arr[];
arr=new int[10];
Let us have a look at this one
As I told you earlier here arr is a variable of data type integer but in addition to that we have a new symbol [] which says that arr is a array variable. This is just declaration.

Multi dimensional arrays


Earlier in one dimensional array we have declared our array as int arr[] but here we declared as int arr[][]. So one thing you might be cleared now is that if you want to create n dimensional array you have to keep n [] braces after your variable name.
Next part is defining array i.e. assigning length of array. Here we defined our array as new int[10][10]. It says that our array contains 10 rows each row containing 10 columns. If you don't get the idea just draw a table with 10 rows and 10 columns and that is your arr[10][10].