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

Java 02

The document provides a comprehensive overview of various Java programming concepts, including switch statements, parameter passing, and object-oriented principles. It covers differences between operators, methods, and data structures, as well as features like JavaBeans and class loading mechanisms. Additionally, it highlights Java's platform independence and the handling of data types and memory management.

Uploaded by

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

Java 02

The document provides a comprehensive overview of various Java programming concepts, including switch statements, parameter passing, and object-oriented principles. It covers differences between operators, methods, and data structures, as well as features like JavaBeans and class loading mechanisms. Additionally, it highlights Java's platform independence and the handling of data types and memory management.

Uploaded by

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

1. What restrictions are placed on the values of each case of a switch statement?

Each case value in a switch statement must be a constant expression. It cannot be a variable or the result
of a runtime computation.

2. What is the difference between an if statement and a switch statement?


An if statement is used for decision-making with multiple conditions, where each condition can have a
different expression.
A switch statement simplifies multiple conditional checks for a single variable by comparing it against
multiple constant values.

3. What is meant by pass by reference and pass by value in Java?


Java uses pass by value exclusively. When you pass a variable to a method, a copy of the variable’s
value is passed.
For objects, the reference is passed by value, meaning the method can modify the object but not the
reference itself.

4. What are the differences between == and .equals()?


== checks if two references point to the same memory location (reference comparison).
.equals() checks if two objects have the same value (content comparison), as defined by the class’s
equals() method.

5. What is the Java API?


The Java API is a library of classes, interfaces, and methods provided by Java to perform common
programming tasks like data manipulation, network interaction, and file handling.

8. What is the difference between a while statement and a do statement?


A while statement evaluates the condition before executing the block.
A do-while statement executes the block at least once before evaluating the condition.

9. What is a native method?


A native method is a Java method implemented in another language like C or C++, typically used for
platform-specific operations or to access low-level system resources.

10. In System.out.println(), what is System, out, and println?


System: A final class in java.lang package.
out: A static member of System, an instance of PrintStream.
println(): A method of PrintStream to print data followed by a new line.

11. How does Java handle integer overflows and underflows?


Java does not throw an error for overflows or underflows. Instead, it wraps around using the modulo
operation for integers.

12. What type of parameter passing does Java support?


Java supports pass-by-value for both primitives and object references.

13. What do you understand by numeric promotion?


Numeric promotion automatically converts smaller data types (like int) to larger data types (like double) to
perform operations without data loss.

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.

16. What is object cloning?


Object cloning is creating a duplicate copy of an object using the clone() method of the Object class.

17. What is the most important feature of Java?


The most important feature of Java is platform independence, achieved through the Java Virtual Machine
(JVM).

19. What is a pointer, and does Java support pointers?


Pointers are variables that store the memory address of other variables. Java does not support pointers
explicitly to ensure security and simplicity.

21. What is the difference between Path and Classpath?


Path: Used by the operating system to locate executables.
Classpath: Used by the JVM to locate Java class files.

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.

26. What is the % operator?


The % operator computes the remainder of a division operation.

27. Which class is extended by all other classes?


All classes in Java implicitly extend the Object class unless explicitly specified otherwise.

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.

33. Is the ternary operator written x : y ? z or x ? y : z?


The ternary operator is written as x ? y : z.

34. How is rounding performed under integer division?


In integer division, any fractional part is truncated, effectively rounding towards zero.

35. What are the legal operands of the instanceof operator?


The left operand must be an object, and the right operand must be a class, interface, or subclass.

36. What happens when you add a double value to a String?


The double value is converted to a String, and the result is the concatenation of the two strings.

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.

38. Which Java operator is right associative?


The ternary operator (? :) is right associative.

39. Can a double value be cast to a byte?


Yes, but the fractional part will be truncated, and the value may be narrowed if it exceeds the range of a
byte (-128 to 127).

40. Can a byte value be cast to a double?


Yes, a byte value can be safely cast to a double without data loss.

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.

42. Can a for statement loop indefinitely?


Yes, a for statement can loop indefinitely if the condition is always true or omitted:
for (;;) {
// Infinite 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.

45. Can you have virtual functions in Java?


Java does not have virtual functions explicitly, but all non-static methods are virtual by default, supporting
polymorphism.

46. What is covariant return type?


A covariant return type allows an overridden method to return a subtype of the return type declared in the
superclass method.

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.

49. Do I need to import the java.lang package? Why?


No, java.lang is automatically imported in every Java program.

50. What is stack and queue?


Stack: A Last-In-First-Out (LIFO) data structure.
Queue: A First-In-First-Out (FIFO) data structure.

51. What is late binding and early binding in Java?


Early binding: Method calls are resolved at compile time (e.g., static methods).
Late binding: Method calls are resolved at runtime (e.g., overridden methods).

52. What is shallow comparison and deep comparison?


Shallow comparison: Compares object references (==).
Deep comparison: Compares the content of objects (.equals() or custom logic).

53. What is lazy loading in Java initialization-on-demand holder?


Lazy loading defers the initialization of an object until it is needed, often implemented using a static
nested holder class.

54. What are the different ways to create an object?


Using new keyword
Using reflection (Class.forName)
Using cloning (clone() method)
Using deserialization

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().

56. What is a volatile variable, and how is it used in Java?


A volatile variable ensures visibility and ordering of variable updates across threads. Transient variables,
in contrast, are not serialized.

57. What is weak loading?


Weak loading refers to loading classes or resources only when they are accessed, avoiding unnecessary
memory usage.

58. What is weak hashing?


Weak hashing uses hash codes with limited guarantees, often used for objects without a strong identity
requirement.

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.

You might also like