Won Contests Let Us Talk Mail Me Light of Knowledge


 Chapter 3 : Article 1 : Variables : Integer Type

01.Integer Variables are used as follows
class ex_integer
{
	public static void main(String args[])
	{
		System.out.println("Integer Demo");
		int x;
		x=10;
		System.out.println("x is "+x);
		int y=20;
		System.out.println("y is "+y);
		int z=x+y;
		System.out.println("z is "+z);
		int sum;
		System.out.println("wrong value of sum "+x+y+z);
		sum=x+y+z;
		System.out.println("right value of sum "+sum);
	}
}
02. Save it as ex_integer.java Compile the above
03. D:\workarea>javac ex_integer.java Run this program
04. D:\workarea>java ex_integer
05. The output will be
		x is 10
		y is 20
		z is 30
		wrong value of sum 102030
		right value of sum 60
 Chapter 3 : Article 2 : Using of long, double and float types
Short Int Float Double Long
16 bit type 32 bit type 32 bit type 64 bit type 64 bit type
Range from
-32,768 to +32,768
Range from
-2,147,483,648 to +2,147,483,648
Range from
3.4e-038 to 3.4e+038
Range from
1.7e-308 to 1.7e+308
Range Longer than int

class ex_double
{
	public static void main(String args[])
	{
		System.out.println("double, long, float Demo");
		double x;
		x=10.123456;
		System.out.println("x is "+x);
		long y;
		y=300000; //Cannot use decimals in between like 3.5
		System.out.println("y is "+y);
		float z;
		z=12;
		System.out.println("z is "+z); //.0 gets added by itself
	}
}

01. Save the above file as ex_double.java , run and compile
02. The result of above file is
		x is 10.123456
		y is 300000
		z is 12.0
 Chapter 3 : Article 3 : Usage of character type variables

class ex_character
{
	public static void main(String args[])
	{
		System.out.println("character Demo");
		char x;
		x='a';
		System.out.println("x is "+x);
		char y;
		y=65; //Return ASCII equivalent char
		System.out.println("y is "+y);		
	}
}

01. Save the above file as ex_character.java , run and compile
02. The result of above file is
		x is a
		y is A
 Chapter 3 : Article 4 : Usage of String type variables

class ex_string
{
	public static void main(String args[])
	{
		System.out.println("String Demo");
		String fname;
		fname="James";
		String lname="Smith";
		System.out.println("fname is "+fname);		
		System.out.println("lname is "+lname);		
		System.out.println("Full Name is "+fname+" "+lname);		
	}
}

01. Save the above file as ex_string.java , run and compile
02. The result of above file is
		fname is James
		lname is Smith
		Full Name is James Smith
 Next CHAPTER 4 : >> WORLD OF OOPS
 My Dream to be your Friend and Create a Group of Intelligent and Understanding Programmers
     If you like this article and/or code mailme or Join our small Java User Group which is by the Programmers for the Programmers ,
Till we meet next time BYE      Kind Regards - James Smith

  Java, J2EE, J2SE and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc.
in the United States and other countries.