Java - 1.5mark Question Answer
Java - 1.5mark Question Answer
2021:
a) Features of Java:
* Platform-independent
* Object-oriented
* Secure
* Robust
* Portable
* Multithreaded
* High performance
c) Method Overloading:
Method overloading allows multiple methods with the same name but different parameter lists in
a class.
d) Define Packages:
A package is a collection of related classes and interfaces that organizes code and prevents
naming conflicts.
e) StringBuffer:
StringBuffer is used for mutable strings. It provides better performance for string manipulations
compared to String.
f) Synchronization:
Synchronization ensures that only one thread accesses a block of code at a time, preventing data
inconsistency.
g) Constructors:
A constructor initializes an object. It has the same name as the class and has no return type.
Exception handling manages runtime errors using try, catch, and finally blocks to maintain
program flow.
j) Define Thread:
Threads are created by extending the Thread class or implementing the Runnable interface.
try {
} catch (Exception e) {
* createNewFile()
* delete()
d) Syntax of charAt()
char charAt(index);
e) Syntax of Jagged Array
f) Syntax of Interface
interface InterfaceName {
// Abstract methods
void method1();
void method2();
g) Package
* A package is a collection of related classes and interfaces that organizes code and prevents
naming conflicts.
* Local variables
* Instance variables
* Static variables
2023
a) Why is Java platform-independent?
* Java is platform-independent because it uses the Java Virtual Machine (JVM), which allows
Java bytecode to run on any operating system that has a JVM installed.
* To compile a Java program, use the javac command in the terminal or command prompt. For
example:
javac ProgramName.java
c). What if I write void static public instead of public
static void?
* The order of keywords does not matter in Java, so void static public is valid. However, the
conventional order is public static void.
* The private specifier restricts access to a member (variable or method) within the same class
only.
e) . Final keyword
* The final keyword is used to create constants (variables that cannot be changed) and classes
that cannot be inherited.
* To define a package in Java, use the package keyword at the beginning of the program. For
example:
package com.example;
* The main method is public so that it can be accessed by the JVM to start the execution of the
program.
* Java does not support multiple inheritance with classes to avoid ambiguity caused by the
diamond problem. It can be achieved through interfaces.
Or