Thursday, 1 December 2016

parse Method and Type Casting

Variable Declaration:
In Java, all variables must be declared before they can be used. The basic form of a variable declaration is:
DataType identifier [ = value][, identifier [= value] ...] ;
Here, The DateType is one of Java's data types. The identifier is the name of the variable. To declare more than one variable
of the specified type, use a comma-separated list.
Note: Java variable names are case sensitive, so MySum and mySum are not same variable.
Example:
int x, y, z; // declares three integers type (int) x, y, and z.
int d = 3, e, f = 5; // declares three more integer with
initialization byte z = 34; // initializes z.
double pi = 3.14; // declares an approximation of pi.
char ch = 'H'; // the variable x has the value 'x'.
parse methods: parse() methods helps to parse string into different numeric types. These are :
parse methods: parse() methods helps to parse string into different numeric types. These are :
Method Syntax Usage
parseByte() Byte.parseByte(string) To convert a string value to byte type
parseShort() Short.parseShort(string) To convert a string value to type short
parseInt() Integer.parseInt(string) To convert a string value to Integer type
parseLong() Long.parseLong() To convert a string value to Long type
parseFloat() Float.parseFloat() To convert a string value to Float type
pareseDouble() Double.parseDouble() To convert a string value to Double type
Type Conversion:
The process of converting one predefined type into another is called Type Conversion. These are of two types:
a) Implicit type conversion
b) Explicit type conversion
 Implicit Type Conversion:
In this conversion java compiler converts all operands up to the type of largest datatype.
The implicit type conversion wherein datatypes are promoted to higher data type is called Coercion.
 Explicit Type Conversion:
An explicit type conversion is user defined that forces an expression to be of specific type.
Syntax :
(DataType) expression
Example :
int x=10, y=15;
(float) ((x+y)/2);
BOOLEAN (LOGICAL) EXPRESSION
Expression that result either true or false is known as boolean expression. It is the combination of constants,
variables, logical and relational operators.
For example:
(a>b) && (a>c)
(m+n) > b || (c+d) > a

No comments:

Post a Comment