Tuesday, 10 January 2012
Monday, 9 January 2012
Java Datatypes?
Many people have to know the basic data types. Without the knowldege of data types we can't do anything over programming.
Let me explain java data types in detail ;-
The Java programming language is statically-typed, which means that all variables must first be declared before they can be used. This involves stating the variable's type and name, as you've already seen:
int gear = 1;
Doing so tells your program that a field named "gear" exists, holds numerical data, and has an initial value of "1". A variable's data type determines the values it may contain, plus the operations that may be performed on it. In addition to int, the Java programming language supports seven other primitive data types. A primitive type is predefined by the language and is named by a reserved keyword. Primitive values do not share state with other primitive values. The eight primitive data types supported by the Java programming language are:
byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive).
short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive).
int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive).
long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).
float: The float data type is a single-precision 32-bit IEEE 754 floating point.
double: The double data type is a double-precision 64-bit IEEE 754 floating point.
boolean: The boolean data type has only two possible values: true and false.
char: The char data type is a single 16-bit Unicode character.
What is scoping : In other words i can say Life Cycle of an variable within a program.
Strings : Java provides a class definition for a type called String
Since the String class is part of the java.lang package, no special imports are required to use it (like a header file in C).
Just like regular data types (and like C), variables of type String are declared as:
String s1;
String s2, s3; //etc.
Please feel free to comment....
Thursday, 5 January 2012
What is Inheritance?
We have to know the inheritance concept good enough to start programming.
Guys its simple : One object persisting the properties of another object , I mean I have some of my dad qualities that’s it.
Main things we have to make a note is Parent Class,Child Class, super keyword and this pointer.
As the name suggests, inheritance means to take something that is already made. It is one of the most important feature of Object Oriented Programming.
Someone has written it and we just use it in our programming by just extending the class with the extend keyword.
Concept : The concept of inheritance is used to make the things from general to more specific e.g. When we hear the word vehicle then we got an image in our mind that it moves from one place to another place it is used for traveling or carrying goods but the word vehicle does not specify whether it is two or three or four wheeler because it is a general word. But the word car makes a more specific image in mind than vehicle, that the car has four wheels . It concludes from the example that car is a specific word and vehicle is the general word. If we think technically to this example then vehicle is the super class (or base class or parent class) and car is the subclass or child class because every car has the features of it's parent (in this case vehicle) class.
Car is derived from vehicle, so vehicle is parent and car is child.
KEYWORDS USED IN INHERITANCE : SUPER : THIS KEYWORD IS USED WHEN WE WANT TO USE A SUPER CLASS IN SUBCLASS
IN SIMPLE WORDS, SOME ONE HAS WRITTEN A CODE AND KEPT IN A FILE AND WE WANT TO USE IT. WHAT WE DO IS WE JUST WRITE A CLASS AND EXTEND THE SUPER CLASS.
LIKE CLASS MYNAME EXTEDS SUPERNAME
WHAT IS SUPER KEYWORD ?
The super is java keyword. As the name suggest super is used to access the members of the super class.It is used for two purposes in java.
e.g. Suppose class A is the super class that has two instance variables as int a and float b. class B is the subclass that also contains its own data members named a and b. then we can access the super class (class A) variables a and b inside the subclass class B just by calling the following command.
SUPER.MEMBER;
Subscribe to:
Posts (Atom)
