Java Theory (9th Class)
Java Theory (9th Class)
1) OOP - Object Oriented Programming is a modular approach which allows the data to be applied within a stipulated
program area. It also provides the reusability feature to develop productive logic and gives more emphasis on data.
2) Data abstraction – It is an act of representing essential features without including background details.
4) Machine Level Language – It is the form of computer language in which instruction are coded in terms of binary
digits i.e. 0s and 1s.
5) Polymorphism - It is a process of using a function or operator for more than one purposes.
6) Procedure Oriented Programming focuses on the functions rather than the data. The data values may keep floating
throughout the program in an insecure and unrestricted manner.
7) Inheritance – It is an OOP principle according to which a class acquires some features from another class.
8) Assembly Level Language – A language in which the instructions are coded in terms of mnemonics and
short forms is known as Assembly level language.
Distinguish between.
1) OOP and POP - Procedural Oriented Programming emphasizes on function rather than data. Data is not safe and
secure as it flows freely from function to function. It follows top-down approach.
Object Oriented Programming emphasizes on data rather than functions. Data is restricted to be used only by
authorized functions so data is safe and secure. It follows bottom-up approach.
2) HLL and LLL - High Level Languages are easy for human being to understand but computer does not understand
them directly. Translators are required to convert HLL to machine code. Low Level Languages are difficult for human
beings to understand but directly understood by computer. No translator is needed.
3) Compiler and Interpreter - Compiler converts the whole source code program into the object code at once. It
shows all errors in the program at once. Interpreter converts the source program into object code one line at a
time. It shows one error at a time.
Q.7) What are Java reserved words? Name any five of them.
Ans. Java reserved words are also known as keywords. These are the words which carry special meaning for
the compiler. Five keywords are – class, public, static, void, double etc.
Example:
//to display hello world
import java.lang.*;
class A
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}
Q.14) What are the points to be taken care of while naming a class in a Java program?
Ans. The class name should not contain blank space. The class name should not be a keyword. The class name
should not start with a digit. No symbol other than $ and _ should be used.
Q.8) Write a Java statement to create an object ‘keyboard’ of the class ‘Computer’.
Ans. Computer Keyboard = new Computer();
Q.12) What do you understand by Boolean data type? Explain with an example.
Ans. Boolean data type is used to create variables which will store true or false. Boolean data type occupies 1 byte of
memory.
Q.13) What do you mean by primitive data type? Give two examples.
Ans. Primitive data types are inbuilt data types or system defined data types which come along with Java language.
There are eight primitive data types. int and double are two primitive data types.
Q.17) What do you mean by type conversion? How is implicit type conversion different from explicit type conversion?
Ans. The change of the data type of an operand to another type is called as type conversion. Implicit type conversion
takes place internally and automatically. In a mixed expression, all lower data type operands are automatically
converted to the higher data type operand present in the expression.
Explicit type conversion means the data type on an operand is forcibly converted to another through user
interference.
Q.3) Explain Arithmetic operators, Relational operators, Logical operators, Unary operators, new operator and dot
operator.
Ans. Arithmetical operators are symbols used for mathematical calculations. Ex: +, –, *, /, %
Relational operators are symbols used for comparisons. They return boolean true or false. Examples:
Unary operators are symbols that operate on a single operand. Examples: ++, – –, !, –, +
The new operator is used to create objects of a class. It allocates memory dynamically.
The dot operator (.) is used to access members of a class or of an object or of a package. It provides path.
Q.4) What is ternary operator? Write its syntax and explain it with an example.
Ans. Ternary operator deals with three operands. It is also called the conditional assignment operator. Because the
value assigned to a variable depends on the result of a condition.
Syntax: Variable = Condition? Expression1 : Expression2;
Here if the condition is true, then expression1 is assigned to the variable. If the condition is false, then expression2
is assigned to the variable.
Ans.
a) Binary operators deal with two operands. Examples: +, –, *, /, %, >, <, >=, <=, ==, !=, =,etc. Ternary operators
deal with three operands. ? and : are Ternary operators.
b) Logical AND (&&) operator is used to combine two or more conditional expressions such that it results in true
if all the conditions are true, otherwise its result is false. Logical OR (||) operator is used to combine two or
more conditional expressions. It will result in true if any one or more condition is true, if all conditions are
false, it results in false.
c) When unary increment or decrement operator is used before the operand, it is known as prefix operator. The
value of the variable changes before the operation will take place. When the unary increment or decrement
operator is used after an operand, it is known post fix operator. It changes the value of the operand after
performing the operation.
d) System.out.print() statement displays the output on screen and keeps the cursor on the same line so that the next
output appears on the same line. System.out.println() statement displays the output on the screen and takes the
cursor to the next line so that the next output will appear on the next line.
]
else
{
Statement3
}
int a;
for(a=1;a<=5;a++)
System.out.println(“Welcome”);
Q.5) Define entry control loop and exit control loop with example.
Ans. In entry control loop, the condition is first checked and then the loop executes. The loop may not execute even
once if the condition is false from the beginning. for and while are its example. In Exit control loop, the condition is
checked after executing the loop block. This loop will execute at least once even if the condition is false from the
beginning. do-while is its example.
Q.6) Write down the general format / syntax of a) for loop, b) while loop and c) do-while loop.
Ans.
b) initialization;
while(test condition)
{
statements
updation
}
c) Initialization
do
{
Statements
Updation
} while(test condition);
Q.7) Write down the use of break and continue in loop.
The break keyword is a jump statement. It is used to terminate a switch block or a loop and takes the control out of it
immediately skipping rest of the iteration of the loop or subsequent cases in the switch block unexecuted. The continue
keyword is a jump statement. It is used in a loop to skip its current iteration and go for the next iteration skipping
statements following it. It does not terminate the loop and keeps the loop running until the loop condition is false.
Q.9) Define finite loop, Delay loop, Infinite loop and Null loop.
Finite loop – When a loop block is executed for a fixed number of times, it is called a finite loop.
Delay loop – A null loop is used to delay the execution of the subsequent statements in the program. That’s why a null
loop is also called as delay loop.
Infinite loop – A loop which never ends and executes for ever is known as infinite loop.
Null loop – A loop that does not include any statement to be executed is known as null loop.
Q.11) Write one similarity and one difference between while and do while loop.
One similarity between while and do-while loop is both are categorized as unfixed iterative loops. One difference
between them is while is an entry control loop and do-while is an exit control loop.
Q.12) Write one similarity and one difference between while and for loop.
Ans. One similarity between while and for loop is both are categorized as entry control loops. One difference between
them is while loop is unfixed iterative loop and for loop is fixed iterative loop.
Q.13) Give one difference between Step loop and Continuous loop.
Ans. Step loop is a loop where the control variable is updated by a given value other than 1 after each iteration.
Continuous loop is a loop where the control variable is updated by 1.