NEW
Font size
WorksheetsJava - Primitive Type
Total questions: 23
Worksheet time: 17mins
Which of the following is NOT a data types in java
int
String
number
double
What is right way of defining String variable?
String name = "John";
String name = "John"
String name = John;
String name "John";
float myFloatNum = 5.99f;
System.out.println(myFloatNum);
What will be the output?
5.99
5.99f
"5.99"
"5.99"f
int x = 5;
int y = 6
int z = 50;
System.out.println(x + y + z);
What will be the output?
61
5650
66
x + y + z
Which of the following are Java features?
Object- oriented programming
Class- based programming
Bytecode is platform independent
All of above
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) { }
(=) sign means
equals and it is used for math problems in Java
assignment operator. It used to assign a value
char is 2 byte in storage?
True
False
Long is 4 byte size in storage?
True
False
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 of the following is NOT safe and can result in a loss of data?
Narrowing primitive
Widening primitive
This data type returns true or false
String
boolean
char
int
Name the data type: 1.0
double
int
char
boolean
Is String a primitive data type?
Yes
No
Both
Which method to use to find length of a string?
length()
size()
long()
count()
Which data type gets returned from length() method in String class?
double
String
int
number
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
Which is correct method to convert String into uppercase
changeUpperCase()
convertUpperCase()
toUpper()
toUpperCase()
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
Choose correct purpose of indexOf() in String class.
returns the index (the position) of the last occurrence of a specified text in a string
returns the character of the first occurrence of a specified character in a string
returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)
returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)
String x = "10";
String y = "20";
String z = x + y;
System.out.println(z);
Guess the output.
1020
10 20
30
"10 20"
