Java Unit Answers
Java Unit Answers
explicitly, while C/C++ are platform-dependent, compile to native code, and support
pointers.
A: JVM runs Java bytecode, JRE includes JVM and libraries to run Java apps, and JDK
System.out.println("Hello, World!");
Example: int x = 10; double y = 5.5; char c = 'A'; boolean flag = true;
Q: Write a Java program to find the largest of three numbers using if-else.
else System.out.println(c);
Example:
Q: What are arrays? Write a program to find the sum of array elements.
System.out.println(sum);
Q: Define class and object in Java. Write a program to create a class and object.
A: String s = "hello";
sb.reverse();
System.out.println(sb);
A: Mechanism to handle runtime errors. try contains code, catch handles exception,
ArrayIndexOutOfBoundsException, NumberFormatException.
Unit 5: Packages and Interfaces
Q: What is a package? How to create and use it?
pkgName.*';
A: Interface is a reference type with abstract methods. Interface can’t have method
A: Abstract class can have method bodies and constructors; interface can’t (till Java 7),