Browsed by
Tag: complete notes on core java in java

What is the Collection interface

What is the Collection interface

The Collection interface provides support for the implementation of a mathematical bag – an unordered collection of objects that may contain duplicates. In Java, the Collection interface is a part of the Java Collections Framework and is present in the java.util package. It is at the top of the hierarchy of collection interfaces. The Collection interface represents a group of objects, known as elements. It provides a standard set of methods to manipulate collections, such as adding, removing, and querying elements. Some…

Read More Read More

What modifiers may be used with top-level class?-

What modifiers may be used with top-level class?-

public, abstract and final can be used for top-level class. In Java, a top-level class (i.e., a class that is not a nested or inner class) can have the following modifiers: public: The class can be accessed from any other class. (default, no modifier): If no access modifier is specified, the class is only accessible within the same package. So, the correct answer would be public and the default (package-private) modifier.

How are Servlets and JSP Pages related

How are Servlets and JSP Pages related

JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java and then compiled, loaded into the server and executed.    

What is the purpose of serialization?

What is the purpose of serialization?

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialised – converted into a replica of the original object. In Core Java, serialization refers to the process of converting an object’s state (fields and data) into a byte stream, which can be easily saved to a file or transmitted over a network. The primary…

Read More Read More

What is a reflection package?-

What is a reflection package?-

java. lang. reflect package has the ability to analyze itself in runtime. In Java, the reflection package refers to the java.lang.reflect package. Reflection is a feature in Java that allows you to inspect or manipulate the runtime behavior of applications. It provides a way to examine or modify the behavior of classes, interfaces, fields, methods, and constructors at runtime. The key classes in the java.lang.reflect package include: Class: Represents a class or interface. Field: Represents a field (a variable) of…

Read More Read More

Why do threads block on I/O?

Why do threads block on I/O?

Threads block on I/O (that is enters the waiting state) so that other threads may execute while the I/O Operation is performed. Threads often block on I/O (Input/Output) operations in Java due to the nature of these operations. When a thread performs I/O, such as reading from a file, writing to a network socket, or waiting for user input, it often has to wait for external resources to be available or for the I/O operation to complete. During this waiting…

Read More Read More

What is the difference between web server and app server?

What is the difference between web server and app server?

A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols. In the context of Core Java, the difference between a web server and an application server lies primarily in their roles and functionalities within a web application architecture: Web Server: Role: A web server is primarily responsible for handling HTTP requests and responses. It serves static content like HTML pages, images, CSS, and JavaScript files to clients (such…

Read More Read More

Can you have an inner class inside a method and what variables can you access?-

Can you have an inner class inside a method and what variables can you access?-

?– Yes, we can have an inner class inside a method and final variables can be accessed. Yes, in Java, you can have an inner class inside a method. This type of inner class is known as a local inner class. Local inner classes are defined within the body of a method, and they have access to the variables declared in the method’s scope (including method parameters and final local variables). Here’s an example: java public class OuterClass { public…

Read More Read More

Can a lock be acquired on a class?

Can a lock be acquired on a class?

Yes, a lock can be acquired on a class. This lock is acquired on the class’s Class object. Yes, in Java, it is possible to acquire a lock on a class. In Java, every class and object has an associated lock, also known as a monitor. This lock is used to control access to the critical section of code to ensure that only one thread can execute the code block at a time. To acquire a lock on a class, you can…

Read More Read More

How can a collection object be sorted?

How can a collection object be sorted?

// Sort Collections.sort(list); // Sort case-insensitive Collections.sort(list, String.CASE_INSENSITIVE_ORDER); // SortReverse-order Collections.sort(list, Collections.reverseOrder ()); // Reverse-order sort case-insensitive Define local, member and a class variable. Within a method variables declared are called “local” variables. Variables declared in the class i.e not in any methods are “member” variables (global variables). Variables declared in the class i.e not in any methods and are called as “static” are class variables. Name the different identifier states of a Thread. Different types of identifiers of a…

Read More Read More