Java Theory Questions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Java Theory Questions

What is Java?
 Java is a high level programming language
 It is Two step compilation process
 It is platform independent
 It supports Object Oriented Programming
 It is case sensitive

Features if Java:
 Simple
 Object Oriented
 Robust
 Portable
 High performance

Structure of Java:
class className
{
public static void main(String[] args)
{
--
}
}

What is JVM?
 JVM stands for Java Virtual Machine
 It is platform dependent
 It is a translator used to convert Byte code into machine understandable format

What is JDK?
 JDK stands for Java Development Kit
 It is used to compile and run the java program

What is JIT?
 JIT stands for Just InTime Compiler
 It is used to increase the performance during conversion of byte code into binaries.

What is compile Time?


The time taken to check the syntzx and semantics and add some extra information
What is Run time?
The time taken by the JVM to convert byte code into machine understandable language

Write the command for compile and run java program in command
prompt?
Compile : javac classname.java
Run : java classname

What is print and println statement?


print statement:
 It is used print in a single line
 Data is mandatory
println statement:
 It is used to print line by line
 Data is optional
What is Tokens?
 Tokens are the basic units in java
 There are four types. They are Keywords,Identifiers,Separators and Literals

What is Keyword?
 Keywords are the reserved words in java
 Each keyword has its own meaning
 These are pre-defined words
 It should be in lower case
 In java there are 49+ keywords
 Example: class , static, if, for

What is Identifiers and its rules?


 Identifiers are the components such as class, variables. Methods and interfaces
Rules:
 Identifiers should not start with numbers but in between or last
 Identifiers do not have spaces inbetween
 Except $ and _ no special characters are used
 Keywords should not be used as identifier
What is Separators?
 Separators are used to separate java instruction
 Example: { , } , ;,

What is Literals?
 Literals are just an information or value
 There are five types of literals. They are Integer literals, Float literals, Character
literals, String literals, Boolean literals.

What is variables?
 Variables are the named memory block which is used to store the data.
 Example: int a=10;

What is Local Variables?


 Local variables are declared inside of a body

What is Instance variables?


 Instance variables are defined without Static keyword.
 They are defined outside method declaration

What is Static variables?


 It is initialized only once at the start of program execution.
 These variables should be initialized first

What is Datatypes?
 Datatype is used to specify what kind of data that is stored inside memory
 There are two types. They are
Primitive Datatypes
Non-Primitive Datatypes

What is Primitive datatypes?


 It will used to specify what type of data has to be stored.
 It is single value datatype.
 Example: byte, int, short, long, float, double
What is Non-Primitive datatypes?
 It will used to specify what type of data has to be stored.
 It is multi value datatype.
 Example: class, Array, String
What is Constant?
 A constant is a variable whose value can’t change once it has been assigned.
 Example float pi = 3.14f;

What is Operators?
 Operators are pre-defined symbols which is used to perform some tasks.
 It is used to perform an operation.
 In java based on number of operands , we can classify into three types:
➔ Unary operator
➔ Binary operator
➔ Ternary operator

What is Expression?
 The combination of operators along with operands is called as an expression

What are the types of operators?


 Arithmetic operator
 Type Casting operator
 Relational operator
 Logical operator
 Conditional operator
 Increment & Decrement operator
 Compound assignment operator

What is Type casting operator?


 The process of converting one datatype into another datatype is called as typecasting.
 It is unary operator. There are two types .
 They are ➔ Primitive Type casting. ➔ Non- Primitive Type casting.

What is Primitive Type casting?


 The process of converting one primitive datatype into another primitive datatype is
called as primitive type casting.
 It is also divided into two types. They are
➔ Widening : The process of converting lower range datatype into higher range
datatype. It is both implicit and explicit manner. Example : Byte -> long , int ->
double
➔ Narrowing : The process of converting higher range datatype into lower range
datatype. It is implicitly not possible only explicitly possible. Syntax: (Datatype)
variable; Example : Long -> byte, float ->int.

What is Non – Primitive Type casting?


 The process of converting one Non - primitive datatype into another Non- primitive
datatype is called as Non- primitive type casting.
 It is also divided into two types. They are
➔ Upcasting : The process of storing child type of reference into parent type of
container.
➔ Downcasting : The process of storing parent type of reference into child type of
container.

What is arithmetic operator?


 Arithmetic operator is a binary operator.
 We are having the following arithmetic operators: +, -, *, /, %.
 Addition operator is used to perform normal addition and concatenation.

What is Relational operator?


 Relational operator is a binary operator.
 It is used for comparison purpose.
 We are having the following Relational operators: = =, < , >, < =, > +, ! =.
 The return type of this operator is Boolean.

What is Logical operator?


 Logical operator is a binary operator.
 It is used for decision making purpose.
 We are having the following Logical operators: AND - &&, OR - || , NOT - !.
 The return type of this operator is Boolean.

What is conditional operator?


 Conditional operator is a ternary operator.
 Syntax: (Boolean) ? value : value;
 The return type of this operator is depends on Operand 2 and Operand 3.
 Operand 2 and Operand 3 are should be always homogeneous.
 When operand 1 is True , operand 2 will be answer.
 When operand 1 is False, operand 3 will be answer.

What are control flow statements?


 Programmer can control the execution flow by using 2 statements such as Decision
making & looping statements.
What is Decision Making statement?

 It is used to decide whether the instructions need to be execute or ignored.


➔ if statement.
➔ if-else statement.
➔ else – if statement.
➔ switch statement – In switch we can pass variables but in case we can’t pass
variables
What is looping statements?

It is used to repeat the task.


➔ for loop ➔ while loop ➔ do-while loop ➔ for-each loop

What is Break?
 It is control transfer statement.
 It is used in switch or loop .
 It is used to take the control from switch or loop.

You might also like