Sie sind auf Seite 1von 30

Description of all the Java keywords covered in

the syllabus
Sl. Key Description
No wor
d
1 Byte Represents smallest integer in the range -
128 to 127. Its size in bits is 8
2 Short Represents integer value in the range -
32767 to 32768. Its size in bits is 16.
3 Int Represents integer value in the range -231
to 231-1. It is the default data type in java
among integers. Its size in bits is 32.
4 Long Represents integer value in the range -263
to 263-1. Its size in bits is 64.
5 Float Represents real numbers with fractional
precision in the range -3.4 x 10-38
to 3.4 x 1038. Its size in bits is 32. It is used to
represent single precision numbers.
6 doub Represents real numbers with fractional
le precision in the range -1.7 x 10-308
to 1.7 x 10308. Its size in bits is 64. It is used to
represent double precision numbers.
7 Char Represents characters found in all the
human languages which is called Unicode
in the range 0 to 65, 536. It also represents
standard set of characters known as ASCII
in the range 1 to 127. Its size in bits is 16.
8 boole Represents logical values true and false.
an Java reserves 8 bits, but uses only 1 bit. 1
represents true value and 0 represents
false value.
9 Final Used with variables to represent their
value as constant. It cannot be changed
during the runtime/ compile time of the
program.
10 Void Indicates the method/function doesn’t
return any value.
11 Retur Transfers the control from the method to
n its calling place. It can be used to return
any type of value. It should be the last
statement in the method definition.
12 Static Can be used to declare the data members
and methods. If declared so, the data
members and methods can be accessed
without the help of an object in the same
class. In other class, they can be accessed
using class name and dot operator.
13 This Used to resolve the conflict between the
data members/instance variables and
formal parameters. It refers to the current
object created for the class.
14 New Allocates memory space to all the data
members of the class and initializes to their
default values when no constructor
defined for the class.
15 If Used to make decisions in java.
16 Else Used as alternative to if when the
condition is false.
17 Switc Used to test the value of the given
h variable or expression against a list of case
values.
18 Case To represent labels/constants in a switch
block.
19 defa Gets executed when none of the case
ult labels/constants matches with the input.
20 Brea Used to exit from switch block or loop.
k
21 conti Used to force early iteration in for loop.
nue When used in while and do while block,
the control gets transferred to while
expression.
22 impo To access the classes present in the
rt package.
23 pack To define the user-defined package to
age group similar classes.
24 While It repeats the block of statements while
the expression that controls is true.
25 Do It executes the block of statements, then
checks the while expression.
26 For It is also a looping statement, used mainly
for pre-determined number of iterations.
27 Class It is the fundamental building block of the
Object Oriented Programming. It
encapsulates code(methods/functions) and
data.
28 priva It is used declare the data member and
te member function of a class to be accessed
only by other member methods of the
same class.
29 publi It is used declare the data member and
c member function of a class to be accessed
by other member methods of the same
class/different class within the package as
well as by the classes present in other
packages.
30 prote It is used declare the data member and
cted member function of a class to be accessed
by other member methods of the same
class/different class within the same
package or by the sub class in inheritance
concept.
31 Throw To report user-defined errors during the
runtime of the program
32 throws Informs that error has occurred in an
input/output operation during the
runtime of the program.
33 Try Detects errors during the runtime of the
programs by passing the error message to
exception object in the catch block.
34 Catch Displays the errors detected by the try
block during the runtime.

Description of all the inbuilt methods/functions


