[go: up one dir, main page]

0% found this document useful (0 votes)
2 views11 pages

Java Question

The document contains a comprehensive set of Java-related questions designed for information technology students, covering various topics such as Java programming concepts, syntax, and features. Each question includes multiple-choice answers, testing knowledge on subjects like Java keywords, operators, data types, and memory management. The questions aim to assess the understanding of Java fundamentals and object-oriented programming principles.

Uploaded by

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

Java Question

The document contains a comprehensive set of Java-related questions designed for information technology students, covering various topics such as Java programming concepts, syntax, and features. Each question includes multiple-choice answers, testing knowledge on subjects like Java keywords, operators, data types, and memory management. The questions aim to assess the understanding of Java fundamentals and object-oriented programming principles.

Uploaded by

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

Java questions for information technology students

1. Who is known as father of Java Programming Language?


A. James Gosling C. Charel Babbage
B. M. P Java D. Blais Pascal
2. In java control statements break, continue, return, try-catch-finally and assert
belongs to?
A. Selection statements C. Transfer statements
B. Loop Statements D. Pause Statement

3. Which provides runtime environment for java byte code to be executed?


A. JDK C. JRE
B. JVM D. JAVAC
4. What is byte code in Java?
A. Code generated by a Java compiler
B. Code generated by a Java Virtual Machine
C. Name of Java source code file
D. Block of code written inside a class
5. Which of the following are not Java keywords?
A. double C. then
B. switch D. instanceof
6. Which of these have highest precedence?
A. () C. *
B. ++ D. >>

7. Which of these is returned by operator '&’?


A. Integer C. Boolean
B. Character D. Float
8. Data type long literals are appended by _____
A. Uppercase L C. Long
B. Lowercase L D. Both A and B
9. Which variables are created when an object is created with the use of the keyword
'new' and destroyed when the object is destroyed?
A. Local variables C. Class Variables
B. Instance variables D. Static variables
10. Java language was initially called as ________
A. Sumatra C. Oak
B. J++ D. Pine
11. What is garbage collection in the context of Java?
A. Java deletes all unused java files on the system.
B. Memory used by the object with no reference is automatically reclaimed.
C. The JVM cleans output of Java program with error.
D. Any unused package in a program automatically gets deleted.
12. Which one is a template for creating different objects?
A. An Array C. Interface
B. A class D. Method

13. Which symbol is used to contain the values of automatically initialized arrays?
A. Brackets C. Parentheses
B. Braces D. Comma
Java questions for information technology students

14. Which one is true about a constructor?


A. A constructor must have the same name as the class it is declared within.
B. A constructor is used to create objects.
C. A constructor may be declared private
D. All of the above
15. Which of these operators is used to allocate memory to array variable in Java?
A. alloc C. new malloc
B. malloc D. new
16. Who invented Java Programming?
a) Guido van Rossum c) Dennis Ritchie
b) James Gosling d) Bjarne Stroustrup
17. Which statement is true about Java?
a) Java is a sequence-dependent programming language
b) Java is a code dependent programming language
c) Java is a platform-dependent programming language
d) Java is a platform-independent programming language
18. Which component is used to compile, debug and execute the java programs?
a) JRE c) JDK
b) JIT d) JVM

19. Which one of the following is not a Java feature?


a) Object-oriented c) Portable
b) Use of pointers d) Dynamic and Extensible

20. Which of these cannot be used for a variable name in Java?


a) Identifier & keyword c) keyword
b) identifier d) none of the mentioned

21. What is the extension of java code files?


a) .js c) .class
b) .txt d) .java

22. What will be the output of the following Java code?


1. class increment {
2. public static void main(String args[])
3. {
4. int g = 3;
5. System.out.print(++g * 8);
6. }
7. }
a) 32 c) 24
b) 33 d) 25
23. Which environment variable is used to set the java path?
a) MAVEN_Path c) JAVA
b) JavaPATH d) JAVA_HOME

24. What will be the output of the following Java program?


