Вы находитесь на странице: 1из 25

float double

It is single precision 32bit It is double precision 64 bit


Default value 0.0f Default value 0.0d

Single Dimensional Array Double Dimensional Array


It is represented along X axis It is represented along X and Y
axis
It is also called single subscripted It is also called double
variable. subscripted variable.
The variables with same name The variables with same name
have single subscript. have two types of subscript
representing row and column
number.

If..else switch
It can perform all relational It can perform only ==
comparisons comparison
It works with any data type It works with byte, short, char, int
primitive data type
It executes a certain section of It can have a number of possible
code only if a particular test execution paths
evaluates to true

Bubble Sort Selection sort


It does sorting by essentially It performs the sorting by
exchanging the elements. selecting the element.
It is a stable algorithm. It is unstable algorithm.

== equals()
It is used to check the equality This function checks the equality
between primitive datatype. between the strings.

Formal parameter Actual parameter


The parameter present in function The parameter present in the
prototype is called formal function call statement is called
parameter. actual parameter.
It stores the duplicate value. It stores the original value

Primitive datatype Composite datatype


Fundamental datatype. Constructed using primitive
datatype
Size is fixed. Size depends on the member
variables
It is passed by value It is passed by reference.
e.g. int, char, double e.g. class, arrays, interface

/ %
It is a division operator It is modulus operator
It gives quotient It gives the remainder

Constructor Function
It has no return type, not even void It has void or a valid return data
type.
It has 2 types: default and It has 2 types: call by value and
parameterized call by reference.
It is invoked automatically when It must be called by using object
object of class is created. of the class or directly.
It is a function having same name It is always defined by any name
as class name. except keyword.

next() nextLine()
Accept a string without any space. Accepts a string with the space.
It terminates the input of
characters when a space is met.

Searching Sorting
To find an element in an array is To arrange the elements in an
called searching. order is called sorting.

isUpperCase() toUpperCase()
Return type is boolean Return type is char
Checks whether a given character Converts the character to its
is an uppercase letter or not upper case.

While do..while
Entry controlled loop Exit controlled loop
Minimum repetition is 0 Minimum repetition is 1
If condition is false in the Loop will execute at least once
beginning , loop never executes. even if the condition is false.

length length()
It is used to find the length of an It is used to find the length of a
array. string.
Eg. int a[] = new int[10]; Eg. String s = “ABC”;
int l = a.length; int l = s.length();

Unary Operator Binary Operator


Operators that operate on single Operators that operate on two
operand are called unary operator operands is called binary
operator.
Eg. ++, -- Eg. +, -, /, %, *

Character literal String literal


It is enclosed within single quotes It is enclosed within double
quotes

= ==
It is an assignment operator It is a relational operator
It is used to assign a value to a It is used to check the equality
variable between primitive datatype.

Base/Super class Derived/Sub class


It is the class which is inherited by It is the one which inherits the
another class base class

SOP() SOPln()
After printing , the cursor remains After printing cursor goes to the
on the same line. next line.
Eg. SOP(“India”); Eg. SOPln(“India”);
SOP(“ is my country”); SOPln(“ is my country”);
Output: India is my country Output: India
is my country

Pure Arithmetic Expression Mixed/Impure Arithmetic


expression
An arithmetic expression that An arithmetic expression that
contains the same type of data contains the different type of data
items (variables or constants) is items (variables or constants) is
called pure arithmetic called impure arithmetic
expression. expression.
Eg.int a, b,c; Eg.int a; float b; double c,x;
C= a+b*2; c= a+b*x;

Arithmetic Expression Arithmetic Statement


It may contain variables, constants If arithmetic expression is
and arithmetical operators to assigned to a variable then it is
produce a meaningful result. known as a arithmetic statement
Eg:x+y Eg. z= x+y;

Prefix Postfix
When increment or decrement When increment or decrement
operators are applied before the operators are applied after the
operand , they are called prefix operand , they are called postfix
operators. operators.

The value of the variable changes The value of the variable changes
before the operation takes place. after the operation takes place.
It works on the principle of It works on the principle of
“change before action” “change after action”

Linear Search Binary Search


