NEW
Font size
WorksheetsJava Programming Quiz
Total questions: 50
Worksheet time: 50mins
Which of the following ensures memory safety and prevents pointer manipulation in Java?
Garbage Collection
JVM Loader
Preprocessor
Bytecode Compiler
Which statement is TRUE about Java’s platform independence?
Java compiler generates native machine code
Java programs depend on OS
Bytecode is executed by JVM on any platform
Java is interpreted line by line
Which of the following identifiers is invalid in Java?
$student
_count
class
totalValue
Which naming convention follows Java standards for variables?
EmployeeName
employee_name
employeeName
Employee_name
What will be the output of System.out.println(10/3);?
3.3333
3
3.0
Compile Error
Which primitive type takes the least memory?
byte
short
int
char
Which of these is a valid floating literal in Java?
3.14f
3,14
.14d
14.
What does the literal 0b1010 represent?
Octal
Binary
Decimal
Hexadecimal
What will x = 5; System.out.println(x++ + ++x); print?
10
12
11
13
Which operator has the highest precedence?
&&
*
==
+
How many elements does new int[5] create?
4
5
6
Undefined
What is the result of accessing an array out of bounds?
0
null
ArrayIndexOutOfBoundsException
Runtime reset
What is printed by: String s1 = "Java"; String s2 = new String("Java"); System.out.println(s1 == s2);
true
false
null
Compile Error
Which method converts all characters in a string to uppercase?
toUpper()
upperCase()
toUpperCase()
setUpperCase()
Which class provides thread-safe operations?
String
StringBuffer
StringBuilder
CharSequence
Output of:
StringBuilder sb = new StringBuilder("Hi");
sb.append("Java");
System.out.println(sb);
Hi
Java
HiJava
Compile Error
Which of the following can be overloaded but not overridden?
Methods
Constructors
Variables
Interfaces
If no constructor is defined in a class:
Compiler throws an error
Compiler provides a default constructor
Object cannot be created
JVM crashes
Which of the following can a constructor call using this()?
Another constructor in the same class
Static method
Parent constructor directly
Instance variable
Constructors cannot be:
Private
Final
Overloaded
Parameterized
Which of these can be overloaded in Java?
Methods only
Constructors only
Both methods and operators
Only static methods
Which keyword allows one method to call another of the same class?
super
this
return
call
If class B extends class A, which executes first during object creation?
Constructor of A
Constructor of B
Static block of B
None
Which keyword calls the parent class constructor explicitly?
super()
parent()
base()
this()
Method overriding is an example of:
Compile-time polymorphism
Runtime polymorphism
Static binding
Overloading
Which keyword prevents a method from being overridden?
static
final
const
abstract
An interface method without a default implementation is implicitly:
public and abstract
private
static
final
Which is true about abstract classes?
Can be instantiated
Must have all abstract methods
Can have both abstract and concrete methods
Must extend an interface
Which of the following handles both checked and unchecked exceptions?
try-catch
throws
finally
throw
Which statement rethrows an exception?
throw e;
throws e;
catch(e);
raise e;
Which method is used to execute a SELECT query?
execute()
executeQuery()
executeUpdate()
executeBatch()
Which JDBC class maintains a connection to the database?
Statement
ResultSet
Connection
DriverManager
Which class is best for reading text line by line?
FileReader
BufferedReader
Scanner
DataInputStream
Which exception must be handled when working with IO streams?
IOException
NullPointerException
ArrayIndexOutOfBoundsException
SQLException
The service() method in a servlet:
Is called once during initialization
Is called for every request
Is called after destroy()
Cannot be overridden
Which method destroys a servlet instance?
destroy()
finalize()
exit()
end()
Which JSP directive defines global page settings?
jsp:forward
jsp:param
What is the default scripting language in JSP?
Java
Python
JavaScript
Groovy
Which annotation marks a Spring Boot application entry point?
@SpringBootApplication
@EnableAutoConfiguration
@Configuration
@SpringBootMain
Spring Boot auto-configuration is triggered by which annotation?
@AutoConfig
@EnableAutoConfiguration
@ConfigClass
@SpringComponent
Which design principle does Dependency Injection support?
Loose coupling
Tight coupling
Hard dependency
Strong cohesion
Which annotation is used for field injection?
@Autowired
@Qualifier
@InjectBean
@Component
Which annotation marks an entity class?
@Entity
@Table
@Repository
@Persistence
Which method in JpaRepository retrieves all records?
findOne()
findAll()
getAll()
list()
Which interface defines user-specific data for authentication?
UserDetails
SecurityConfig
AuthProvider
RoleManager
What is the default login URL in Spring Security?
/signin
/login
/auth
/userlogin
Which annotation binds URL path variables to method parameters?
@PathVariable
@RequestParam
@ModelAttribute
@RequestBody
DispatcherServlet acts as:
View component
Front Controller
Service layer
DAO layer
Which annotation maps HTTP GET requests to a method?
@GetMapping
@PostMapping
@PutMapping
@RequestParam
To send JSON response, a method should return:
String
ResponseEntity
HttpRequest
ModelAndView
