0% found this document useful (0 votes)
36 views

java

Uploaded by

Dipali Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

java

Uploaded by

Dipali Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 9

Fundamentals of Java Class 11 MCQ

1. NetBeans is an IDE using which we can develop ___________ in Java.


a. GUI application
b. CUI application
c. BW application

Answer ⟶ a. GUI application


d. None of the above

2. NetBeans provides various components used to create a GUI front-end interface like
___________.
a. jTextArea
b. jLabel
c. jButton

Answer ⟶d. All of the above


d. All of the above

3. GUI components’ __________ is controlled by their properties and methods.


a. Appearance
b. Behavior
c. Both a) and b)

Answer ⟶c. Both a) and b)


d. None of the above

4. We should use meaningful names for controls on the _________ in the code. It makes
programming convenient.
a. Form
b. Variables
c. Both a) and b)

Answer ⟶c. Both a) and b)


d. None of the above

5. Some useful Data Types supported in Java are ___________.


a. Int & Boolean
b. Double
c. Char

Answer ⟶d. All of the above


d. All of the above

6. String is an _________ type supported in Java.


a. Object
b. Constraint
c. Class

Answer ⟶a. Object


d. None of the above

7. A variable must be declared _____________.


a. After it can be used
b. Between it can be used
c. Before it can be used

Answer ⟶c. Before it can be used


d. None of the above
8. What are the different operators used in Java _________.
a. Logical Operator
b. Conditional Operator
c. Comparison Operator

Answer ⟶d. All of the above


d. All of the above

9. The __________ selects among a set of statements depending on the value of a controlling
expression.
a. If Statement
b. For Statement
c. While Statement

Answer ⟶a. If Statement


d. None of the above

10. If else statement is also known as ________.


a. Control statement
b. Structure statement
c. Program statements

Answer ⟶a. Control statement


d. All of the above

11. An IF statement in Java is also a _______ statement.


a. Number
b. conditional
c. String

Answer ⟶b. conditional


d. None of the above

12. In Java, an ELSE statement needs to come after a _________ statement.


a. IF
b. ELSE IF
c. IF or ELSE IF

Answer ⟶c. IF or ELSE IF


d. None of the above

13. It is required to define an IF statement code between two braces.


a. False
b. True
c. Some time True and Some time False

Answer ⟶a. False


d. None of the above

14. An ELSE statement’s code may be enclosed in braces.


a. FALSE
b. TRUE
c. Some time True and Some time False

Answer ⟶b. TRUE


d. None of the above

15. Without an IF statement, an ELSE or ELSE-IF statement in Java cannot occur.


a. FALSE
b. TRUE

Answer ⟶b. TRUE


c. Some time True and Some time False d. None of the above

16. if the condition is false in if condition, which of the following will be true.
a. IF Statement will be executed
b. ELSE Statement is executed.
c. IF and ELSE both will not execute.

Answer ⟶b. ELSE Statement is executed.


d. IF and ELSE both will execute.

17. How many lines of code can be written inside an IF, ELSE, or IF-ELSE block in Java?

Answer ⟶d. None of the above


a. 25 b. 72 c. 105 d. None of the above

18. In which of the following situations is an IF-ELSE statement preferable to a SWITCH


statement?
a. Checking multiple condition
b. Checking for Less-than condition
c. Checking for Ranges

Answer ⟶d. All of the above


d. All of the above

19. How many ELSE-IF statements can be present between the beginning IF and the closing ELSE
statements?

Answer ⟶d. None of the above


a. 44 b. 55 c. 320 d. None of the above

