Thank you Visiting In Advance
BY IT PROGRAMMING WORLD
Java
Background of this Blog
A. Distinguish between valid & invalid identifiers?
B. List of eight primitives types?
C. Defines literal values for numeric and textual types?
D. Define the terms variables and reference variable?
Identifiers
“An identifier is a name given to a variable class or method.”
Identifiers have the following characteristics:
Can start with a Unicode letter, underscore (_), or dollar sign ($)
Are case-sensitive and have no maximum length.
Example of valid identifiers:-
ü identifier
ü username
ü user_name
ü _sys_var1
ü $chnage
Java programming language supports two basic data types:-
1. Primitive types
2. Class types
“Primitive data types are simple values, not objects.”
Ø The java programing language defines eight primitive data types, which can considered in four categories:
Logical - Boolean
Textual - char
Integral - byte, short, int and long
Floating - double and float
“Class types are used for more complex types, including all the types that you declare yourself.”
ü They are used to create objects.
Ways of declare variables, Declarations, & Assignments.
Public class Assign
{
Public static void main(String[]args)
{
//declare and assign values to int
Integer variables int x=6, y=1000;
//declare and assign floating value
Float z=3.414f;
//declare and assign value to Boolean
Boolean truth=true;
//declare and assign value to char variable
Char c=’A’;
}
}
Ø In java programming, beyond primitive types all other types are reference types.
Ø A reference variable contains a handle to an object.
Example:
Public class MyDate
{
Private int day=9;
Private int month=11;
Private int year=1991;
Public MyDate(int day, int month, int year)
{…………..}
Public String tostring()
{…………}
}
Public class TestMyDate
{
Public static void main(String[]args)
{
MyDate today=new MyDate(9,11,1991); // create object of MyDate Class
}
}
Ø Variable “today” is a reference variable holding one object of “MyDate” class
No comments:
Post a Comment
Please Comment Your Valuable Feedback....