Self-practice questions
_________________________________________________________________________________
1) Which of the following is a relational operator in Java?
a. +
b. =
c. ==
d. &&
2) Which of the following operators is used to perform addition in Java?
a) +
b) -
c) *
d) /
3) Which of the following operators is used to perform division in Java?
a)%
b)&
c)|
d)/
4) Which of the following is a logical operator in Java?
a)++
b)/
c)&&
d)=
5) Which of the following is a unary operator in Java?
a) +
b) /
c) -
d) *
6) Which of the following operators has the highest precedence in Java?
a)+
b)/
c)++
d)&&
7) Which of the following operators is used to perform modulo division in Java?
a)/
b)%
c)*
d)&
8) Which of the following operators is used to perform bitwise AND in Java?
a)&
b)&&
c)|
d)^
9) Which of the following operators is used to perform equality comparison in Java?
a) =
b) ==
c) !=
d) >
10) Which of the following operators is used to perform bitwise OR in Java?
a) |
b) ^
c) &
d) ||
11. What is the output of the following code snippet?
1. int i = 0;
2. while (i < 3) {
3. [Link](i + " ");
4. i++;
5. }
12. Which of the following is not a valid primitive data type in Java?
a. int
a. float
a. double
a. string
13) What is the output of the following code snippet?
1. int x = 5;
2. int y = 10;
3. if (x < y) {
4. [Link]("x is less than y");
5. } else {
6. [Link]("x is greater than or equal to y");
7. }
14) Which of the following operators is used to perform decrement in Java?
a. --
a. +
a. *
a. &
15) Which of the following operators is used to perform logical OR in Java?
a. &
a. &&
a. |
a. ^
16) What is the output of the following code snippet?
1. int a = 5;
2. int b = 2;
3. int c = a / b;
4. [Link](c);
17) Which of the following operators is used to perform left shift in Java?
a. <<
a. >>
a. &
a. |
18) Which of the following is not a valid identifier in Java?
a. $test
a. _test
a. 123test
a. test123
19) Which of the following is a conditional operator in Java?
a. =
a. *
a. +
a. ?
20) What is the output of the following code snippet?
1. int x = 10;
2. int y = 20;
3. int z = x++ + ++y;
4. [Link](z);
a. 31
a. 32
a. 33
a. 34
21) Which of the following is a unary logical operator in Java?
a. !
a. &
a. |
a. ^
22) What is the output of the following code snippet?
1. int i = 0;
2. do {
3. [Link](i + " ");
4. i++;
5. } while (i < 3);
23) Which of the following operators is used to perform bitwise XOR in Java?
a. ^
a. |
a. &
a. ~
24) What is the output of the following code snippet?
1. int a = 5;
2. int b = 7;
3. [Link]((a > b) ? "a is greater than b" : "a is less than or equal to b");
25) What is the right output of this program ?
public class UnaryOperators {
public static void main(String[] args) {
int i = 5;
[Link](i++);
[Link](++i);
[Link](i--);
[Link](--i);
}
}
26) what will be output of given code?
public class ShiftOperators {
public static void main(String[] args) {
[Link](8<<2);
[Link](",");
[Link](8>>1);
}
}
27) what will be output of given code?
public class BitwiseNotOperator{
public static void main(String[] args) {
int i = 50;
[Link](~i);
[Link](",");
[Link](~--i);
[Link](",");
[Link](~++i);
}
}
28) what will be output of given code?
public class ModulusOperator {
public static void main(String[] args) {
int a = 15;
int b = 12;
[Link](a%b);
[Link](",");
[Link](b%a);
}
}
29) what will be output of given code?
public class RelationalOperators {
public static void main(String[] args) {
int a = 4;
int b = 5;
[Link](a>b);
[Link](",");
[Link](a<b);
}
}
30) what will be output of given code?
public class LogicalOperators {
public static void main(String[] args) {
int a = 5;
int b = 10;
boolean flag = a>b;
[Link](!flag);
}
}
31) what will be output of given code?
public class TernaryOperators {
public static void main(String[] args) {
int a = 10;
String result = a > 5 ? "Hello 1" : "Hello 2";
[Link](result);
}
}
32) Which of the following is the correct way to use the ternary operator?
A var result = (condition) ? valueIfTrue : valueIfFalse;
B var result = (condition, valueIfTrue, valueIfFalse);
C var result = ?(condition) valueIfTrue : valueIfFalse;
D var result = if(condition) ? valueIfTrue : valueIfFalse;
33) What is the precedence order of the operators: *, +, and ()?
A +, *, ()
B *, +, ()
C (), *, +
D (), +, *
34) Which operator is used to invert the value of a boolean variable?
A~
B!
C–
D^
35) Which of the following operators has the highest precedence in Java?
A &&
B+
C/
D ++
36) What does the expression ‘x &= y’ do?
A Sets x to the result of x AND y
B Sets x to the result of x OR y
C Sets x to the result of x XOR y
D Compares x and y for equality
36) Which of the following is a unary operator in Java?
A+
B–
C/
D*
37) What is the output of the following code snippet?
int x = 5;
int y = 10;
int z = x++ + ++y;
[Link](z);
38) Which operator is used for type casting in Java?
A cast
B instanceof
C ()
D typeof
39) What does the ‘>>>=’ assignment operator do?
A Performs a right shift and assigns the result
B Performs a left shift and assigns the result
C Performs an unsigned right shift and assigns the result
D Performs an unsigned left shift and assigns the result
40) Which of the following is the correct use of the bitwise XOR operator in Java?
A int result = x ~ y;
B int result = x ^ y;
C int result = x | y;
D int result = x && y;
41) 1. When the operator ++ is placed after the variable name, the first assignment of the value of
the variable takes place and then the value of the variable is incremented, this operation is also
called ……………………………
A) pre-increment
B) post-increment
C) left to right increment
D) right to left increment
42. When the operators are having the same priority, they are evaluated from …………………………..
in the order they appear in the expression.
A) left to right
B) right to left
C) any of the above
D) none of the above
43. To change the order in which expressions are evaluated …………………. are placed around the
expression that is to be evaluated first.
A) ampersand
B) equals
C) parentheses
D) greater than
44) What will be the values of x, y and z after execution of the following statements?
int x, y, z;
x=9, y=10;
z=++x=y++;
45) If int x=15; y=20; what will be the value of x after executing the following statement
x=(x<y) ? (y+x) : (y-x);
46) When one of the operands is real and the other is an integer, the expression is called a
……………………. expression.
A) hybrid
B) mix-mode-arithmetic
C) arithmetic
D) real-integer
47) In Java, the ……………………… is used to access the instance variables and methods of class
objects.
A) dot operator(.)
B) instance of
C) bitwise
D) conditional
48) The …………………….. is an object reference operator and returns true if the object on the left-
hand side is an instance of the class given on the right-hand side.
A) dot operator(.)
B) instance of
C) bitwise
D) conditional
49) what will be output of given code?
1. class leftshift_operator
2. {
3. public static void main(String args[])
4. {
5. byte x = 64;
6. int i;
7. byte y;
8. i = x << 2;
9. y = (byte) (x << 2)
10. [Link](i + " " + y);
11. }
12. }
50) What does the expression int z = 7; z = z++ + ++z; evaluate to?
51) What is the value of int a = 3; a = a++ + a–;?
52) What is the output of the following code snippet?
int b = 2;
[Link](++b + b++);
53) What is the output of the following code snippet?
int d = 3;
[Link](d++ + ++d – d–);
54) What is the output of the following code snippet?
int m = 2;
[Link](m++ + m– – ++m);
55) what will be output of given code?
int z = 5;
[Link](z++ + z++ + z++);
56) If int a = 8; and int b = a–;, what are the values of a and b?
57) What is the output of the following code snippet?
int c = 6;
[Link](c– – c++ + ++c);
58) What is the output of the following code snippet?
int k = 7;
[Link](k++ + ++k – k–);
59) What will be the value of "x" after execution ?
int x = 0, y = 0 , z = 0 ;
x = (++x + y-- ) * z++;
60) what will be output of given code?
int ++a = 100 ;
[Link]( ++a ) ;
61) What is the output of the following program ?
class Numbers{
public static void main(String args[]){
int a=20, b=10;
if((a < b) && (b++ < 25)){
[Link]("This is any language logic");
}
[Link](b);
}
}
62) What will be the output?
if(1 + 1 + 1 + 1 + 1 == 5){
[Link]("TRUE");
}
else{
[Link]("FLASE");
}
63) what will be the output?
public class Test{
public static void main(String args[]){
[Link](""=="");
[Link](" ");
[Link]("A"=="A");
[Link](" ");
[Link]("a==A");
64) What will be the output?
public class Test{
public static void main(String args[]){
int a = 42;
double b = 42.25;
[Link]((a%10)+" "+(b%10));
}
}
65) What will be the output after compiling and running following code?
1. public class Test{
2. public static void main(String... args){
3. int x =5;
4. x *= 3 + 7;
5. [Link](x);
6. }
7. }
66) Determine output:
public class Test{
public static void main(String... args){
int a=5 , b=6, c=7;
[Link]("Value is "+ b + c);
[Link](a + b + c);
[Link]("String " + (b+c));
}
}
67 Determine output:
public class Test{
static int i = 5;
public static void main(String... args){
[Link](i++);
[Link](i);
[Link](++i);
[Link](++i+i++);
}
}
68. what will be output of given code?
public class Demo
{
public static void main(String x[])
{
int a=5,b;
b=a++ & 7 | 8 + 9 ;
[Link]("B is "+b);
}
}
69. what will be output of given code?
public class Demo
{
public static void main(String x[])
{
int a=5,b;
b = a++ & 7 | 8 + 9 && a>3 ;
[Link]("B is "+b);
}
}
70. what will be output of given code?
public class Demo
{
public static void main(String x[])
{
int a=5,b;
b = a>5 && a>4;
[Link]("B is "+b);
}
}
71. what will be output of given code?
public class Demo
{
public static void main(String x[])
{
int a=10;
if(a)
{ [Link]("Hi");
}
else
{ [Link]("Hello");
}
}
}
72. what will be output of give code?
public class Demo
{
public static void main(String x[])
{ int a=10;
if(a>5 && ++a>5)
{ [Link]("Hi");
}
else
{ [Link]("Hello");
}
}
}
73. what will be output of given code?
public class Demo
{
public static void main(String x[])
{
int a=10;
if(!(a>5 && ++a>5 ||a++>6 && a<7))
{ [Link]("Hi");
}
else
{ [Link]("Hello");
}
}
}
74. what will be output of given code?
public class Demo
{
public static void main(String x[])
{
int a=10;
if(!(a>5 && ++a>5 ||a++>6 && !(!(a)<7)))
{ [Link]("Hi");
}
else
{ [Link]("Hello");
}
}
}
75. what will be output of given code?
public class Demo
{
public static void main(String x[])
{
boolean b=true;
switch(b)
{
case false:
[Link]("Good");
break;
default:
[Link]("Wrong choice");
}
}
}
Q76. What will be output of given code?
public class Demo
{
public static void main(String x[])
{
String s="good";
switch(s)
{
case "bad";
[Link]("Bad");
break;
default:
[Link]("Wrong choice");
}
}
}
Q77. What will be output of given code?
public class Demo
{
public static void main(String x[])
{
String s="good";
switch(s)
{
case "bad":
[Link]("Bad");
break;
default:
[Link]("Wrong choice");
}
}
}
Q78. What will be output of given code?
public class Demo
{
public static void main(String x[])
{
String s="good";
switch(s)
{
case "bad"!=s:
[Link]("Bad");
break;
default:
[Link]("Wrong choice");
}
}
}
79. what will be output ?
public class Demo
{
public static void main(String x[])
{
float a=5.4f;
switch(a)
{
case 2.3f;
[Link]("Bad");
break;
default:
[Link]("Wrong choice");
}
}
}
80. what will be output of given code?
public class Demo
{
public static void main(String x[])
{
char ch='a';
switch(ch)
{
case 'a':
[Link]("Bad");
break;
default:
[Link]("Wrong choice");
}
}
}
True and false question
_________________________________________________________________
Q1. is it true java is not pure object language if yes then why and if no then why?
Q2. is JVM platform dependent?
Q3. is there present in unsigned int in java?
Q4. can we use long double in java?
Q5. is it true primitive data type variable not store address of memory?
Q6. is it true referential data type store address of memory?
Q7. is byte code is not machine code?
Q8. can we see the byte code in java?
Q9. is byte code present in .class file?
Q10. is it true then byte code generates after compilation?
Q11. is it true java program must be run after program compile?
Q12. is command line argument present in main function?
Q13. Is it true JVM generate byte code?
Q14. Is it true java compiler is platform independent?
Q15. Is it true byte code is platform independent?
Write down interview Question
___________________________________________________________
Q1. what is java?
Q2. what is object-oriented concept explain in depth?
Q3. explain pillars and feature of OOP?
Q4. Explain feature of JAVA?
Q5. Explain Byte code and why byte code is platform independent?
Q6. Explain compiler and JVM?
Q7. What is JDK JRE and JVM?
Q8. What is difference between JDK JRE and JVM?
Q9. what is command line argument and why use it?
Q10. what is main method and why use it?
Q11. Why main method is static in java?
Q12. Can we pass different parameter in main function other than string in Java?
Q13. Explain JVM architecture in java?
Q14. explain data types in depth?
Q15. what is difference between primitive and non-primitive data type in Java?
Program for practice
___________________________________________________________________
Q1. Write a C program to input week number(1-7) and print the corresponding day of week name
using if else. How to print day of week using if else in C programming. Logic to convert week
number to day of week in C programming.
Example
Input
Input week number: 1
Output
Monday
Q2. Write a C program to enter month number between(1-12) and print number of days in month
using if else. How to print number of days in a given month using if else in C programming. Logic to
find number of days in a month in C program.
Example
Input
Enter month number: 1
Output
It contains 31 days.
Q3.