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....
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment