
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

2K+ Views
A JComboBox is a subclass of JComponent class and it is a combination of a text field and a drop-down list from which the user can choose a value. A JComboBox can generate an ActionListener, ChangeListener, and ItemListener interfaces when the user actions on a combo box.We can implement auto-complete JComboBox when the user types an input value from a keyboard by using customization of a combo box (AutoCompleteComboBox) by extending the JComboBox class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.basic.*; public class AutoCompleteComboBoxTest extends JFrame { private JComboBox comboBox; public AutoCompleteComboBoxTest() { setTitle("AutoCompleteComboBox"); ... Read More

283 Views
The run() method of the Thread class is called internally after the start() method is invoked to begin a new thread. However, if the run() method is called directly (without start()), it does not start a separate thread and executes within the current thread. The run() Method In Java, the run() method of the Thread class is used to define the sequence of actions that a thread will execute. This method will be invoked by the Java Virtual Machine (JVM) implicitly; we can also invoke this method explicitly in the current thread without calling the start() method. Note! The run() ... Read More

456 Views
A JDialog is a subclass of Dialog class and it does not hold minimize and maximize buttons at the top right corner of the window. There are two types of dialog boxes namely, modal and non-modal. The default layout for a dialog box is BorderLayout.In the below program, we can implement a transparent JDialog by customizing the AlphaContainer class and override the paintComponent() method.Exampleimport java.awt.*; import javax.swing.*; public class TransparentDialog { public static void main (String[] args) { JDialog dialog = new JDialog(); dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); dialog.getRootPane().setOpaque(false); dialog.setUndecorated(true); dialog.setBackground(new Color (0, 0, ... Read More

673 Views
A String class can be used to represent character strings; all the string literals in Java programs are implemented as instances of the String Class. In Java, Strings are constants and their values cannot be changed (immutable) once declared.Printing Maximum Occurred Character The maximum occurring character of a string refers to the character that appears multiple times (more than any other character in a string) in a string. To count the maximum occurring character of a string, we have the following approaches - Using an Array Using HashMap Using an Array Using an array is one way to ... Read More

3K+ Views
This article will discuss "how to check the memory used by a program" in Java, including a brief introduction of the process for calculation and an appropriate example that correctly checks the memory usage by the program. Understanding Memory Usage in Java Programs A Java code that takes a long time to execute, makes heavy use of dynamic memory. In such scenarios, we may end up with Out-of-Memory errors (due to a memory shortage of the heap space). We can calculate the memory space (heap) used by a Java program using the methods provided by the Runtime class.If the heap space is ... Read More

6K+ Views
SerialVersionUIDThe SerialVersionUID must be declared as a private static final long variable in Java. This number is calculated by the compiler based on the state of the class and the class attributes. This is the number that will help the JVM to identify the state of an object when it reads the state of the object from a file.The SerialVersionUID can be used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible w.r.t serialization. If the deserialization object is different than serialization, then it can throw an InvalidClassException.If the serialVersionUID is ... Read More

1K+ Views
This article explains the different ways of calling the garbage collector (GC) in Java. It also includes a brief introduction to garbage collection, various calling approaches, and relevant examples. Garbage Collection (GC) in Java In Java, the garbage collection is carried out by a daemon thread called the Garbage Collector (GC). Instead of waiting until the Java Virtual Machine (JVM) runs a garbage collector, we can request the JVM to run the garbage collector. There is no guarantee that the JVM will accept our request. In Java, we can call the garbage collector (GC) manually in "two ways", which ... Read More

4K+ Views
An invokeLater() method is a static method of the SwingUtilities class and it can be used to perform a task asynchronously in the AWT Event dispatcher thread. The SwingUtilities.invokeLater() method works like SwingUtilities.invokeAndWait() except that it puts the request on the event queue and returns immediately. An invokeLater() method does not wait for the block of code inside the Runnable referred by a target to execute.Syntaxpublic static void invokeLater(Runnable target)Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class InvokeLaterTest extends Object { private static void print(String msg) { String name = Thread.currentThread().getName(); System.out.println(name + ": " + msg); } ... Read More

5K+ Views
The sleep() method is a static method of Thread class and it makes the thread sleep/stop working for a specific amount of time. The sleep() method throws an InterruptedException if a thread is interrupted by other threads, that means Thread.sleep() method must be enclosed within the try and catch blocks or it must be specified with throws clause. Whenever we call the Thread.sleep() method, it can interact with the thread scheduler to put the current thread to a waiting state for a specific period of time. Once the waiting time is over, the thread changes from waiting state to runnable state. Syntax public ... Read More

3K+ Views
The join() Method In Java, a join() is a final method of the Thread class, and it can be used to join the start of a thread's execution to the end of another thread's execution so that a thread will not start running until another thread has ended. If the join() method is called on a thread instance, the currently running thread will be blocked until the thread instance has finished its execution. The join() method in Java is important in multithreading because it allows one thread to wait for the completion of another thread before continuing execution. Syntax Following is ... Read More