0% found this document useful (0 votes)
17 views14 pages

RGGZT WBH Ju

The document contains a compilation of Java-related questions and answers from the years 2021, 2022, and 2023. It covers various topics including JVM, differences between Java and C++, wrapper classes, polymorphism, garbage collection, and JDBC. Each section provides concise explanations and examples relevant to the respective topics.

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)
17 views14 pages

RGGZT WBH Ju

The document contains a compilation of Java-related questions and answers from the years 2021, 2022, and 2023. It covers various topics including JVM, differences between Java and C++, wrapper classes, polymorphism, garbage collection, and JDBC. Each section provides concise explanations and examples relevant to the respective topics.

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

Java- 2mark(2021,22,23) Question answer:

2021:
a) Write about JVM:

* The JVM is a runtime stand for

Java Virtual Machine that converts

byte code into machine code for

execution.

* It allows Java programs

to be platform-independent.

* It also handles memory management

and garbage collection.


b) Write any four differences between Java and C++:

Java:

* Java uses automatic garbage collection.

* Java is platform-independent.

* Java supports multiple inheritance through interfaces.

* Java’s default access modifier is private.

C++:

* C++ requires manual memory management.

* C++ is platform-dependent.

* C++ supports multiple inheritance for classes.

* C++’s default access modifier is private.


c) What is wrapper class?

* Wrapper classes in Java convert primitive data types (like int, float) into objects (like Integer, Float).

* Provide methods to convert back from the object to the primitive data type.

d) Illustrate super keyword?

* The super class in Java is used to call the constructor of the superclass.

* super() is used to call the constructor.

* super is used to access the superclass’s members.

e) Write a short note on polymorphism:

* Polymorphism in Java refers to the ability of an object to take on many forms.

* It allows objects of different classes to be treated as objects of a common type.

* It includes method overloading and overriding.


f) Difference between:

Mutable data type

* Data type can be changed after creation.

* Example: ArrayList, StringBuilder.

* Can be modified.

Immutable data type

* Immutable data types cannot be changed after creation.

* Example: String, Integer, & Double.

* Cannot modify.

g) Auto Boxing:

* Auto boxing is a feature in Java that automatically converts primitive data types to their corresponding wrapper class objects.
* For example, int to Integer, float to Float.

h) Write a simple basic program to create a thread using Runnable interface.

public class MyThread implements Runnable {

@Override

public void run() {

System.out.println("Thread is running.");

public static void main(String[] args) {

MyThread thread = new MyThread();

Thread t = new Thread(thread);

t.start();
}

i) Write about arrays in Java

* Arrays in Java are used to store a collection of elements of the same datatype.

* They are fixed-size data structures.

* You can create arrays of primitive data types (like int, char, double).

* Java supports multi-dimensional arrays.

j) What is the difference between FileInputStream and FileOutputStream?

FileInputStream

* Reads data from a file.


* Data flow: Reads data from the file to the program's memory.

FileOutputStream

* Writes data to a file.

* Data flow: Writes data from the program's memory to the file.

2022:
a) what is command line argument:

* command-line arguments are values passed to a program when it’s executed from the command line.

* they are typically used to provide input or configuration options to the program

* In Java, command-line arguments are accessed through the args parameter in the main method.

b) write down 4 important pillars of oops:


* Encapsulation

* Abstraction

* Inheritance

* polymorphism

c) what is wrapper class:

* wrapper classes in Java convert primitive data types (like int, float) into objects (like Integer, Float)

* provide methods to convert back from the object to the primitive data type.

d) What is garbage collection?

* Garbage collection is an automatic memory management system in Java.

* The JVM has a garbage collector that automatically reclaims the memory occupied by objects.

* This prevents memory leaks and simplifies memory management for developers.
e) Difference between:

Method Overloading

* Multiple methods with the same name but different parameters exist within the same class.

Method Overriding

* A subclass provides a specific implementation for a method that is already defined in the superclass.

f) How define array Dynamically

* Dynamically define arrays using data-type [] array-name = new data-type[size]

g) write down two predefined Package name.

* Java.lang

* Java.util

h) write down name of thread exceptions.


* InterruptedException

* IllegalThreadStateException

i) syntax of creating thread using Runnable interface.

public class MyThread {

public void run() {

// Thread's code

j) write down name of JDBC drivers.

* MySQL Connector
* Oracle JDBC Driver

2023:
a) what are the uses of static keyword

* Creates class-level variables and methods, accessible without object creation.

* Used for creating utility classes with static methods.

b) what are different types of constructor?

* Default constructor (no arguments)

* Parameterized constructor (with arguments)

* Copy constructor (initialize object with values from another object)

c) Define an interface?
* An interface defines a contract of methods that a class must implement.

* It enforces a specific behavior on classes that implement it.

d) what is up-casting?

* Up-casting is assigning a subclass object to a superclass reference variable.

* It is automatically done by the compiler.

e) Define Jagged Array?

* A Jagged array is an array of arrays where each element can have different size.

* It's essentially an array where each element is another array, and those inner arrays can vary in size.

f) How to create String object.

* Using string literal: String str = "Hello";

* Using new keyword: String str = new String("Hello");


g) what are character streams?

* Character stream is a sequence of characters that can be read from or written to.

* It provides a way to handle text data in a human-readable format.

h) what is Thread prioritization?

* Thread prioritization assigns a priority to each thread, indicating its relative importance.

* Higher priority threads are scheduled to run before lower priority threads.

i) what are the uses of java.net package?

The Java.net package provides classes for network communication such as creating Sockets, handling URLs and sending HTTP requests.

j) what are the uses of JDBC?

* Database Access: Connects Java applications to relational databases like MySQ

L, Oracle, etc to execute SQL queries.


* Data manipulation: Performs operations like inserting, updating, deleting data from databases.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy