0% found this document useful (0 votes)
17 views7 pages

Practice Worksheet 2

This document contains practice questions on Java language basics including fill in the blanks, true/false, naming concepts, choosing the correct option, and answering questions. The questions cover topics like Java keywords, data types, operators, expressions and their evaluation.

Uploaded by

Deepali Koirala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

Practice Worksheet 2

This document contains practice questions on Java language basics including fill in the blanks, true/false, naming concepts, choosing the correct option, and answering questions. The questions cover topics like Java keywords, data types, operators, expressions and their evaluation.

Uploaded by

Deepali Koirala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PRACTICE WORKSHEET 2 CHAPTER : JAVA LANGUAGE BASICS

Q1. FILL IN THE BLANKS

1. _________ are tokens that convey a special meaning to the java compiler.
a. operators
b. keywords
c. constants
d. identifiers

2. _________ are characters which define the structure of a program.


a. punctuators
b. keywords
c. literals
d. operators

3. The default value of boolean datatype is __________.


a. true
b. false
c. null
d. 0

4. char datatype occupies ______ bits of memory


a. 16
b. 2
c. 8
d. 32

5. _______ are remarks written by the programmer and are ignored by the compiler.
a. escape sequence
b. comments
c. constants
d. identifiers

6. The precision of float values is ____________


a. 7
b. 15
c. 9
d. 8

7. The Unicode equivalent of a null character is ______.


a. “”
b. /U0000
c. \U0000
d. \U000

8. By default java treats real numbers as _______.


a. byte

Shailesh Manjrekar 9819498104


b. float
c. double
d. int
9. Relational operators return _______ datatype
a. char
b. String
c. boolean
d. double

10. double +float = _________ datatype


a. double
b. float
c. long
d. int

Q2. STATE TRUE AND FALSE


1.Relational operators join two or more expressions in disjunction.
a. true
b. false

2.Intrinsic simple datatypes are called as primitive datatypes


a. true
b. false

3.The default value of char is '\U0000'


a. true
b. false

4.true and false are java keywords


a. true
b. false

5.Coercion is conversion done explicitly by type casting operators.


a. true
b. false

6. += is an unary operator
a. true
b. false

7. ‘\n’ is a valid character literal


a. true
b. false

8. The maximum length of a java identifier can be 255.


a. true
b. false

9. Constants can be changed only once during execution of the program.

Shailesh Manjrekar 9819498104


a. true
b. false

10. -127 is the smallest value that can stored in a byte datatype
a. true
b. false

Q3. NAME THE FOLLOWING


1. Determines execution of operators when more that one operator of the same precedence appear in an
expression.
a. operator precedence
b. operator associativity
c. operands

2. Operators which require only one operand to complete an expression


a. binary
b. uniform
c. unary

3. Expressions which contain the same type of operands.


a. pure
b. impure
c. mixed

4. Escape sequence used to print a new line


a. \l
b. \n
c. \t

5. Set of Characters enclosed in “ “.


a. int
b. char
c. String

Q4. CHOOSE THE CORRECT OPTION


1. Given m = 3, n = 4; the value of ans is:
ans = --m + --n + m-- - --n;

a. 6
b. 5
c. 7
d. 4

2. Given int k=5,j=9;


k= k++ - ++k - ++j - j++ +k;
System.out.println(k+" "+j)

Shailesh Manjrekar 9819498104


a.-16 10
b.-13 13
c.-14 12
d.-15 11

3. Given a=10 , b=12


a *= a++ - b-- + ++a - ++b;

a. -21
b. -18
c. -20
d. -19

4. Given a=5,b=6,c=7;
a %= a++ * ++b / c++ + ++c;

a. 3
b. 4
c. 5
d. 6

5. Given int x=4, y=7 ,z=10;


System.out.println(x-y<z && y+z>x || x-z<=y-x+z);

a. true
b. false
c. 4
d. 10

6. The output of the following will be:


System.out.println("one"+"ten"+1+10);
System.out.println("one"+"ten"+(1+10));

a. oneten11
oneten(1+10)

b. oneten110
oneten11

c. oneten110
onten110

d. oneten11
11oneten

Shailesh Manjrekar 9819498104


7. Arrange the following in the correct order of precedence (higher to lower)
+, /, &&, ==, --, +=

a. +=, &&, ==, +, /, --


b. --, +, /, ==, &&, +=
c. --, /, +, ==, &&, +=
d. --, /, +, &&, ==, +=

8. Write the most appropriate datatype type for each of the following literals
1. True
2. T

a. 1. boolean 2. char
b. 1. String 2. int
c. 1. boolean 2. int
d. 1. String 2.char

9. Which is the most appropritate ternary operator to print the value of the biggest number out of 2
numbers

a. System.out.println( a>b ? b : a);


b. System.out.println(a > b : a ? b);
c. System.out.println(a>b? a : b);
d. System.out.println(a>b ? "a" : "b" );

10. The number of bits occupied by the following datatypes are :


short, float

a. 2,4
b. 16,32
c. 8,64
d. 16,24

Q5. ANSWER THE FOLLOWING :

1. Write the ternary operator for the following :


a. Print profit or loss based on cp, sp.
b. Calculate 20% tax if the salary is more than 15000 otherwise 10% tax.
c. Print the absolute value of a number without using Math class.

2. Write the default values of the following


a. char
b. float
c. boolean

Shailesh Manjrekar 9819498104


d. int

3. Identify whether the following conversions are implicit or explicit.


a. double stored as int
b. int stored as double
c. char stored in int

4. Identify the type of operators:


a. ++
b. +=
c. ==
d. %
e. &&

5. What is the output of the following int a=5,b=6,c=4;


a) d = a>b ? (a>c?a:c) : (b>c?b:c)
b) d = a*b > b*c ? (b-a>a-c? b:a) : (a+c<b+c?b:c)

6. Write a single line equivalent java statement for


a. | c4 * √3a |
b. Squareroot of (a 2+b2 ) + c 2
c. Printing the following output on the screen using a single System.out.println()
Say “Welcome”
to Java

7. Write the output of the following , given that variable a is -99 initially
a. --a>a-- b. --a<-99

8. Correct the following java statements , given the following variable declaration int a, b; short s,t; float f,
double d;
a. t = a;
b. s = a/b;
c. f = f/d;
d. a=f*d

9. Write the output of the following


a. -5%2
b. 5%2
c. 5.0%2
d. 5%2.5

10. Given x=3 , y=-2 , z=5 , Write the values of x,y,z after the expression is executed.
a. x*=--y*z++;

Shailesh Manjrekar 9819498104


b. z+=++x*--y- --z/--x;

Shailesh Manjrekar 9819498104

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy