Browsed by
Tag: tutorials on core java in java

Why Calling System.setProperty() does not Affect the Classpath at Run-Time

Why Calling System.setProperty() does not Affect the Classpath at Run-Time

You can easily set any system properties in java using System.setPropoerty method, However it may not have any effect in case of CLASSPATH property. This is mainly because the Java system class loader is initialized very early in the JVM startup sequence. The class loader copies the classpath into its own data structures, and the classpath property is not read again. Therefore changing it after its already copied does not affect anything. There are mainly two reasons for this –…

Read More Read More

How to create a immutable object in Java? Does all property of immutable object needs to be final?

How to create a immutable object in Java? Does all property of immutable object needs to be final?

  To create a object immutable You need to make the class final and all its member final so that once objects gets crated no one can modify its state. You can achieve same functionality by making member as non final but private and not modifying them except in constructor. Also its NOT necessary to have all the properties final since you can achieve same functionality by making member as non final but private and not modifying them except in…

Read More Read More

How much subclasses you can maximum in Inheritance?

How much subclasses you can maximum in Inheritance?

In one of our old JAVA projects we had an inheritance depth of five. Believe us we never liked that code. It’s bad to have a huge inheritance depth. A maintainable inheritance depth should be maximum 5. Anything above that is horrible. There is no limit as such specified anywhere that there is some limit on the inheritance sub classing but depending on environments you will get stack over flow error.

Why main() in java is declared as public static void main? What if the main method is declared as private?

Why main() in java is declared as public static void main? What if the main method is declared as private?

Public – main method is called by JVM to run the method which is outside the scope of project therefore the access specifier has to be public to permit call from anywhere outside the application static – When the JVM makes are call to the main method there is not object existing for the class being called therefore it has to have static method to allow invocation from class. void – Java is platform independent language therefore if it will…

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.

What is adapter class

What is adapter class

An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested. For example, the MouseMotionAdapter class has two methods, mouseDragged()and mouseMoved(). The signatures of these…

Read More Read More

What is the difference between scrollbar and scrollpane

What is the difference between scrollbar and scrollpane

A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling. In Core Java, a Scrollbar and a ScrollPane are two distinct components used for handling scrolling behavior in graphical user interfaces. Here’s the difference between them: Scrollbar: A Scrollbar is a user interface component that provides a graphical representation of the current position within a larger data set. It is typically associated with a single-dimensional range,…

Read More Read More

Who is loading the init() method of servlet

Who is loading the init() method of servlet

?– Web server. In Java servlets, the init() method is automatically called by the servlet container (e.g., Tomcat, Jetty) when the servlet is first loaded into memory. It is part of the servlet lifecycle and is invoked only once during the servlet’s initialization. So, the correct answer to the question “Who is loading the init() method of servlet?” would be: The servlet container (or servlet engine) is responsible for loading and invoking the init() method of a servlet.

What Checkbox Method Allows You to Tell if a Checkbox is Checked

What Checkbox Method Allows You to Tell if a Checkbox is Checked

getState().getState() In Core Java, to determine if a Checkbox is checked, you can use the isSelected() method. The isSelected() method returns a boolean value that indicates whether the Checkbox is currently in the checked state or not. Here’s an example: java import java.awt.*; import java.awt.event.*;public class CheckboxExample { public static void main(String[] args) { Frame frame = new Frame(“Checkbox Example”); Checkbox checkbox = new Checkbox(“Check me”); checkbox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (checkbox.isSelected()) { System.out.println(“Checkbox is checked”);…

Read More Read More

What an I/O Filter

What an I/O Filter

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another. In the context of Core Java, an I/O filter typically refers to an object that is used to perform filtering on data as it is read from or written to a stream. Input/Output (I/O) streams in Java are used for reading from or writing to various sources, such as…

Read More Read More