It works on both sorted and It works only on sorted array
unsorted array
Search begins at the start of the Array is divided into 2 halves and
array i.e. 0th position then the desired item is searched
in either half.

nextInt() hasNextInt()
Return type is int Return type is boolean
It receives the next token as an It checks whether the next token in
integer from the scanner object the scanner object can be
interpreted as an int value

Pure Function Impure Function


A function which returns a value It may not return a value
to its caller module is called pure
function
It doesn’t change the state of an It changes the state of an object
object during call.
It is also called accesser method It is also called Mutator

Source code Object code


It is the source of a program , the It is the machine executable file
original file which is written by the having instructions for the
programmer.It is served as an machine in the form of binary
input to the compiler. digits, generated by the compiler.

Boolean boolean
It is a wrapper class of the It is a primitive datatype
primitive datatype boolean

Testing Debugging
It is a process in which a program is It is a process in which the errors
validated. in the program are removed.
It is complete when all desired It is finished when there are no
verifications against specifications errors and the program is ready
have been performed. for execution.

break Continue
It is used for unusual termination It is opposite of break. As soon as
of loop. As soon as break is continue is executed , the control
encountered, the control exits skips the rest of the statements
from the loop. and goes for the next iteration.

throw throws
It is applied within a function It is used along with function
signature
It is used to handle a specific It maybe used to eliminate
exception multiple exceptions
It is used for explicit elimination of It is used to declare an exception
an exception

Instance variable Class variable


It is declared without static It is declared with static keyword
keyword
They are individual copies of each They are a common copy for
object each object.

Private Protected
Private elements are not shared They can be applied to the
by another class during derived class at the time of
inheritance. inheritance.
They are not accessed outside the They are used in the class as
class. private members which can be
applied within the class.

Object Class
It is an instance of a class. It is a blueprint or a template from
which objects are created.
It is created through new It is declared using keyword class.
keyword. E.g. Xyz obj =new Xyz(); E.g. class Xyz{ }
It is real and unique entity having It is a representation of an
some characteristics and abstraction only.
behaviours.

Call by value Call by reference


Formal parameters are copies of Formal parameters contain the
actual parameters. reference of the actual
parameters.
Primitive data types are passed Composite data type are passed
by value by reference.
Changes made in formal Changes made to the formal
parameters are not reflected in parameter are automatically
the actual parameter. reflected back in the actual
parameter.

equals() compareTo()
Return datatype is boolean Return datatype is int
It only compares 2 strings and It also gives whether the first string
gives whether they are equal or is greater or smaller than the
not second one.

Name the following


1. Mathematical function which is used to find sine of an angle given in
radians—sin()
2. String function which removes the blank spaces provided in the
prefix and suffix of a string—trim()
3. Keyword which is used to resolve the conflict between method
parameter and instance variables.—this
4. Keyword used to call a package in the program – import
5. Any one reference data type—class, array, String, interface
6. Package that contains wrapper class - lang
7. Method that converts String to primitive float datatype – parseFloat()
8. Method that determines if specified character is an uppercase
character –isUpperCase()
9. Value that a boolean variable return – true / false
10.Size in bits of a char type variable – 16
11.Used to join more than one relational operator - logical operator
12.Alternative to if..else statement—switch
13.Keyword that causes the control to transfer back to method call –
return
14.Keyword that stores the address of currently calling object – this
15.Character set used in java – Unicode
16.Smallest individual unit in java – token
17.Keyword used to allocate memory space to reference data types –
new
18.OOP principle that allows a class to derive properties from another
class.--- Inheritance
19.Unexpected error occurring during program execution –Runtime
error
20.Collection of variables of same type that are referenced by common
name – array
21.A method having same name as class –constructor
22.They represent non- graphic characters – escape sequence
23.An interpreter that converts byte code to machine language – JVM
24.Full form of JVM – Java Virtual machine
25.An instance of a class – object
26.Operators that act on one operand – unary operator
27.Keyword that makes a variable act as a constant – final
28.OOP principle that is implemented through function overloading –
polymorphism
29.Group of classes- package
30.Reserved words in java – keywords
31.Keyword used in inheritance – extends
32.Keyword that indicates that method has no return type - void
33.Function to close the scanner – close()
34.Exception thrown by method nextInt() – InputMismatchException
35.Exception thrown by method next()- NoSuchElementException
36.Package that is invoked by default – java.lang
37.keyword to use the classes defined in a package—import
38.Default initial value of boolean variable data type – false
39.keyword that distinguishes between class variable and instance
variable – static
40.keyword that informs that an error has occurred in an input/output
operation - throws
41.java concept that is implemented through superclass and subclass –
Inheritance
42.unit of class that gets called, when object of the class is created -
constructor
43.ascii code of blank – 32
44.the techniques that can be used to concatenate the elements of two
different arrays into a single array.--- Merging

