JAVA interview question and answers on JAVA variables, operators and IO file handling

Below are the Java entry level interview questions and answers. These questions are about Java variables,  Operators in Java,  Java Control Flow Statements, Java IO and File Handling. Read interview questions and answers on Java Modifiers and Java Data Types.

1) What is Variable?
A named memory location to store the temporary data within a program. Two types of memory in Computer environment. Variables store in Primary memory (RAM).
  • Primary memory (RAM)
  • Secondary memory (ROM - HDD, DVD, USB drive etc...)
2) How to Declare Variables in Java?
Java supports Explicit declaration of variables.
dataType variableName;
int a;
char x;

3) How to assign values to Variables in Java?
Two types of Assign values to variables,
i) Initialization
int a =100; //Initialization
ii) Reading (Reading using Input devices, from files)
int a =100;
int b;

4) What are Variable Naming restrictions in Java?
i) Java Variables are case sensitive.
ii) Java variable names should start with a letter or $ or _
iii) Variable names should not match with Java Keywords/Reserved words
iv) Must be unique in the scope of declaration.
v) Must not exceed 255 characters.

5) What are the types of Variables in Java?
i) Local Variables
Local variables are declared in methods or blocks.
ii) Instance Variables
Instance Variables are declared in a class but outside of a method or any block.
iii) Class / Static Variables
Static Variables are declared as static, these can't be local.

6) What are Operators?
Operators are used to perform mathematical, comparison and logical operations.

7) What are the categories of Operators in Java?
i) Arithmetic Operators
ii) Relational Operators
iii) Assignment Operators
iv) Logical Operators

8) What are Arithmetic Operators in Java?
Arithmetic Operators in Java are,
i) Addition + (Addition, String concatenation)
ii) Subtraction - (Subtraction, Negation)
iii) Multiplication *
iv) Division /
v) Modules %
vi) Increment ++
vii) Decrement --

9) Give an Example for Arithmetic Operators?
public static void main(String[] args) {
int a =10, b =5;
String c = "Selenium", d ="Testing";
System.out.println("Addition of a, b is: " +(a+b));//Addition of a, b is: 15
System.out.println(a % b);//0
a = ++b;
a = --b;

10) What are Relational Operators in Java?
Relational Operators in Java are,
i) ==
ii) !=
iii) >
iv) >=
v) <
vi) <=
Relational Operators return Boolean/logical result (true/false)

11) Give an Example for Relational Operators?
public static void main(String[] args) {
int a =10, b =20;

12) What are Logical Operators in Java?
Important Logical Operators in Java are,
i) Logical Not operator !
ii) Logical And Operator &&
iii) Logical Or operator ||

13) Give an Example for Logical Operators?
Example for Logical Operators,
public static void main(String[] args) {
boolean a =true, b =false;
System.out.println(!(a && b));//true
System.out.println(a && b);//false
System.out.println(a || b);//true

14) What are the important Assignment Operators in Java?
Important Assignment Operators are,
i) Assignment  =
ii) Add and Assign +=
iii) Subtract and Assign -=
iv) Multiply and Assign *=

15) Give an Example for Assignment Operators?
public static void main(String[] args) {
int a = 10;
a += 10;
a -= 10;
a *= 10;

16) What are the Types of Control Flow Statements in Java?
Java has Three types of Control Flow Statements,
i) Decision Making Statements
ii) Looping Statements
iii) Branching Statements

What Others are Reading Now...

0 Comment to "JAVA interview question and answers on JAVA variables, operators and IO file handling"

Post a Comment