0% found this document useful (0 votes)
6 views6 pages

35 Marks Paper

The document contains multiple choice, numerical, and theoretical questions related to values and data types in Java, covering topics such as primitive data types, operators, and string manipulation methods. It includes 12 multiple choice questions, 8 numerical questions, and 15 theoretical questions, focusing on Java programming concepts. The questions are designed to test knowledge and understanding of Java's data handling capabilities.
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)
6 views6 pages

35 Marks Paper

The document contains multiple choice, numerical, and theoretical questions related to values and data types in Java, covering topics such as primitive data types, operators, and string manipulation methods. It includes 12 multiple choice questions, 8 numerical questions, and 15 theoretical questions, focusing on Java programming concepts. The questions are designed to test knowledge and understanding of Java's data handling capabilities.
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/ 6

Values and Data Types - Java

Multiple Choice Questions (Total: 12 marks) (0.5 marks each)

1. Which of the following is not a primitive data type in Java?


A. int
B. String
C. char
D. Boolean
2. What is the size of a float in Java?
A. 4 bytes
B. 2 bytes
C. 8 bytes
D. Depends on the platform
3. 3. Which data type should you use to store a value like 9876543210 in Java?
A. int
B. short
C. long
D. double
4. 4. What is the default value of a boolean variable in Java (for class-level variables)?
A. true
B. false
C. 0
D. null
5. 5. What will 10 / 3 return in Java if both are int values?
A. 3.33
B. 3
C. 4
D. Error
6. What will be the output?
int x = 5;
double y = 2;
System.out.println(x / y);
Answer: Output is =

7. Which operator is used to compare two values in Java?

8. What will be the result of the following code?

char c = 65;

System.out.println(c);
Values and Data Types - Java

9. Predict the output:

boolean flag = (10 > 5) && (5 < 2);

System.out.println(flag);

10. What is the output?

System.out.println(10 + 20 + "Hello" + 30 + 40);

11. Default value, maximum and minimum value of Byte, Short, int, long, float, double
data types

12. Define Expressions in Java

13. Give example of shorthand operator

14. Which of these is a bitwise operator?


(a) &&
(b) ||
(c) &
(d) and

15. What will Math.ceil(4.3) return?


(a) 4.0
(b) 5.0
(c) 4
(d) 5

16. Which method returns the absolute value of a number in Java?

(a) Math.max()

(b) Math.round()

(c) Math.abs()

(d) Math.sqrt()

17. What is the output of Math.round(3.6)?


(a) 3
(b) 4
(c) 3.0
(d) 4.0
Values and Data Types - Java

18. Which method is used to return the square root of a number?

(a) Math.pow()

(b) Math.floor()

(c) Math.sqrt()

(d) Math.exp()

19. What does Math.random() return?

(a) Integer between 0 and 1

(b) Float between 0 and 1

(c) Double between 0.0 and 1.0

(d) Boolean value

20. What will Math.pow(2, 3) return?


(a) 6
(b) 8
(c) 9
(d) 4
21. What will "Hello".charAt(1) return?
(a) 'H'
(b) 'e'
(c) 'l'
(d) 'o'
22. What does the method substring(2, 5) return for string "Programming"?
(a) "gram"
(b) "ogr"
(c) "ogr"
(d) "ogr"
23. Which method is used to find the length of a string?
(a) length()
(b) size()
(c) getLength()
(d) count()
24. What is the result of "Java".concat("Programming")?
(a) "Java Programming"
(b) "JavaProgramming"
(c) "Java+Programming"
(d) "Java Programming"
Values and Data Types - Java

Numerical Questions (Total: 8 marks) (1 mark each)

a. What will be the output/result of the


following?
int a = 8, b = 12, c = 5;
int result = ++a * b-- - c++ + --b +
a-- * ++c;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("result = " + result);

b. Predict the output:


int x = 7;
x *= 2 +
3;
System.out.println(x);

c. What is the result of:


System.out.println(10 >> 2);
System.out.println((5 > 3) && (8 < 5));

d. Output of this expression:


int a = 5;
a += a++ + ++a;
System.out.println(a);

e. Write a Java Math expression for:


sqrt{(5^2 + 12^2)}

f. Write the Java Math expression to compute:


((2)2)1/2

g . Output of the following?


System.out.println(10 >> 2);

h.What will be the output of "Hello World".indexOf('o');


Values and Data Types - Java

Non-Numerical (Theory) Questions (Total: 15 marks) (1 mark each)

a. Define a data type. What are the two broad categories of data types in Java?

b. Explain the difference between == operator and .equals() method in Java.

c. List all 8 primitive data types in Java with their sizes.

d. Explain the difference between == and = operators in Java.

e. Describe types of variable in Java?

f. Difference between Declaration and Initialization of variables

g. Difference between constants and variables

h. Define Built in data types

i. List all arithmetic operators in Java and give one example for each.

j. What does the trim() method do in Java strings? Provide an example.

k. What are different types of operators? Explain with two examples.

l. Difference between Print() and Println()

m. Define concatenation with code example

n. Give example of Ternary Operator

o. List any four string manipulation methods in Java and explain their purpose.
Values and Data Types - Java

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