1. class output {
2. public static void main(String args[])
Java questions for information technology students
3. {
4. double a, b,c;
5. a = 3.0/0;
6. b = 0/4.0;
7. c=0/0.0;
8.
9. System.out.println(a);
10. System.out.println(b);
11. System.out.println(c);
12. }
13. }
a) NaN c) 0.0
b) Infinity d) all of the mentioned
25. Which of the following is not an OOPS concept in Java?
a) Polymorphism c) Compilation
b) Inheritance d) Encapsulation

26. What is not the use of “this” keyword in Java?


a) Referring to the instance variable when a local variable has the same name
b) Passing itself to the method of the same class
c) Passing itself to another method
d) Calling another constructor in constructor chaining
27. What will be the output of the following Java program?
1. class variable_scope
2. {
3. public static void main(String args[])
4. {
5. int x;
6. x = 5;
7. {
8. int y = 6;
9. System.out.print(x + " " + y);
10. }
11. System.out.println(x + " " + y);
12. }
13. }
a) Compilation error c) 5 6 5 6
b) Runtime error d) 5 6 5
28. What will be the error in the following Java code?
byte b = 50;
b = b * 50;
a) b cannot contain value 50
b) b cannot contain value 100, limited by its range
c) No error in this code
d) * operator has converted b * 50 into int, which cannot be converted to byte without casting
29. Which of the following is a type of polymorphism in Java Programming?
a) Multiple polymorphism c) Multilevel polymorphism
b) Compile time polymorphism d) Execution time polymorphism
30. What will be the output of the following Java code?
class box
Java questions for information technology students
{
int width;
int height;
int length;
}
class main
{
public static void main(String args[])
{
box obj = new box();
obj.width = 10;
obj.height = 2;
obj.length = 10;
int y = obj.width * obj.height * obj.length;
System.out.print(y);
}
}
a) 100 c) 200
b) 400 d) 12
31. What is Truncation in Java?
a) Floating-point value assigned to a Floating type
b) Floating-point value assigned to an integer type
c) Integer value assigned to floating type
d) Integer value assigned to floating type

32. What will be the output of the following Java program?


class Output
{
public static void main(String args[])
{
int arr[] = {1, 2, 3, 4, 5};
for ( int i = 0; i < arr.length - 2; ++i)
System.out.println(arr[i] + " ");
}
}
a) 1 2 3 4 5 c) 1 2
b) 1 2 3 4 d) 1 2 3
33. What will be the output of the following Java code snippet?
class abc
{
public static void main(String args[])
{
if(args.length>0)
System.out.println(args.length);
}
}
a) The snippet compiles and runs but c) The snippet compiles, runs and
does not print anything prints 1
b) The snippet compiles, runs and d) The snippet does not compile
prints 0
Java questions for information technology students
34. Which exception is thrown when java is out of memory?
a) MemoryError c) MemoryOutOfBoundsException
b) OutOfMemoryError d) MemoryFullException
35. What will be the output of the following Java code?
class String_demo
{
Public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
System.out.println(s);
}
}
a) abc c) b
b) a d) c
36. Which of these are selection statements in Java?
a) break c) for()
b) continue d) if()

37. What will be the output of the following Java code?


class output
{
public static void main(String args[])
{
String c = "Hello i love java";
boolean var;
var = c.startsWith("hello");
System.out.println(var);
}}
a) 0 c) 1
b) true d) false
38. Which of these keywords is used to define interfaces in Java?
a) intf c) interface
b) Intf d) Interface
39. What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Quiz");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}
a) QuizziuQ c) Quiz
b) ziuQQuiz d) ziuQ
40. What will be the output of the following Java program?
class Output
{
public static void main(String args[])
Java questions for information technology students
{
double x = 2.0;
double y = 3.0;
double z = Math.pow( x, y );
System.out.print(z);
}}
a) 9.0 c) 4.0
b) 8.0 d) 2.0
41. 41. Which of the following are not Java keywords?
A. double C. then
B. switch D. instanceof
42. Division operator has ____ precedence over multiplication operator
A. Highest C. Equal
B. Least D. None of These
43. Java program processing always starts with main() method
A. True B. False