Escape Sequences Non-graphic character


\t Horizontal tab
\v Vertical tab
\\ Backslash
\’ Single quote
\” Double quote
\b Backspace
\f Form feed
\0 Null
\r Carriage return
\n New line feed

Data type Default initial value


Int 0
Float 0.0f
Double 0.0d
String “”
Boolean false
Char ‘\u0000’

Datatype Size in bits


byte 8
char 16
short 16
int 32
float 32
long 64
double 64

Primitive Datatype Wrapper class


char Character
byte Byte
short Short
int Integer
long Long
boolean Boolean
float Float
double Double

Function Class to Argument/Parameter Return


which the that the function datatype of
function takes the
belongs function
parseInt() Integer String int
parseLong() Long String long
parseFloat() Float String float
parseDouble() Double String double

Function Class to Argument/Parameter Return


which the that the function datatype
function takes of the
belongs function
isLetter() Character Char boolean
isDigit() Character Char boolean
isLetterOrDigit() Character Char boolean
isWhitespace() Character Char boolean
isUpperCase() Character Char boolean
isLowerCase() Character Char boolean
toUpperCase() Character Char char
toLowerCase() Character Char char

Function Class of Argument Return


the /parameter type of
function passed to the
the function function
length() String - int
charAt() String int char
indexOf() String char int
lastIndexOf() String char int
substring String int String
toLowerCase() String - String
toUpperCase() String - String
concat() String String String
equals() String String boolean
equalsIgnoreCase() String String boolean
compareTo() String String int
compareToIgnoreCase() String String int
trim() String - String
endsWith() String String boolean
startsWith() String String boolean

What is an infinite loop?


A sequence of instructions which loops endlessly.

What is constructor ? When is it invoked ?


A constructor is a member function of a class that has same name as
class and initializes data member of a class.
It is invoked at the time of object creation.

What are identifiers ?


An identifier is a sequence of characters used to name variables,
methods, classes, packages and interfaces.

What is JDK ? What is its purpose ?


The Java Develpoment Kit (JDK) is a software development environment
used for developing java applications and applets. It includes the
JRE(Java Runtime Environment), a compiler(javac), an archiver(jar),
interpreter, document generator and other tools needed in java
development.

Define Encapsulation?

The wrapping up of data and functions (that operate on the data)into a


single unit(called class) is called encapsulation.

What are keywords? Give an example

They are the words that convey a special meaning to the language
compiler. These are reserved for special purpose and must not be
used as normal identifiers. Ex. Public, int, else

What is a parameterized constructor?

Constructors that take arguments are called parameterized constructors.

What is inheritance?

It is the process by which one object acquires the properties of another


object
Define abstraction ?

The act of representing essential features and hide unnecessary or


background details is called abstraction.

What are seperators ? Give example

They are special characters in java ,which is used to separate variables or


characters. Eg. brackets ( , ), curly brackets { , } , square brackets [,]
etc

What is recursive function ?

A function which calls itself in its body is called recursive function.

Define Compound statement

It is a statement that includes multiple statements under curly brackets.eg:


if..else, for, while etc..

Define null loop OR empty loop

A for statement which doesn’t include any statement in the body of the
loop is called null loop or empty loop.

Eg:for(inti=1; i<=10; i++);

Define Static data member

It is an instance variable which is global in the class and is commonly used


by all the objects of that class.

Define Static member method

It is a member method which uses only static data members

What is function overloading ?

It is the process of defining functions with the same name but with
different number and types of parameters.