20. Select the proper Java IF statement syntax from the list below.
a. if(condition) //statement
b. if(condition){ //statement}
c. if(condition){ //statement1 //statement2}

Answer ⟶d. All of the above


d. All of the above

21. What does the Java programme with IF-ELSE statements produce?
if(TRUE)
System.out.println(“True”);
else
System.out.println(“False”);
a. True
b. False
c. Compiler error

Answer ⟶c. Compiler error


d. None

22. What is the output of the Java program?


int a=10;
if(a==9)
System.out.println(” My “);
System.out.println(“School”);
else
System.out.println(“My Class”);
a. My School
b. My Class
c. Compiler error

Answer ⟶c. Compiler error


d. None of the above

30. Java is a ______ programming language.


a. Procedure Oriented
b. Object-Oriented
c. Practical

Answer ⟶b. Object-Oriented


d. All of the above

31. The code in the Java programming language is put inside ___________.
a. Blocks
b. Methods
c. Classes, Interfaces

Answer ⟶d. All of the above


d. All the above

32. What file extension is associated with the Java class source code?
a. .jpp
b. .jsp
c. .java

Answer ⟶c. .java


d. None of the above

33. What file extension is associated with compiled Java class files?
a. .jpp
b. .java
c. .class

Answer ⟶c. .class


d. .clear

34. In Java, the keyword used to declare a class is _________.


a. Function
b. Method
c. class

Answer ⟶c. class


d. Java

35. A Java class can contain___________.


a. Variables
b. Methods, Constructors
c. Inner Classes (A class inside another class)

Answer ⟶d. All of the above


d. All of the above

36. In Java, the word ________ is used to create a new object.


a. java
b. new
c. class

Answer ⟶b. new


d. function

37. In Java, an object is created at _________ time.


a. Assembling time
b. Run time
c. Compile-time

Answer ⟶b. Run time


d. None of the above

Que 1. What is Computer Program?


Answer: A computer program is a sequence of instructions given to the computer in order to accomplish a
specific task. The instructions tell the computer what to do and how to do it.
Que 2. Give the example of five high-level programming languages.
Answer: Java, C++, Python, Ruby or Scala.
Que 3. Which language does a computer understand?
Answer: Machine Language
Que 4. What is a Compiler?
Answer: Compiler is a language processor which translates high-level language to machine language code that a
computer can understand.
Que 5. What is Java?
Answer: Java is a High-Level Object-Oriented programming language and has been used widely to create various
types of computer applications such as database applications, desktop applications, Web-based applications,
mobile applications, and games among others.
Que 6. What is Java Compiler?
Answer: A Java compiler that translates Java Source Code into Java Bytecode (a highly optimized set of
instructions). Like other language compilers (c, c++), it does not translate Java code to machine language code.

Que 7. What is Java Interpreter / JVM?


Answer: Java Interpreter is known as JVM (Java Virtual Machine). Java Interpreter translates the Java bytecode
into to the respective machine code as per the operating system and then executes it.

Que 8. What is the need of JVM? [SQP]


Answer: When the bytecode (also called a Java class file) is to be run on a computer, a Java interpreter, called the
Java Virtual Machine (JVM), translates the bytecode into machine code and then executes it.

Que 9. Why java is platform independent and portable? [CBSE 2018]


Answer: The advantage of JVM is that once a programmer has compiled a Java program into bytecode, it can be
run on any platform (say Windows, Linux, or Mac) as long as it has a JVM running on it. This makes Java
programs platform independent and highly portable.
Que 10. Write the full from of IDE? What is IDE?
Answer: IDE stands for Integrated Development Environment. IDE is an integrated development environment,
which combines the text editor and java compiler. It simplifying writing, compiling and executing java programs.
Que 11. Give one example of IDE.
Answer: Java NetBeans IDE.
Que 12. What is comment? How many ways you write comment in java?
Answer: Comments are non-executable statement, are used in code to document the program. Especially useful
for writing the purpose of the program, so that anyone can understand it.
Comments are used for enhancing the readability of code and are ignored by the compiler when compiling a file.
You can write comments in a Java program in the following two ways:
(a) Beginning a comment line with two consecutive forward slashes (//)
(b) Writing the comment between the symbols /* and */

Que 13. How can you write single-line comments in java?


Answer: In Java single-line comment can be written by using // at the beginning of line. For example
// this is a single-line comment

Que 14. How can you write multiline comments in java program?
Answer: In Java, the multi-line comment can be written by /* ….. */. You need to start the comment by /* and
end by */.
For example:
/* This is an
example of
a multiline comment. */
Que 15. What is package?
Answer: A package in java is a group of related classes. All classes in a package can share their data and code.
Package declaration statement is the first statement in the java program.
package MyJavaProgram ;
Que 16. Why main() is special method of java?
Answer: main() function is very important component of java application program, because the execution of
program is always started from the main() function.

Que 17. Which function is used to print the statement?


Answer: println() and print() function of java is use to print the message and value of variable.

Que 18. Differentiate between System.out.print( ) and System.out.println().


Answer: System.out.print() is print the message and leave the cursor in the same line,
while System.out.println() is print the message and move the cursor to the next line.

Que 19. Expand IDE. Name any one open source IDE for writing Java programs.
Answer: IDE stands for Integrated Development Environment.
Open Source IDE for writing Java Program – NetBeans, Eclipse, IntelliJ IDEA, Code::Blocks, etc.

Que 20. Which symbol is used in jave at the end of the statement?
Answer: The semicolon ; at the end of the statement. All Java statements must end with a semicolon.

Que 21. Define JVM. [SQP]


Answer: Java Virtual Machine (JVM), translates the bytecode into machine code and then executes it.

Que 22. What are comment entries in Java? Mention two ways to give comments. [SQP]
Answer: Comments are used in code by programmers to document their programs – to provide explanatory notes
to other people who read the code. This is especially useful in the real world, where large programs are written by
one programmer and maintained by other programmers.
Beginning a comment line with two consecutive forward slashes (//)
Writing the comment between the symbols /* and */
Que 23. Why Java program is platform independent? [SQP}
Answer: A Java compiler instead of translating Java code to machine language code, translates it into Java
Bytecode. A Java interpreter, called the Java Virtual Machine (JVM), translates the bytecode into machine code
and then executes it. The bytecode can be run on any platform as long as it has a JVM running on it. This makes
Java programs platform independent and highly portable. (keywords bytecodes and JVM to be included)

Que 24. How can you write multiline comments in java program? [SQP]
Answer: Writing the comment between the symbols /* and */

Que 25. Why main is a special method in the java program? [SQP]
Answer: Main is a special method that every Java application must have. When you run a program, the
statements in the main method are the first to be executed

Que 26. Why a Compiler is needed?


Answer: As you are already aware, a computer only understands its own language called “machine language”.
Therefore, a compiler is needed to translate high level program code into machine language code that will be
understood by the computer.
Que 27. Why we need to compile a program on every platform like Windows or Mac before execution of
Program?
Answer: All platform/OS (windows, Mac) has different instruction sets, compiler is always generating the
executable code as per platform. So it is required to compile every program before execution on each platform
separately.
Que 28. What is the extension of Java Program File?
Answer: .java
Que 29. What is the extension of Java Bytecode File or Class File?
Answer: .class
Que 30. What is method?
Answer: A method is a group of statements written to perform a specific task. The method body is enclosed
within a pair of curly braces and contains the statements that the method will execute.
Que 31. What is the error in the given statement?
SystemOUT.println(“Hello world”);
Answer: OUT must be ‘out’, and a dot (.) will come between System and out. The correct code is –
System.out.pirntln(“Hello World”);

Que 32. What is the error in the given statement?


System.out.println(“Hello world”)
Answer: Missing of semicolon at the end of the statement.
In java every statement must be terminated with semicolon. The correct code is –
System.out.pirntln(“Hello World”);
Que 33. What is the error in the given statement?
System.out.printl(‘Hello world’)
Answer: (i) printl() is not a valid function name, it should be println(), to print the line and move the cursor to
the new line.
(ii) Single quote ‘’ is used for character constant, So Hello World must be enclosed with double quotes. “”.
System.out.pirntln(“Hello World”);
Que 34. Is Java a case sensitive language? Justify your answer. [CBSE 2019]
Answer: Yes, Java is a case sensitive language.
In java, ‘A’ and ‘a’ both values are treated as different because both have different ASCII / UNICODE value.
Que 35. Write any three applications where java is used. [CBSE 2017 COMPT]
Answer: Three applications are – Database applications, Desktop applications,
Web based applications, Mobile applications, and Games, etc.
Que 36. Expand IDE. Name any one open source IDE for writing Java programs.
Answer: IDE stands for Integrated Development Environment.
Open Source IDE for writing Java Program – NetBeans, Eclipse, IntelliJ IDEA, Code::Blocks, etc.
Que 37. Write any four best features of Java. [CBSE 2019 COMPT]
Answer: Four best features of Java are: –
(a) Simple
(b) High Level Object Oriented Programming Language
(c) Highly Portable
(d) Platform Independent
(e) Secured Language
(f) Architectural Neutral (g) Robust

Q1. What is Java Bytecode?

Answer: Bytecode is a java compiled code, which translated by java compiler from java source code to java
bytecode. Java Bytecode is a highly optimized set of instructions. Bytecode is also known as Java class file.
When the bytecode is to be run on a computer, a Java interpreter, called the Java Virtual Machine (JVM),
translates the bytecode into machine code and then executes it.
The advantage of such an approach is that once a programmer has compiled a Java program into bytecode, it can
be run on any platform (say Windows, Linux, or Mac) as long as it has a JVM running on it. This makes Java
programs platform independent and highly portable.

Q2. Explain the difference between a Class and an Object with an example.

Answer: Class :- A class is a physical or logical entity that has certain attributes, known as Data members and
Method members to get, set or update the class data members.
For Example Book is a Class which has title, author, publisher, genre and price as the data members and
display_details(), getPrice(), setPrice() etc, are the Member methods.
Objects:- Object is the instance of class i.e. implementation of class physically. Each object has their own data
members. To implement the class we need to create instance of class i.e. variable of class type is called object.
A class as a template from which objects are created.
All objects of the same class have the same type of data members.
Method members of a class are invoked on an object to perform the action associated with that method.

Q3. What is a constructor? Why is it used?

Answer: Constructor is a special method member of class, which is used to initialize the data members of the
class, when you create the instance of class.
Properties of Constructor:
The constructor has the same name as the class.
It has no return type, and
It may or may not have a parameter list.
Whenever a new object of a class is created, the constructor of the class is invoked automatically.
We do not call the constructor explicitly.

Q4. How are exceptions handled in Java?

Answer: Exception is an error situation that is unexpected in the program execution and cause it to terminate
unexpectedly. To avoid this condition, you need to handle the exception properly.
To handle the exceptions in Java, you need to use try .. catch block. The basic idea in exception handling is
to –Denote an exception block – Identify areas in the code where errors can occur
Catch the exception – Receive the error information
Handle the exception – Take corrective action to recover from the error

Java provides the following keywords to handle an exception:

try – A try block surrounds the part of the code that can generate exception(s).
catch – The catch blocks follow a try block. A catch block contains the exception handler – specific code that is
executed when the exception occurs. Multiple catch blocks following a try block can handle different types of
exceptions.
finally – The optional finally block is always executed when the try block exits. This means the finally block is
executed whether an exception occurs or not.
Note:- Programmers use this block to put in clean up code, for example, freeing up resources allocated in the try
block.

The structure of a try-catch statement block for exception handling is as below:

try {
// Part of the program where an exception might occur
}
catch (exceptiontype1 argument1) {
// Handle exception of the exceptiontype1
}
catch (exceptiontype2 argument2) {
// Handle exception of the exceptiontype2
}
finally {
//Code to be executed when the try block exits
}

Q5. How can threads be created in Java? Briefly explain with an example.

Answer: A multithreaded program is one that can perform multiple tasks concurrently so that there is optimal
utilization of the computer’s resources. A multithreaded program consists of two or more parts called threads each
of which can execute a different task independently at the same time.

In Java, threads can be created in two ways

By extending the Thread class


By implementing the Runnable interface

You might also like