44. Which of the following below live on the heap in java?


A. Class
B. Instance variable
C. Method
D. Object
45. Which of the following interface is used to declare core methods in java?

A. Set C. Collection
B. EventListner D. Comparator

46. Which of these interfaces handle sequences?

A. Set C. Comparator
B. List D. Collection
47. Which of this interface must contain a unique element?
A. Set C. Array
B. List D. Collection

48. Which of the following declarations does not compile?


A. double num1, int num2 = 0; C. int num1, num2 = 0;
B. int num1, num2; D. int num1 = 0, num2 = 0;

49. What is the value of tip after executing the following code snippet?
int meal = 5;
int tip = 2;
int total = meal + (meal>6 ? ++tip : --tip);

A. 1 C. 3
B. 2 D. 6
Java questions for information technology students

50. JDK stands for ____.


A. Java development kit C. JavaScript deployment kit
B. Java deployment kit D. None of these
51. JRE stands for ___.
A. Java run ecosystem C. Java Runtime Environment
B. JDK runtime Environment D. None of these
52. What makes the Java platform independent?
A. Advanced programming language C. Class compilation
B. It uses bytecode for execution D. All of these

53. Can we keep a different name for the java class name and java file name?
A. Yes B. No

54. Multiline comment is created using ___.

A. // C. <!-- -- >
B. /* */ D. All of these
55. What is the entry point of a program in Java?
A. main() method C. Last line of code
B. The first line of code D. main class

56. Which keyword in java is used for exception handling?

A. exep C. throw
B. excepHand D. All of these
57. Which class in Java is used to take input from the user?
A. Scanner C. Applier
B. Input D. None of these

58. Method used to take a string as input in Java?


A. next() C. Both A. and B.
B. nextLine() D. None of these
59. Which of these is a type of variable in Java?
A. Instance Variable C. Static Variable
B. Local Variable D. All of these
60. What will be the output of following Java code?
public class Main {
public static void main(String[] args) {
String str = "Hello";
str = "Bye";
System.out.println(str);
}
}
A. Hello C. Error
B. Bye D. All of these
Java questions for information technology students
61. What is type casting in Java?
A. It is converting type of a variable C. Creating a new variable
from one type to another D. All of these
B. Casting variable to the class
62. Which type of casting is lossy in Java?
A. Widening typecasting C. Manual typecasting
B. Narrowing typecasting D. All of these

63. Which of the following can be declared as final in java?


A. Class C. Variable
B. Method D. All of these
64. Finally block is attached to?
A. Try-catch block C. Method block
B. Class block D. All of these

65. The break statement in Java is used to ___.


A. Terminates from the loop C. Skips the current iteration
immediately D. All of these
B. Terminates from the program
immediately

66. What will be the output of following Java code?


public class Main {
public static void main(String arg[]) {
int i;
for (i = 1; i <= 12; i += 2) {
if (i == 8) {
System.out.println(i);
break;
}
}
}
}

A. 1 C. 8
B. No output D. 1357911
67. Array in java is ___.
A. Collection of similar elements C. The data type of consisting of
B. Collection of elements of different characters
types D. None of these
68. Which of these is the correct method to
create an array in java?
A. int[] arr = {1, 3, 5}; D. int arr[] = {1, 4, 6};
B. int[] arr; E. All of these
C. arr = new int[] {3, 1, 8};
69. Object in java are ___.
A. Classes C. Iterators
B. References D. None of these
Java questions for information technology students

70. What is garbage collection in java?

A. Method to manage memory in java C. Delete all values


B. Create new garbage values D. All of these
71. Static variables in java are declared as ___.
A. final variables C. Constants
B. new variables D. All of these
72. 'this' keyword in java is ___.
A. Used to hold the reference of the current C. Used to create a new instance
object D. All of these
B. Holds object value
73. What will be the output of following Java code?
import java.util.Scanner;