Define local variable


It is a variable that is accessible only from the function or the block in which
it is declared.

What are protected access specifier.

They are used in the class as private members which can only be used
within the class but can be applied to another class during
inheritance.

What is copy constructor

It is used to copy the initial values of the instance variables of an object to


the instance variables of another object.

What is constructor overloading ?

A process of using a number of constructors with the same name but


different types of parameters list is called constructor overloading.

Eg. class xyz{ int a;

Xyz()

{ a=0;}

Xyz(int s)

{ a =s;}

Define Multiple Inheritance

When a sub class inherits from multiple base classes, it is called multiple
inheritance.

Define Single Inheritance

If a base class is derived by a single target then it is called single


inheritance.

Define Hierarchical Inheritance


When many targets inherit from a single base class , it is called hierarchical
inheritance.

Define Multilevel Inheritance

A target which inherits a base class can be in turn used as a base for
another target. Such system is called Multilevel inheritance.

Define Hybrid Inheritance

When more than one type of Inheritance systems are used together, it is
called Hybrid Inheritance.

What is Dynamic Binding

It is the process that links the function call with function signature at run-
time.

What is function prototype OR function header?

It is the first line of the function which contains its access specifier, return
type, function name, and list of parameters(number, type and order).
e.g. public int Add(int m, int n)

What is function signature?

It is the method name along with the number, type and order of its
parameters. E.g. factorial(int)

How functions are distinguished during function overloading ?

The functions should have either different number of parameters, or the


data types of the parameters should be different.

What is static Binding ?

Linking a function with its caller program at the time of creating program
logic is called static binding.

Define Instance Variable

It is a variable present in every instance(object) of the class. They represent


the state of the object.
Explain type casting

It is the explicit conversion of one datatype into another using the typecast
operator()

Define Byte code

It is an intermediary binary form of java source code that is obtained after


getting converted with the help of java compiler.It is machine
independent and makes program highly portable.

What is an exception ?
It is an event that occurs during the execution of a program that
disrupts the normal flow of instructions.

What are library classes ? Give example.

Library classes are the predefined classes which are a part of Java API. E.g.
String, Scanner

What is an array ?

An array is a group or collection of values of a similar datatype.

What is meant by precedence of operators ?


The order in which the operators are applied to the operands in an
expression is called precedence of operators. E.g.
5+10/2
5+5
10

What is a literal ?

It is a constant data item. There are different literals like ‘A’ which is
character literal, false which is Boolean literal etc.

Define object using an example


It is an instance of a class. E.g. If we have a class dog, then a dog named
tommy can be said to be an object of the class.

Define variable ?
It is a named memory location , which holds a data value of a particular
data type. Eg double p;

What is a wrapper class ? Give eg


It wraps a primitive data type into an object. E.g. Boolean, Character

Define impure function ?


They are those functions which changes the state of an object.

What is meant by private visibility of a method ?


IT means that the method cannot be accessed outside the class.

What is a default constructor ?


The constructor that accepts no parameter are called default
constructor. They initialize the instance variables with default values
and if we do not explicitly define a constructor for the class, then java
creates a default constructor for the class.

What are punctuator ? Name some punctuators ?


They are special characters used as punctuation signs. E.g. comma (, )
semicolon (; ) dot (.) etc..

What is Null literal ?


It denotes the absence of a value. It is used to initialize an object or an
array.
e.g String s = null;
Integer t = null;

Explain System.exit(0)?
This function is used when we want to terminate the execution at any
point of the program. As soon as the function is invoked, it terminates
the execution ignoring the rest of the statements of the program.

What is autoboxing ?
The automatic conversion of primitive datatype into an object of its
equivalent wrapper class is known as autoboxing.
e.g Integer I = new Integer(26);

What is Unboxing ?
Unboxing is the system of converting an object of wrapper class into
primitive data type.

e.g. Integer I = new Integer(26);

int y = I;

What is meant by subscript of an array ?

The cell number of the array used within square bracket along with array
variable is said to be subscript of an array.

What do you mean by direct initialization of the array ?

It refers to assigning the values to the array at the time of its declaration.

What is package ? Name any 2 Java Application Programming


Interfaces packages ?
A package is a group of related classes. Java.io, java.util, java.lang, java
.math

Name any 2 OOPs principle ?


Data Abstraction, Inheritance, Polymorphism, Message passing,
Encapsulation.

Name the 2 types of constructors ?


Default constructor and Parameterized constructor

Name the operators?

< Relational operator ++ Unary increment && Logical operator


?: Ternary or conditional operator

What are the 2 ways of invoking function ?

1. Call by value or pass by value


2. Call by reference or pass by reference.

Name any 2 library packages


Java.io, java.util

Name the logical operators


&& AND
|| OR
! Not

Write 2 characteristics of a constructor ?

They have the same name as that of the class name. They are executed
when an object is created.

Name the two ways of initializing a variable

Static and Dynamic

Name some types of Inheritance

Single Inheritance, Multiple Inheritance, Hierarchical Inheritance, Hybrid


Inheritance and Multilevel Inheritance.

Name the two types of Java Programming

1. Stand alone System(Java application)


2. Internet applets(Java applets)

Name the 3 types of comments


1. Single line //
2. Multi line /*….*/
3. Documentation /**….*/

Name the three types of access specifiers?


Public, private and protected

Name any 4 tokens of java


Literals, Identifiers, Seperators, Punctuators, Operators, keywords,
Assignment

Name the types of errors


Runtime, Logical, Syntax

Name the two jump statements

break and continue


Give the precedence of logical operators
Not-> And-> Or

Give 2 advantages of using functions

It reduces the length of the program. It takes less memory space for
storage of program. Debugging is easier. It enhances reusability of
code.

Why == can never be used to check equality of the strings ?

Because comparing two strings is same as comparing two character arrays


which are non primitive data.

A constructor can never be defined as private. Explain.

A constructor can never be declared private because the object creation


outside the class may not be possible.

Character.toUpperCase(ch), if ch is already in uppercase, what will


happen?
The function returns the same character

What will following return and why ? Character.toLowerCase(‘?’)


It returns the same character i.e. ? because the given character is not a
Letter.

Explain for loop with an example


It is a iterative statement used to execute a block of code repeatedly for
a fixed number of times.
Syntax for(initialization; test condition; updation){…}

What is the purpose of the new operator ?


It is used to create new objects or new array.e.g.
int arr[] = new int[10];
Myclass obj = new Myclass();

Explain the function of return statement ?


It terminates the execution of the function and returns a value to the
calling function.

What does a class encapsulate ?


A class encapsulates the data(instance variables) and methods

Name the method of Scanner class that is used to input an

1. Integer data from standard input stream – nextInt()


2. A string data from standard input stream - nextLine()

Name the search or sort algorithm that

1. Makes several passes through the array, selecting the next smallest item
in the array each time and placing it where it belongs in the array -
Selection sort
2. At each stage , compare the sought key values with the key value of the
middle element of the array.—Binary search.

Conversion of String to primitive datatype is possible when it contains


only numbers. What will happen if we try to convert alphabetic or
alphanumeric strings to primitive datatypes ?
It will throw NumberFormatException

What is the need of autoboxing ?

1. To pass a primitive data toa function that uses a wrapper object as


function argument.
2. To add a primitive data in the list of array elements.

What is the need of Unboxing ?


1. When a data from arraylist is to be used as primitive data.
2. When the value from wrapper object is to be passed to the function
having primitive argument.

Name the functions to convert String to


1. int -----Integer.parseInt() OR Integer.valueOf()
2. float-----Float.parseFloat() OR Float.valueOf()
3. double -----Double.parseDouble() OR Double.valueOf()
4. long ----Long.parseLong() OR Long.valueOf()

Give the argument type of the function valueOf()---- String

Give the return datatype of the function toString()---- String

Name the functions to convert


1. int to String ----Integer.toString()
2. long to String ---- Long.toString()
3. float to String --- Float.toString()
4. double to String --- Double.toString()

Why is class called as composite data type?

A class encapsulates one or more datatypes together to be used as a single


unit. So, it is called a composite data type.

When there are multiple definitions with the same function name , what
makes them different from each other ?

The function signature i.e. the number and type of parameters

Name two exception handling blocks and explain them ?

1. try – It identifies a block of code in which an exception can occur.


2. catch – It identifies a block of code called as exception handler that can
handle a particular type of exception.

How is inheritance useful?


It helps in reusability in such a way that it adds some additional features
to a class without modifying the contents of the class.

What is the use of exception handling in java ?


When some error occurs in a program then an exception is created by
its throwable class. It helps java not to terminate the program when the
error occurs rather the program is able to continue execution. It handles
irregular situations that occur when a program is executing.

Why is a class called a factory of objects?


Factory of object means a factory that makes objects. Class is an object
maker. It contains all attributes to create an object. It also contains the
statements that describe the operation that the object is going to
perform.

Give the use and syntax of ternary operator?


It requires three operands. It checks the condition and returns only one
value out of two.

Syntax: condition ? true value: false value

What is the role of keyword void in declaring functions ?

It signifies that the function will not return any value to the calling function.

Mention any two attributes required for class declaration?

Access specifier, class name

Give the use of wrapper class

To store primitive values in objects. To provide conversion system from


String type to other primitive types and vice versa.

Give the scope of local variables

The scope is from the line it is declared until the closing curly brace of the
method within which it is declared.

Why do we need a constructor as a class member.

It is needed as a class member to initialize the instance variables when as


object is created.

If a function contains several return statement, how many of them will be


executed ?

Only one

What is the use of null loop ?

To create a delay during execution

What is fall through situation in switch case statement?

If in the switch, break is not present in any case, the control goes to the
next case. This execution of more than one case at a time is called
“Fall through”.

Why is an object called an instance of a class?


An object is based on the blueprint as specified by the class or the copy of
the class, every object of a class reserves the memory of the same
capacity of that of a class

What is the function of catch block in exception handling ? wher does


it appear in a program ?
A catch block is the group of java statements that are used to handle a
raised exception.The catch block should be placed after try block.

Name the package that contains the class

BufferedReader—java.io Scanner—java.util

String--- java.lang Double – java.lang

Name the return type of following library functions

replace(char,char)- String log()- double

random()- double ceil()- double pow()--- double nextInt()--int

Name the class of the following functions

random()--- Math ceil()—Math nextInt()- Scanner

Distinguish between accumulator and counter


Accumulator is a variable that contains cumulative sum of a number of
values. Counter is a variable that increases by one after each execution.

Give a similarity between while and do..while loop


Both are conditional iterative structures.

Give the difference between toLowerCase() and toUpperCase()


toLowerCase()- converts all characters of the string to lowercase
whereas toUpperCase() converts all characters of the string to upper
case.

Give the difference between entry controlled loop and exit controlled
loop?

In entry controlled loop the condition is checked at the entry of the loop. If
false, loop is never executed. Hence minimum iteration could be 0
also. In exit controlled loop, condition is checked at the end of the
loop. So loop is executed at least once.

Give the difference between operator and expression ?


Operator is a symbol or a token like ++, - , * etc which acts on one , two
or three operands to give meaningful result.
Expression is any valid combination of operators ,constant and
variables.

Difference between token and identifier

Token is a smallest individual unit in a program.e.g. keyword, punctuators,


seperators etc.

Identifier is the name given to different parts of a program. E.g. variable,


class, function etc.

Give difference between boolean and character literal

A boolean literal can have either true or false. A character literal is a single
character enclosed within a pair of single quotes.

Give one similarity and one difference between while and for loop?

Similarity- both are entry controlled looping statement

Difference – While loop is used when number of iteration is not known and
for loop is used for number of iteration is known.

How is implicit conversion different from explicit conversion?


The automatic conversion of smaller datatype to bigger data type is
called implicit conversion. E.g. int x = ‘s’;
Process of converting bigger datatype to smaller one using the typecast
operator () is called explicit conversion. E.g.
char s= (char)95;

Give the difference between static and non-static data members

A static data member is an instance variable that is common for all


objects of the class. Non-static data member is not common for all
objects of the class.
How are private members of a class different from public members?

Public member can be accessed from any other class. Private members can
only be accessed within the declared class.

Вам также может понравиться