covered in the syllabus
Sl. Method Description Example
No Name
1 void print Displays the System.out.print(10
(any type of output and );
value) the cursor System.out.print(12
remains in the .3);
same line. System.out.print('a'
);
System.out.print("
Hello ");
2 void println Displays the System.out.println(
(any type of output and 10);
value) the cursor System.out.println(
comes to the 12.3);
next line. System.out.println('
a');
System.out.println(
"Hello ");
3 double Returns the Math.sin(Math.toR
sin(radian sine value of adians(45));
value) the argument
as radian.
4 double Returns the Math.cos(Math.toR
cos(radian cosine value adians(45));
value) of the
argument as
radian.
5 double Returns the Math.tan(Math.to
tan(radian tan value of Radians(45));
value) the argument
as radian.
6 double Returns the Math.log10(3)
log10(any logarithmic
type value of the
numerical argument.
value)
7 int/float/doubl Returns the Math.abs(-5);
e absolute Math.abs(-5.5f);
value of the Math.abs(-
abs(int/float/d argument. 123.456);
ouble)
8 int/float/doubl Returns the Math.max(1,4);
e/char maximum Math.max(1.2f,8.6f)
value among ;
max(arg1, the Math.max(45.6,
arg2) arguments. 89.90);
Math.max('a','A');
9 int/float/doubl Returns the Math.min(1,4);
e/char maximum Math.min(1.2f,8.6f);
value among Math.min(45.6,
min(arg1, the 89.90);
arg2) arguments. Math.min('a','A');
10 double Returns the Math.sqrt(4);
sqrt(int/float/d square root Math.sqrt(25.0f);
ouble) value of the Math.sqrt(625.0);
argument.
11 double Returns the Math.pow(1,2);
pow(arg1, value of arg1 Math.pow(1.2f,3.4f)
arg2) raised to arg2 ;
Math.pow(2.3,4.5);
Math.pow('a', 2);
//finds 972
12 double Returns the Math.ceil(4); //4.0
ceil(int/float/d value greater Math.ceil(4.2f);
ouble) than or equal //5.0
to the Math.ceil(5.0);
argument. //5.0
Math.ceil(5.3); //6.0
Math.ceil(-1.2); //-
1.0
13 double Returns the Math.floor(4); //4.0
floor(int/float/ value lesser Math.floor(4.2f);
double) than or equal //4.0
to the Math.floor(5.0);
argument. //5.0
Math.floor(5.3);
//5.0
Math.floor(-1.2);
//2.0
14 double Returns a Math,random();
random() random //0.3
number (int)Math.random(
between )*10; // returns any
0(inclusive) number in the
and range 0 to 9
1(exclusive)
15 int/long Returns the Math.round(5.6f);
round(float/do rounded //6
uble) value of a Math.round(4.5);
number from //5
.5 and above.

16 double Returns the Math.rint(1.0);//1.0


rint(int/float/d value closest Math.rint(1.4); //1.0
ouble) to the Math.rint(1.5); //2.0
argument Math.rint(2.2);
passed. If it is //2.0
odd number, Math.rint(2.5);
then it will //2.0
round .5 and Math.rint(2.6);
above to the //3.0
next number.
If it is even
number, then
it will round .6
and above to
the next
number.
17 int length() Returns the String s="Java
total no. of program";
characters int L=s.length(); //12
present in the
string object
including
space.
18 char Returns the String s="Java
charAt(int) character at program";
the char c=s.charAt(2);
corresponding //v
index position. char
If the index c1=s.charAt(s.length
position is not ());
found, then it //Error
raises a run- char
time error c2=s.charAt(s.lengt
StringIndexOu h()-1);
tOfBounds // m
Exception.
19 int Returns the String s="Java
indexOf(char/s first program";
tring) occurrence of int i1=s.indexOf('a');
the character //1
or string int
present in the i2=s.indexOf('A');//-
string object. 1
If the int
character/strin i3=s.indexOf("va");
g is not found //2
then it
displays the
index position
as -1 by
default.
20 int Returns the String s="Java
indexOf(char/s first program";
tring, occurrence of int i1=s.indexOf('a',
the character 3);//3 Searches for
int) or string 'a' from 3rd index
present in the onwards, since it is
string object present at 3rd index
from the itself, it will return
specified the same index
staring index number.
by the user.
21 int Returns the String s="Java
lastIndexOf(ch last program";
ar/string) occurrence of int
the character i1=s.lastIndexOf('a');
or string //10
present in the
string object.
22 boolean Checks String s="Java
startsWith(stri whether the program";
ng) string starts boolean
with the b=s.startsWith("J");
specified //true
string boolean
argument b1=s.startsWith("Jav
and returns "); //true
true/false Boolean
b3=s.startsWith("j");
//false
23 boolean Checks String s="Java
endsWith(strin whether the program";
g) string ends boolean
with the b=s.endsWith("m");
specified //true
string boolean
argument b1=s.startsWith("ra
and returns m"); //true
true/false boolean
b3=s.startsWith("Ra
m"); //false
24 boolean Checks the String s1="Java";
equals(string) equality String s2="Java";
between boolean
calling string b=s1.equals(s2);
and //true
argument Here s1 is calling
string and string, and s2 is
returns true if argument string.
they are
exactly
matching
with the case
of characters,
otherwise
false.
25 boolean Checks the String s1="Java";
equalsIgnoreC equality String s2="JAVA";
ase(string) between boolean
calling string b=s1.equalsIgnoreC
and ase(s2); //true
argument Here s1 is calling
string by string, and s2 is
ignoring the argument string.
case of
characters
and returns
true if they
are having
same
characters,
otherwise
false.
26 String Returns the String s1="convert";
toUpperCase() string in s1=s1.toUpperCase()
uppercase by ;
converting
lowercase //CONVERT
characters to
uppercase.
27 String Returns the String
toLowerCase() string in s1="CONVERT";
Lowercase by s1=s1.toLowerCase()
converting ;
uppercase
characters to //convert
lowercase.
28 String Returns the String
replace(char,c string after s1="babbage";
har) replacing all s1=s1.replace('b','*');
String the // *a**age
replace(string, occurrences of String
string) existing s2="keyboard";
character/strin s2=s2.replace("key",
g with new "Black");
character/strin //Blackboard
g.
29 String Returns the String
substring(int) part of the s1="Computer";
String string from String
substring(int, the specifieds2=s1.substring(3);
int) index //puter
positions. String
s3=s1.substring(3, 7);
//puter
30 String trim() Returns the String s1=" Go to
string after the class ";
removing the s1=s1.trim();
space before //Go to the class
and after the
end of the
string. It does
not remove
space in
between the
string.
31 String Concatenates String s1="St. ";
concat(string) or joins the String s2="Johns";
calling string String
with the string s3=s1.concat(s2);
present as the //St.Johns
argument.
32 int Compares the String s1="Laptop";
compareTo(str calling string String
ing) and s2="Desktop";
argument int
string by c=s1.compareTo(s2)
taking the ;
difference in // subtracts the
ASCII values. ascii value of L and
It returns D and gives the
+ve/-ve/0. If output as positive
+ve then value indicating
calling string is that Laptop is
greater than greater than the
the argument Desktop.
string. If it is –
ve, then
calling string is
lesser than the
argument
string. If 0,
then it
indicates both
the strings are
same.
33 String Returns a int x=12;
toString(numb numerical String
er) string by s1=Integer.toString(
converting x);
numbers to float y=12.3f;
string. String
s2=Float.toString(y
);
double z=12.3;
String
s3=Double.toString
(z);
34 String Returns a int x=12;
valueOf(num numerical String
ber) string by s1=String.valueOf(x
converting );
numbers to float y=1.2f;
string String
s2=String.valueOf(
y);
double z=67.7;
String
s3=String.valueOf(z
);

35 boolean Checks and boolean


isUpperCase(c returns true if b=Character.isUpp
har) the character erCase('D'); // true
is upper case,
otherwise
false.
36 boolean Checks and boolean
isLowerCase(c returns true if b=Character.isLow
har) the character erCase('a'); // true
is lower case,
otherwise
false.
37 boolean Checks and boolean
isDigit(char) returns true if b=Character.isDigit
the character ('5'); // true
is digit,
otherwise
false.
38 boolean Checks and boolean
isLetter(char) returns true if b=Character.isLett
the character er('D'); // true
is an
alphabet,
otherwise
false.
39 boolean Checks and boolean
isLetterOrDigit returns true if b=Character.isLett
(char) the character erOrDigit('a'); //
is true
alphabet/digi b=Character.isLett
t, otherwise erOrDigit('3');//true
false.
40 boolean Checks and boolean
isWhitespace(c returns true if b=Character.isUpp
har) the character erCase('D'); // true
is upper case,
otherwise
false.
41 char Converts the char
toUpperCase( character c1=Character.toUp
char) from perCase('a'); //A
lowercase to char
uppercase. c2=Character.toUp
perCase('B'); //B
char
c3=Character.toUp
perCase('$');
// $
42 char Converts the char
toLowerCase(c character c1=Character.toLo
har) from werCase('A'); //a
uppercase to char
lowercase. c2=Character.toLo
werCase('b'); //b
char
c3=Character.toLo
werCase('$');
// $
43 byte Converts the String s1="12";
parseByte(nu numerical byte
mber as string to byte b=Byte.parseByte(s
string) type. 1); [or]
byte
b=Byte.valueOf(s1);
44 short Converts the String s1="123";
parseShort(nu numerical short
mber as string to short s=Short.parseShort(
string) type. s1); [or]
short
s=Short.valueOf(s1);
45 int Converts the String s1="123";
parseInt(num numerical int
ber as string) string to int a=Integer.parseInt(
type. s1);
[or] int
a=Integer.valueOf(
s1);
46 long Converts the String s1="123";
parseLong(nu numerical long
mber as string to long a=Long.parseLong(
string) type. s1);
[or] long
a=Long.valueOf(s1)
;
47 float Converts the String s1="123.4";
parseFloat(nu numerical float
mber as string to float a=Float.parseFloat
string) type. (s1);
[or]float
a=Float.valueOf(s1)
;
48 double Converts the String s1="123.56";
parseDouble(n numerical double
umber as string to a=Double.parseDo
string) double type. uble(s1);
[or]
double
a=Double.valueOf(
s1);

49 boolean Converts the String s1="true";


parseBoolean( numerical boolean
boolean value string as a=Boolean.parseBo
as string) true/false toolean(s1);
boolean type.[or]
boolean
a=Boolean.valueOf
(s1);
50 char Reads a System.out.println(
(char)br.read( character "Enter a
) given as input character");
by the user. char
c=(char)br.read();

51 String Reads a string System.out.println(


br.readLine() given as input "Enter a string");
by the user. String
s=br.readLine();

52 System.arrayc Copies the int


opy(source_ar elements x[]={1,2,3,4,5,6,7,8,9
ray, specified from ,10};
Source_index, the source int y[]=new int[5];
Destination_ar array to System.arraycopy(
ray, destination x,0, y, 0, 5);
Destination_in array. In the above
dex, No. of example, from the
elements to be source array x[]
copied) from 0th index
copies 5 elements
into destination
array y[] from 0th
index.
53 char Converts the String s="Hello";
toCharArray() string to an char
array of ch[]=s.toCharArray
characters. ();
for(int
i=0;i<ch.length;i++)
System.out.println(
ch[i]);
54 int nextInt() Reads the Scanner s=new
token from Scanner(System.in)
the scanner ;
object as System.out.println(
integer. "Enter an integer
value");
int x=s.nextInt();
55 float Reads the Scanner s=new
nextFloat() token from Scanner(System.in)
the scanner ;
object as System.out.println(
float. "Enter an float
value");
float
x=s.nextFloat();
56 double Reads the Scanner s=new
nextDouble() token from Scanner(System.in)
the scanner ;
object as System.out.println(
double. "Enter an double
value");
double
x=s.nextDouble();
57 long Reads the Scanner s=new
nextLong() token from Scanner(System.in)
the scanner ;
object as long System.out.println(
integer. "Enter an long
value");
long
x=s.nextLong();
58 String next() Reads a string Scanner s=new
token from a Scanner(System.in)
scanner object ;
till it finds first System.out.println(
space "Enter a string");
character.It String x=s.next();
means it
reads only
one word
from the
user’s input.
59 String Reads a string Scanner s=new
nextLine() token from Scanner(System.in)
scanner object ;
till the user System.out.println(
press enter "Enter a string");
key. It means String
it reads more x=s.nextLine();
than one
word from
the user’s
input.
60 boolean Checks the Scanner s=new
hasNextInt() availability of Scanner("3 4");
integer token boolean
in the scanner b=s.hasNextInt();
object. true
Likewise there are
other methods:
hasNextFloat(),
hasNextDouble(),
hasNextLong(),
hasNext(),
hasNextLine()

Inbuilt packages and classes covered in the


syllabus
import java.lang.*;
* indicates the following classes: System, String, Math,
Integer, Float, Double, Long, Byte,
Short, Character, Boolean. The methods/ functions of
these classes were given in the
table.
import java.io.*;
* indicates the following classes: InputStreamReader,
BufferedReader
import java.util.*; only Scanner class according to the
syllabus.
Common Syntax Errors with their description
Sl.No Example Error
Name
1 int a=10 Statement
missing ;
2 int a=1, a=1; Multiple
declarations
for a
3 int x=12.3; Possible loss
of precision.
Required int
found
double
4 int x; Variable x
System.out.println(x); might not
have been
initialized.
5 if(a>b); else without
System.out.println(a); if because if
else condition is
System.out.println(b); terminated
by
semicolon.
6 System.out.println(a); Cannot find
symbol a
7 Class sample Class or
{ interface
void display() { int expected
x=10; } } because the
keyword
class is
written as
Class
8. system.out.println(10); Package
system does
not exist.
9 String s="Hello; Unclosed
String literal.
10 class Sample Expected {
void display(){ } }
11 Display() Invalid
method
declaration,
return type
required.
Common Runtime error or exceptions
Sl. Example Error Name
No
1 int x=10, y=0; ArithmeticException-
int z=x/y; Divide By Zero. A
System.out.println(z); Number cannot be
divided by zero.
2 System.out.println("Enter During the execution,
an integer"); if the user enter any
int other value other than
a=Integer.parseInt(br.rea integer, then it raises
dLine()); the error as
NumberFormatExcept
ion
3 String s="Code"; StringIndexOutOfBou
System.out.println(s.char nds, because accessing
At(s.length()); the character at the
index position which is
beyond the range.
Example: "Code" there
are 4 characters in it.
The index ranges from
0 to 3. But s.length()
gives the value as 4 in
which this index
number is not found.
4 int x[]={1,2,3,4}; ArrayIndexOutOfBoun
System.out.println(x[4]); dsException because
accessing the array
element at 4th index
which is not found.
5 In Scanner Class: During the execution,
System.out.println("Enter if the user enter any
an integer"); other value other than
int a=sc.nextInt(); integer, then it raises
the error as
InputMismatchExcepti
on
Syntax of all the concepts covered in the
syllabus
Sl. Concept Syntax [or] General Form
No
1 Single line //……………………………..
comment
2 Multiple line /*…………………..
comment …………………….. */
3 Documentation /**………………………….
comment …………………………………
…………………………*/
4 Class definition Class classname
{
data members;
constructors
member methods
}

5 Method Access-specifier modifier


definition returntype
methodname(parameter list)
{
statements;
}
6 Method Access-specifier modifier
prototype returntype
methodname(parameter list)

7 Default public classname()


constructor {
statements;
}
8 Parameterized public classname(parameter
constructor list)
{
statements;
}
9 Variable Datatype variablename;
declaration
10 Multiple Datatype variable1,
variable variable2,……………variable
declaration
11 Variable Datatype variable;
initialization variable=value;
[or]
Datatype variable=value;
12 Multiple Datatype variable1,
variable variabl2,……………..;
initialization Variable1=value;
Variable2=value;
.
.
.
Variable=value;
13 Prefix or --var;
preincrement ++var;
and
predecrement
14 Postfix or Var--;
postincrement Var++;
and
postdecrement
15 if statement if(condition)
{
statements;
}
16 if else statement if(condition)
{
statements;
}
else
{
Statement;
}

17 Nested if if(condition)
statement {
if(Condition)
statements;
}
18 if…else if if(condition)
statement {
statements;
}
else if(condition)
{
statements;
}
.
.
else
{
statements;
}
19 switch switch(expression)
statement {
case label1:
statements;
break;
.
.
.
case labeln:
statements;
break;
default:
statement;
}
20 Ternary Var=expression1?expression2:ex
Operator pression3;
21 while statement while(expression)
{
statements;
}
22 do while do
statement {
statements;
}while(expression);
23 for statement for(initialization; condition;
updation)
{
statements;
}
24 Nested while while(expression)
statement {
while(expression)
{
statements;
}
}
25 Nested do while do
statement {
do
{
statements;
}while(expression);
}while(expression);

26 Nested for for(initialization; condition;


statement updation)
{
for(initialization; condition;
updation)
{
statements; } }
27 Creating an classname objectname=new
object classname();
28 Accessing non- Objectname.datamember;
static Objectname.methodname();
datamembers/
member
function in a
static function
within the same
class/outside the
class.
29 Accessing static classname.datamember;
datamembers/ classname.methodname();
member
function in a
static function
utside the class
30 Explicit Type Var=(datatype)(var or
conversion or expression);
Typecasting
31 Calling objectname.functionname(arg
method/functio uments)
n
32 Calling classname objectname=new
constructor classname(arguments);
function
33 Creating a new package package-name;
package class classname
{
definition
}
34 Importing single import
class from the packagename.classname;
package
35 Importing single import
class from the packagename.subpackagena
sub-package me.classname;
36 Importing all import packagename.*;
classes from the
package
37 Importing all import
classes from the packagename.subpackagena
sub-package me.classname;
38 Putting try
statements in a {
try block where statements;
error might }
occur during the catch(Exceptionname object)
runtime {
followed by statements;
catch block to }
report the error
39 private/public private datatype variable;
declaration of public datatype variable;
datamembers
40 static static datatype variable;
datamember
declaration
41 Array datatype arrayname[ ]; or
declaration datatype [ ]arrayname;
42 Array datatype
initialization arrayname[]={v1,v2,……………vn}
;
43 Finding length Var=Arrayname.length;
of an array
44 Array creation datatype arrayname[]=new
or memory datatype[size];
allocation
45 Accessing array Var=arrayname[index value];
element

Apart from the above list, the syntax of various inbuilt


methods is presented in tabular form under the
heading “Description of all the inbuilt
methods/functions”
Note: Along with these, learn all the definitions,
differences, uses of operators covered in
the syllabus.
Also Learn all the standard number logics like prime
number, palindrome number, Armstrong number,
super number, Fibonacci series, twin-prime, factorial,
etc.,
Scientific notation of a number:
Floating point constants can be represented in two
ways: Standard and Scientific.
Scientific/ Exponential notation: This way is used to
represent numbers as mantissa e/E exponent part.
Mantissa is either a real number expressed in decimal
notation or an integer. The exponent is an integer with
an optional +/- sign. E2 means 102
For ex:6.022E23 or 6.022e23 is equivalent
to 6.022×1023,
and 1.6×10−35 would be written 1.6e-35
Important Note:
Learn Precedence of Operators and Associativity from
text book.
Learn Dangling else and fall through condition.
Learn definition and examples for empty and infinite
loop.
Learn static or early binding.
Instantiation,
Default values given by the default constructor to the
following datatype:
Data type Value
int/byte/short 0
double 0.0
float 0.0f
String null
boolean false
char ‘\u0000’(null character)

Compound Statement: Group of statements enclosed


within a block are called as compound statement.

Das könnte Ihnen auch gefallen