Java 8 Mark
Java 8 Mark
Class Declaration
Main Method
Syntax:
Explanation:
The main method (public static void main(String[] args)) is the entry point of execution.
protected Package & Subclass Accessible in the same package and subclasses
Example:
class AccessExample {
3. What are static members in Java? Explain static methods, variables, and blocks with examples.
Example:
class StaticExample {
Example:
import java.io.Serializable;
5. Explain wrapper classes in Java and their significance. How does autoboxing and unboxing
work?
int Integer
double Double
char Character
Example:
2. int a = 10, b = 5;
3. System.out.println(a + b); // 15
7. Explain different conditional and control statements in Java with suitable examples.
Conditional Statements:
if (num > 0) {
System.out.println("Positive");
} else {
System.out.println("Negative");
}
Looping Statements:
Example:
System.out.println(i);
}
8. Discuss the difference between String, StringBuffer, and StringBuilder with examples.
Example:
9. Explain the concept of instance control flow and instance blocks in Java with a program.
Instance control flow is the execution order of instance variables, instance blocks, and constructors.
Example:
class Test {
int x = 10;
{ // Instance block
System.out.println("Instance Block");
Test() {
System.out.println("Constructor");
Output:
Instance Block
Constructor
10. What are regular expressions (RegEx) in Java? Explain their usage with examples.
Example:
import java.util.regex.*;
Matcher m = p.matcher("123ABC");
System.out.println(m.find()); // true