0% found this document useful (0 votes)
15 views7 pages

Java - 1.5mark Question Answer

The document outlines key concepts and features of Java, including its platform independence, object-oriented nature, and various keywords such as 'final' and 'super'. It explains methods like exception handling, thread creation, and the use of packages and interfaces. Additionally, it covers the importance of the main method, the concept of constructors, and the distinction between 'throw' and 'throws'.

Uploaded by

rikunsahoo26
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)
15 views7 pages

Java - 1.5mark Question Answer

The document outlines key concepts and features of Java, including its platform independence, object-oriented nature, and various keywords such as 'final' and 'super'. It explains methods like exception handling, thread creation, and the use of packages and interfaces. Additionally, it covers the importance of the main method, the concept of constructors, and the distinction between 'throw' and 'throws'.

Uploaded by

rikunsahoo26
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/ 7

JAVA 1MARK QUESTION ANSWER

2021:
a) Features of Java:

* Platform-independent

* Object-oriented

* Secure

* Robust

* Portable

* Multithreaded

* High performance

b) Purpose of the final keyword:

The final keyword in Java is used to:

* Make variables constant

* Prevent method overloading

* Prevent class inheritance

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.

h) What is Exception Handling?

Exception handling manages runtime errors using try, catch, and finally blocks to maintain
program flow.

i) Differentiate between throw and throws:

* throw: Used to explicitly throw an exception in a method.

* throws: Declares exceptions that a method might throw in its signature.

j) Define Thread:

A thread is a lightweight process that runs independently.

Threads are created by extending the Thread class or implementing the Runnable interface.

A lightweight process for multitasking.


2022
a) Ways to Create Threads in Java

* Extending the Thread class or implementing the Runnable interface.

b) Syntax of Single Try and Catch

try {

// Code that might throw an exception

} catch (Exception e) {

// Handle the exception here

c) Two methods used in File

* createNewFile()

* delete()

d) Syntax of charAt()

char charAt(index);
e) Syntax of Jagged Array

int[][] arr = new int[3][];

arr[0] = new int[2];

arr[1] = new int[3];

arr[2] = new int[1];

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.

h) Use of Abstract Class

* Used to define a class that cannot be instantiated.


* Used to define methods without implementation.

i) . Types of Variables in Java

* Local variables

* Instance variables

* Static variables

j) Write down use of super keyword

* To refer to the parent class object.

* To access the parent class constructor.

* To access the parent class methods that are overridden.

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.

b). How to compile a Java program?

* 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.

d) . What is private specifier in Java?

* The private specifier restricts access to a member (variable or method) within the same class
only.

* It provides the highest level of encapsulation.

e) . Final keyword

* The final keyword is used to create constants (variables that cannot be changed) and classes
that cannot be inherited.

f). How to define packages in Java?

* To define a package in Java, use the package keyword at the beginning of the program. For
example:

package com.example;

g). Does constructor return any value?

* Constructors do not have a return type, but they initialize objects.

h). Why is the main method public?

* The main method is public so that it can be accessed by the JVM to start the execution of the
program.

i). Why is multiple inheritance not supported by Java?

* Java does not support multiple inheritance with classes to avoid ambiguity caused by the
diamond problem. It can be achieved through interfaces.

Or

ans- To avoid confusion from the Dimond Problem.

j). What is TCP/IP?

* TCP/IP stands for Transmission Control Protocol/Internet Protocol, which is a set of


communication protocols used for networking and transmitting data over the internet.

* TCP is a protocol for data transfer over the internet.

You might also like