Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
Java: All Recent Posts Grouped
Concept Learning Code Sheets View all
Resolving Class and Local Variable Name Clash #3871  (20-Mar-2018)
In Topic(s) : Data Types Variables and Constants   


class VariableNameClash
{
static int x=10;
public static void main(String[] args)
{
int x=20;
System.out.println(x);
//System.out.println(this.x);
System.out.println(VariableNameClash.x);
}
}

Methods to rightly use variable names when their names clash between class/static types and local types.


Variable Default Values #3867  (20-Mar-2018)
In Topic(s) : Data Types Variables and Constants   

class VarDefaultValues
{
static byte b;
static short s;
static int i;
static long l;
static char c;
static double d;
static float f;
static boolean bool;
public static void main(String[] args)
{
System.out.println("Default value of byte "+b);
System.out.println("Default value of short "+s);
System.out.println("Default value of int "+i);
System.out.println("Default value of long "+l);
System.out.println("Default value of char "+c);
System.out.println("Default value of double "+d);
System.out.println("Default value of float "+f);
System.out.println("Default value of boolean "+bool);
}
}

Java class variables have default values. Let us experiment with that.


Variable Kinds – Local, Class and Instance Variables #3865  (20-Mar-2018)
In Topic(s) : Data Types Variables and Constants   

class VarKinds
{
static int x=1;
int y=2;
public static void main(String[] args)
{
int z=3;
VarKinds ob=new VarKinds();
System.out.println(x);
System.out.println(ob.y);
System.out.println(z);
}
}

Mainly used kinds Local, Class and Instance Variables are discussed here.


Variable Declaration and Initialisation #3862  (20-Mar-2018)
In Topic(s) : Data Types Variables and Constants   

class VarDecInit
{
public static void main(String[] args)
{
int x;
x=10;
int y=20;
int z=y;
double d=Math.pow(2,3);
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println(d);
}
}

Variable declaration and initialisation varieties are explained here.


Understanding Reference data type #3859  (20-Mar-2018)
In Topic(s) : Data Types Variables and Constants   

class RefDataType
{
int rd=5;
public static void main(String[] args)
{
RefDataType robj = new RefDataType();
System.out.println(robj.rd);
int ar[]={1,2};
System.out.println(ar);
System.out.println(ar[0]+", "+ar[1]);
}
}

Reference data type for class object reference and array reference.


Understanding boolean data type #3850  (19-Mar-2018)
In Topic(s) : Data Types Variables and Constants   

class BooleanType
{
public static void main(String[] args)
{
boolean b=true;
//int x=b;
if(b) System.out.println(b);
if(b==true) System.out.println(b);
}
}

The java boolean data type declaration and its features.


Understanding char data type #3848  (19-Mar-2018)
In Topic(s) : Data Types Variables and Constants   


class CharType
{
public static void main(String[] args)
{
char a=0;
char b=10;
char c=33;
char d=65;
char e=126;
char f=255;
char g=65535;
char h='a';
char i='u03C0';
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);
System.out.println(g);
System.out.println(h);
System.out.println(i);
}
}

The java char data type and its possible values are explained here.


Understanding byte, short, int and long types #3846  (19-Mar-2018)
In Topic(s) : Data Types Variables and Constants   

class IntTypes
{
public static void main(String[] args)
{
byte bp=127;
byte bn=-128;
short sp=32767;
short sn=-32768;
int ip=2147483647;
int in=-2147483648;
long lp=9223372036854775807L;
long ln=-9223372036854775808L;
System.out.println("Largest byte type value = "+bp);
System.out.println("Smallest byte type value = "+bn);
System.out.println("Largest short type value = "+sp);;
System.out.println("Smallest short type value = "+sn);;
System.out.println("Largest int type value = "+ip);;
System.out.println("Smallest int type value = "+in);;
System.out.println("Largest long type value = "+lp);
System.out.println("Smallest long type value = "+ln);;
}
}

Different types of integer data types with its maximum and minimum value limits are explained with this code.


Understanding double and float data type #3840  (19-Mar-2018)
In Topic(s) : Data Types Variables and Constants   

class DoubleFloat
{
public static void main(String[] args)
{
Double x=2342.34567;
float y=2342.34567f;
System.out.println(x);
System.out.println(y);
Double X=x;
Float Y=y;
System.out.println("Double type max value = "+X.MAX_VALUE);
System.out.println("Float type max value = "+Y.MAX_VALUE);
System.out.println("Double type size = "+X.SIZE);
System.out.println("Float type size = "+Y.SIZE);
}
}

Double and float data type declaration its max value and sizing.


Boolean Literals #3822  (13-Mar-2018)
In Topic(s) : Tokens Keywords Identifiers Literals   

class BooleanLiterals
{
public static void main(String[] args)
{
boolean pass=true;
boolean topper=false;
if(pass)
System.out.println("You have successfully cleared the exams.");
if(topper)
System.out.println("Congrats for being the topper");
else
System.out.println("With a little more effort you can even become a topper.");
}
}

Use of boolean literals.


Solved ProblemsView all



Data type selection #3873 (21-Mar-2018)
In Topic(s) : Data Types Variables and Constants   

Write a program to initialise a variable with price of an item as a fractional value. Then prepare another variable to output the price multiplied with 100 so that its lowest currency denomination (LCD) value is achieved. Print the LCD price with a suitable message. Choose appropriate variable names and data types.

Write a program to initialise a variable with price of an item as a fractiona








Concept Notes and ResourcesView all







Back