Programming Fundamentals
Token
The smallest individual unit in a
program is known as Token. Java has the following types of tokens: keyword,
Identifier, literal, punctuators and operators.
Keywords
Keywords are words that have a
specific predefined meaning in Java. They cannot be used as variable names.
They are also known as reserve words. eg. void, private, if, while etc.
Literals:
Items having fixed data values are
referred to as Literals. They are also known as Constants. Various types of
literals available in Java are :
§
Integer literals
– may be a positive or negative integer number (without decimal).
§
Floating
literals- a decimal number.
§
Boolean literals-
true or false
§
Character
literals – a single character in single quotes.
§
String literals-
group of characters enclosed in double quotes.
§
Null literals –
special symbol indicating nothing.
Identifier:
A
user given name to any object, class, variable or constant. The naming rules
for identifiers are-
Ø
Identifiers may have alphabets, digits
and dollar ($), underscore (_) sign.
Ø
They must not be Java keywords.
Ø
They must not begin with digit.
Ø
They can be of any length.
Ø
They are Case Sensitive ie. Age is
different from age.
Variable:
Variable is a named storage location
in computer memory whose contents can change during a program run.
Operators:
Operators are special symbols that
perform specific operations on one, two, or three operands, and then return a
result. Java offers the following types of Operators:-
v
Arithmetic Operator : - +, * , / , %
v
Increment/Decrement Operator : ++, --
v
Relational or Comparison Operators: >,
>= , <, <= , ==, !=
v
Logical Operators : &&, ||, !
v
Assignment Operators =, +=, -=, *= , /=,
%=
v
Other Operators . , new, type etc.
Expression:
An expression is a valid combination
of operators, constants and variable and keywords i.e. combination of Java
tokens. Java expression may Arithmetic, Compound and Logical depending on the
operators and values.
Data types in JAVA: Data types are means to
identify the type of data and associated operations of handling it. Java offers
two types of data types.
Primitive: These are in-built data types
offered by the compiler. Java supports 8 primitive data types e.g. byte, short,
int, long, float, double, char, boolean.
Reference: These are
constructed by using primitive data types, as per user need. Reference data
types store the memory address of an object. Class, Interface and Array are the
example of Reference Data types. The Java programming language is statically
typed, which means that all variables must first be declared before they can be
used.
Primitive Data types:
v Byte (1 Byte): The byte data type is an 8bit signed
two's complement integer. It has a minimum value of 128and a maximum value of
127 (inclusive).
v Short (2 Byte) : The short data type is a 16bit signed
two's complement integer. It has a minimum value of 32,768and a maximum value
of 32,767 (inclusive).
v Int (4 Byte): The int data type is a 32bitsigned
two's complement integer. It has a minimum value of2,147,483,648and a maximum
value of 2,147,483,647 (inclusive).
v Long (8 Byte): The long data type is a 64bitsigned
two's complement integer. It has a value from -263 to
263-1
v Float (4 Byte): The float data type is a
singleprecision32bit value from -3.4E+38 to +3.4E+38.
v Double( 8 Byte): The double data type is a
doubleprecision64bit -1.7E+308 to 1.7E+308
v Boolean (1 Byte): The boolean data type has only two
possible values: true and false. Use this data type for simple flags that track
true/false conditions.
v Char (2 Byte): The char data type is a single 16 bit
Unicode character. It has a minimum value of'\u0000' (or 0) and a maximum value
of '\uffff ' (or 65,535 inclusive).
Conversion of data- Parsing It is required to convert numbers
stored in string form in to numeral form so that calculation can be carried.
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
|
No comments:
Post a Comment