Font size
WorksheetsJava Operators
Total questions: 129
Worksheet time: 2hrs 9mins
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
What would the new value of A be?
A=1;
a++;
1
2
3
4
Please write correct output in following space-
10
20
No Output
Error
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
small
tiny
huge
Compilation fails
Find the output of the following snippet.
class Numbers
{
public static void main(String args[])
{
int a=20, b=10;
if((a<b)&&(b++ <25))
{
System.out.println("this is any language logic");
}
System.out.println(b);
}
}
10
12
11
Compilation Error
Which are the types of operators seen? Select as many you think
bitwise operator
subtraction operator
equality operator
arithmetic operator
what is modulo operation used for ?
performs division
performs division and gives no remainder
performs division and gives remainder
does not perform division
arithmetic operators return a value. True or false?
true
false
conditional operators does not return a value
true
false
which data types work on bitwise operators?
byte
double
char
int
which type of operator it is? i + =5
addition assignment operator
conditional operator
arithmetic operator
equality operator
--------- is a symbol, that operates on operands and produce a result
operands
variables
operators
Ternary
Which are the types of operators seen? Select as many you think
bitwise operator
subtraction operator
equality operator
arithmetic operator
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
What would the new value of A be?
A=1;
a++;
1
2
3
4
Please write correct output in following space-
10
20
No Output
Error
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
small
tiny
huge
Compilation fails
Find the output of the following snippet.
class Numbers
{
public static void main(String args[])
{
int a=20, b=10;
if((a<b)&&(b++ <25))
{
System.out.println("this is any language logic");
}
System.out.println(b);
}
}
10
12
11
Compilation Error
Which are the types of operators seen? Select as many you think
bitwise operator
subtraction operator
equality operator
arithmetic operator
what is modulo operation used for ?
performs division
performs division and gives no remainder
performs division and gives remainder
does not perform division
arithmetic operators return a value. True or false?
true
false
conditional operators does not return a value
true
false
which data types work on bitwise operators?
byte
double
char
int
which type of operator it is? i + =5
addition assignment operator
conditional operator
arithmetic operator
equality operator
--------- is a symbol, that operates on operands and produce a result
operands
variables
operators
Ternary
Choose the logical operators
And
Less than
OR
Not Equal
What is the result of 13<=13 ?
True
False
Both true and false
None
The result of AND operator is always true, if both the conditions results are _____
True
False
What is the symbol of ternary operator?
?:
?;
:?
;?
What is the value in variable A?
A+=112
112
111
113
130
What is the another name of constant in java?
Dynamic
Static
Literals
Change
in Java every statement is end with _____?
Comma
Colon
Semicolon
Brace
Java is case sensitive language.
True
False
Choose the correct statement about java?
First name of a java is OAK
Java is a advanced version of VB
Java is the name of a Tree
Java doesn't support object
Java program can distributed over the internet by using _____
Tablet
Applet
HTML
Package
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
else x--;
else if (x < 0) x--;
if (x < 0) x--;
else x = 0;
else x++;
x--;
++i and i++ cannot be used anywhere for the same purpose
true
false
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
--; decreases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
What would the new value of A be?
A=1;
A--;
0
1
2
-1
What does the following code output?
int x = 1;
System.out.println(x++);
1
2
compilation error
runtime error
PRE-increment us used when you want to use the incremented
value of the variable in that expression. Whereas POST-increment uses the original value before incrementing it
True
False
What would the new value of A be?
A=1;
a++;
1
2
3
4
Write the java expression for the following
ax5+bx3+c
(a)
Give the output of the following , when m = 10, n =6
m - = 9 % ++n + ++n/2
(a)
What is the value of y if x = 5
y = ++x - x++ + --x
(a)
a2+b
(a)
What will be the value x if a = , b =
x = ( a > b ) ? a : b
(a)
Rewrite the following code using ternary operator
int c ;
if( a > b )
c = a;
else
c = b;
(a)
Evaluate if a = 10 , b = 8
a % b++
(a)
What is the output of the following
char x = 'A' ;
int m ;
m = ( x== 'a') ? 'A' : 'a' ;
(a)
What will be the value of m if m = 8
m *= 8
(a)
Write the output of the following
( 4 > 7 ) || ( 7 < 15 )
true
false
how many values are required by unary operators
Three
One
Two
The operator '==' checks for
Equal values
Greater values
lesser values
String values are always written in
Single quotes
without quotes
Double quotes
How many characters can be stored in a character data type?
one
two
three
What is the difference between float and double data type?
Unary operators are used to increase or decrease only one number.
true
false
none
true && true
true
false
false == false
true
false
true != true
true
false
false || true
true
false
false ^ false
true
false
false && false
true
false
true || true
true
false
true ^ false
true
false
true == false
true
false
false != true
true
false
Types of Java Operators
logical
arithmetic
relational
all of above
Java expression
a<b
Types of operator for above expression is
Relational
logical
arithmetic
Evaluate this expression
a=3,b=4
!(a==0) && (b<5)
true
false
Which of the following statement is valid
int a+b=5;
double char =m;
int name;
name = 5;
IQ = 5;
int IQ;
Java expression
a&&b
Type of operator
relational
logical
arithmetic
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
What will be the output of the following program?
public class DemoOnOperators
{
public static void main(String[] args)
{
int input = 7;
int output = ++input + ++input + ++input;
System.out.println(output);
}
}
-20
109
27
35
What will be the output of the following program?
public class DayMonthDemo
{
public static void main(String args[])
{
int num = 69;
int days = num % 30;
int month = num / 30;
System.out.println(month + " Month and " + days + " days");
}
}
3 Month and 9 days
2 Month and 9 days
0 Month and 69 days
0 Month and 29 days
Choose the incorrect statement about the following expressions?
a=a+1; // Expression 1
a++; // Expression 2
a+=1; // Expression 3
++a; // Expression 4
All expressions give the same result
'Expression 2' is faster that 'Expression 3' which inturn is faster than 'Expression 1'
The value of 'a' after 'Expression 2' is different from 'Expression 4'
The value of 'a' after 'Expression 1' is same as 'Expression 3
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
small
tiny
huge
Compilation fails
What is the output of the Java code snippet with Ternary operator?
String name = "java";
int marks = name == "java"?10:20;
System.out.println("Marks=" + marks);
marks=0
marks=10
marks=20
None of the above
Find the output of the following snippet.
class Numbers
{
public static void main(String args[])
{
int a=20, b=10;
if((a<b)&&(b++ <25))
{
System.out.println("this is any language logic");
}
System.out.println(b);
}
}
10
12
11
Compilation Error
It provides a runtime environment in which Java byte code can be executed
JVM
JDK
JRE
Eclipse IDE
What does IDE mean?
Integration Development Environment
Integration Device Environment
Which one is correct?
public static main(Strings[] args) { }
public private static main(Strings[] args) { }
public static void main(Strings[] args) { }
public void static main(Strings[] args) { }
byte is 1 byte size in storage?
True
False
Long is 4 byte size in storage?
True
False
char is 2 byte in storage?
True
False
(=) sign means
equals and it is used for math problems in Java
assignment operator. It used to assign a value
Which one is used for remainder in Java?
/
%
+
*
int x = 3; in this case, which of the following statement is true?
x = x+1;
x++;
x += 1;
All of above
A developer wants to convert a smaller data type to larger data type. What is this in Java?
Widening primitive
Narrowing primitive
Which data type is used to store:
TRUE
Boolean
Double
String
Integer
Which data type is used to store:
100
Integer
Double
Boolean
String
"D"
What is a variable?
A storage location of memory which can change
A random area to store things in.
Something that changes
Something that can only store numbers
It provides a runtime environment in which Java byte code can be executed
JVM
JDK
JRE
Eclipse IDE
Which one is correct?
public static main(Strings[] args) { }
public private static main(Strings[] args) { }
public static void main(Strings[] args) { }
public void static main(Strings[] args) { }
char is 2 byte in storage?
True
False
(=) sign means
equals and it is used for math problems in Java
assignment operator. It used to assign a value
int x = 3; in this case, which of the following statement is true?
x = x+1;
x++;
x += 1;
All of above
Which one is used for remainder in Java?
/
%
+
*
Which component is used to compile, debug and execute java program?
JVM
JDK
JIT
JRE
Which component is responsible for converting bytecode into machine specific code?
JVM
JDK
JIT
JRE
Which component is responsible to run java program?
JRE
JVM
JIT
JDK
Which component is responsible to optimize bytecode to machine code?
JRE
JVM
JDK
JIT
Which statement is true about java?
Sequence dependent programming language
Code dependent programming language
Platform independent programming language
Platform dependent programming language
JVM is _____
code dependent
code independent
platform dependent
platform independent
What is the extension of compiled java classes?
.class
.js
.txt
.java
Which of the following option leads to the portability and security of Java?
The applet makes the Java code secure and portable
Use of exception handling
Dynamic binding between objects
Bytecode is executed by JVM
Which of the following is not a Java features?
Architecture Neutral
Dynamic
Use of pointers
Object-oriented
In which memory a String is stored, when we create a string using new operator?
Stack
String memory
Random storage space
Heap memory
correct execution process in Java
load->edit->compile->verify->execute
edit->load->compile->execute->verify
edit->compile->load->verify->execute
verify->edit->compile->load->execute
JVM full form___
Java Visual Model
Java Virtual Model
Java Visual Machine
Java Virtual Machine