class ThisKeyword {
private int a = 4;
private int b = 1;

void getSum(int a, int b) {


this.a = a;
this.b = b;
System.out.println(this.a + this.b);
}
}

public class Main {


public static void main(String args[]) {
ThisKeyword T = new ThisKeyword();
T.getSum(3, 5);
}
}
A. 5 C. 8
B. 9 D. 4
74. The 'super' keyword is used to ___.
A. Access instance of the parent class C. Access instance of child class
B. Access instance of the same class D. Access instance of friend class
75. The super() method is used to ___.
A. Call constructor of friend class C. Call constructor of the parent class
B. Is a declared method D. Call constructor
76. Wrapper class in java is ___.
A. Used to encapsulate primitive data types C. Create a new instance of the class
B. Declare new classes called wrapper D. None of these
77. bstract class is ___.
A. Created using abstract keyword C. Needs to be inherited to be used
B. Contains only abstract method D. All of these
Java questions for information technology students

78. What is file handling in java?


A. It is creating, deleting, and modifying files using a java program.
B. Creating new method
C. Filing method to different file to extract them better
D. All of these
79. How can we access methods for file handling in java?
A. Java.files C. Java.io.File
B. Java.io D. Java.FileHandling
80. Which method is used to add a new line to file in Java?
A. file.addLine() C. file.write()
B. file.nextLine() D. file.line()
81. Which method deletes a file in Java?
A. file.delete() C. file.garbage()
B. file.remove() D. file.dump()
82. Which method in java is used to read lines from file?
A. file.read() C. file.getLine()
B. file.nextLine() D. All of these
83. The correct syntax to import the math library in java is ___.
A. import java.lang.math C. import java.math
B. import math D. All of these
84. Which is/are valid method(s) of math library in java?
A. max() C. log10()
B. cbrt() D. All of these
85. Which method in java is used to generate random numbers in Java?
A. random.nextInt() C. rand()
B. random() D. All of these
86. In java, recursion is ___.
A. Method C. The process to call methods
B. A process allowing methods to call D. None of these
itself
87. Which of the following is a valid data structure in java?
A. Array C. Vector
B. List D. All of these
88. What is a comparator in Java?
A. Interface to compare integer C. Interface to compare two objects in java
B. Comparison method for lists D. All of these
89. What will be the output of following Java code?
public class Main {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("include");
sb.append("help");
System.out.println(sb);
}
}
A. Error C. help
B. include D. Includehelp
90. What is a deadlock in Java?
A. State when all processes have complete working and are dead
B. State when threads are in hold state forever
Java questions for information technology students
C. State when threads are not ready
D. All of these
91. Null in Java is ___.
A. Reserved keyword C. Used in exception handling
B. Literal value D. All of the above
92. Which keyword is used to inherit classes in Java?
A. extends C. isChild
B. inheritance D. None of these
93. What is boolean in Java?
A. A value consisting of only true and false C. Truthy value in java
value D. All of these
B. A value consisting of 8 values
94. Multithreading in java is ___.
A. Executing multiple processes C. Blocking threads
simultaneously D. All of these
B. Creating more threads at a time
95. Which of the following methods is used to extract the length of a string in Java?
A. length() C. sizeof()
B. len() D. size()
96. What is a set in Java?
A. Represented in the form of values C. Primary structures
B. Used to store key-value pairs D. All of these
97. Which Java method is used to clear element of ArrayList?
A. deleteAll() C. clearAll()
B. delete() D. clear()

98. Which Java keyword is used to access features of a package?


A. get C. extends
B. import D. All of these
99. What will be the output of following Java code?
public class ConcatNull {
public static void main(String[] args) {
String str1 = "include";
String str2 = "help";
System.out.println(str1 + str2);
}
}
A. includehelp C. help
B. include D. None of these
100. What is the full form of AWT?
A. Absolute window toolKit C. Absolute wear kit
B. Abstract window toolKit D. Abstract window tools

You might also like