Login


Lost your password?

Don't have an account ? Register ×
  
Java All : Tokens Keywords Identifiers Literals
Concept Learning Code Sheets

Understanding Tokens #3795

Demonstration of a program with presence of different types of tokens.

class AllTokens
{
public static void main(String[] args)
{
int a=10,b=20;
int c=a+b;
System.out.println("a+b="+c);
}
}

Identifier Choices #3798

Making Identifier name choices.

class IdentifierExamples
{
public static void main(String[] args)
{
final int MAX=255;
int ageSum=0;
int lion=12;
int rehsus_monkey=25;
int bigSnake$=25;
int tortoise250=250;
ageSum=lion+rehsus_monkey+bigSnake$+tortoise250;
System.out.println("Average age of animals I chose = "+ageSum/4);
System.out.println("This is about "+((ageSum/4*100)/MAX)+" % of max known 255");
}
}

Integer literals decimal, octal, hexadecimal, binary #3801

Use of integer literals in its different notation forms as decimal form, octal form, hexadecimal form and binary form.

class IntegerLiterals
{
public static void main(String[] args)
{
int a=65;
int b=0101;
int c=0x41;
int d=0b01000001;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
}

Decimal literals float, double #3804

Use of decimal/fractional/real literals in its different size as float and double.

class DecimalLiterals
{
public static void main(String[] args)
{
float a=22.345f;
double b=22.345;
double c=0x22.345P0;
double d=22.345E2;
double e=22.345E-2;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
}
}

Character literals #3808

Use of character literals as direct character assignment, unicode assignment or octal assignment.

class CharLiterals
{
public static void main(String[] args)
{
//single quote form to char type assignment
char cx='A';
char cy='u0041';
char cz='101';
//single quote form to int type assignment
int ix='A';
int iy='u0041';
int iz='101';
//int form to char type assignment
char ca=65;
char cb=0x41;
char cc=0101;
char cd=0b01000001;

System.out.println(cx); System.out.println(cy); System.out.println(cz);
System.out.println(ix); System.out.println(iy); System.out.println(iz);
System.out.println(ca); System.out.println(cb); System.out.println(cc); System.out.println(cd);
}
}

Null Literal #3814

Use of a special case of using null as a literal for nullifying a reference.

class NullLiteral
{
void show()
{
System.out.println("This will print only if object is not null referenced");
}
public static void main(String[] args)
{
NullLiteral ob=new NullLiteral();
ob=null;
ob.show();
int a[]={1,2};
a=null;
a[0]=4;
}
}

String Literals #3818

Use of string literals as chain of normal alphabets, unicode characters, octal characters, escape sequences etc.

class StringLiteral
{
public static void main(String[] args)
{
System.out.println("Hello World!");
String s1="Hello Man!";
String s2="Hello Womanu0021";
String s3="Hello Mankind41";
String s4=""Hello Aliens"";
String s5="HellotGOD";
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
System.out.println(s4);
System.out.println(s5);
}
}

Boolean Literals #3822

Use of boolean 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.");
}
}
Solved Problems

Marking Identifiers in a program #3825

Write down both the programmer defined and java library defined identifiers i

Marking Literals and Its Type in a program #3828

Write down all the literals in the given program and tell its type of literal

Exam Questions
Quizzes

Code Sheets:8  Solved Problems:2  Exam Questons:4  Quizzes:9
Back