Java 02
Java 02
Each case value in a switch statement must be a constant expression. It cannot be a variable or the result
of a runtime computation.
14. How can one prove that the array is not null but empty?
You can check the array’s length:
if (array != null && array.length == 0) {
System.out.println("The array is empty.");
}
15. What is Dynamic Binding?
Dynamic Binding occurs when the method to be invoked is determined at runtime based on the object’s
type.
24. Can a source file contain more than one class declaration?
Yes, a source file can contain multiple class declarations, but only one of them can be declared public.
25. I don’t want my class to be inherited by any other class. What should I do?
Declare the class as final.
28. Which non-Unicode letter characters may be used as the first character of an identifier?
Non-Unicode characters cannot be used as the first character of an identifier. Identifiers must start with a
letter, currency character ($), or an underscore (_).
29. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Unicode: 16 bits
ASCII: 7 bits (commonly extended to 8 bits)
UTF-16: 16 bits
UTF-8: Variable (1 to 4 bytes)
30. What restrictions are placed on the location of a package statement within a source code file?
The package statement must be the first line of code (excluding comments) in a Java source file.
31. What are order of precedence and associativity, and how are they used?
Order of precedence determines which operator is evaluated first in an expression.
Associativity determines the order in which operators of the same precedence level are evaluated
(left-to-right or right-to-left).
32. Which characters may be used as the second character of an identifier, but not as the first character
of an identifier?
Digits (0-9) can be used as the second or subsequent characters but not as the first character of an
identifier.
37. What is the difference between the prefix and postfix forms of the ++ operator?
Prefix (++x): Increments the value and returns the updated value.
Postfix (x++): Returns the original value, then increments it.
41. What is the difference between a break statement and a continue statement?
break: Exits the nearest enclosing loop or switch statement.
continue: Skips the current iteration and proceeds to the next iteration of the loop.
43. What is the difference between the >> and >>> operators?
>>: Arithmetic right shift, preserving the sign bit.
>>>: Logical right shift, filling the leftmost bits with zero.
44. What is the difference between an object-oriented programming language and an object-based
programming language?
Object-oriented languages (e.g., Java) support inheritance, polymorphism, and dynamic binding.
Object-based languages (e.g., JavaScript) do not support inheritance or dynamic binding.
47. Are reusable software components written in Java designed to be manipulated visually by
development environments like JBuilder or VisualAge?
Yes, JavaBeans are reusable software components designed for visual manipulation in IDEs.
48. What is a package?
A package is a namespace that organizes classes and interfaces, preventing naming conflicts and
providing access control.
55. How do you load a class? What is the mechanism to load a class?
Classes are loaded using the class loader, typically through Class.forName() or ClassLoader.loadClass().
59. How can we send a POST request from a normal Java program?
Using HttpURLConnection or HttpClient classes to send HTTP POST requests.
60. What are JavaBeans, and how are they different from normal Java classes?
JavaBeans are reusable components with standard naming conventions (getters/setters) and are
serializable. A normal class can become a JavaBean by following these conventions.
61. What new functionality have you used from JDK 1.5?
Some features introduced in JDK 1.5 include generics, enhanced for-loops, autoboxing/unboxing,
varargs, annotations, and the concurrency utilities.