
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 9150 Articles for Object Oriented Programming

8K+ Views
A JTable is a subclass of JComponent class for displaying complex data structures. A JTable component can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. A JTable can generate TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener and RowSorterListener interfaces. We can remove a selected row from a JTable using the removeRow() method of the DefaultTableModel class.Syntaxpublic void removeRow(int row)Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class RemoveSelectedRowTest extends JFrame { private JTable table; private DefaultTableModel model; private Object[][] data; private String[] columnNames; private JButton button; public RemoveSelectedRowTest() { setTitle("RemoveSelectedRow ... Read More

10K+ Views
What is an Annotation? An annotation is like metadata that provides additional information about the code. It does not affect the code directly but provides the information so that the compiler or runtime environment can use it while executing the code. To define or use any annotation in Java, you need to specify the annotation name starting with the "@" symbol. Here is the syntax to use annotations in Java: @annotation_name Where the @ symbol specifies the annotation, and annotation_name is the name of the annotation. Following is a list of a few important annotations and their usage: ... Read More

709 Views
A JList is a subclass of JComponent class and it can be used to display a list of objects that allows the user to select one or more items. A JList can generate a ListSelectiionListener interface and need to implement the abstract method valueChanged(). A DefaultListModel class provides a simple implementation of a list model, which can be used to manage items displayed by a JList control. We can add the items to a JList using the addElement() method of the DefaultListModel class, we can also add items with different fonts to JList using HTML tags like for bold style text, for italic style ... Read More

6K+ Views
Both Object level lock and Class level lock are used to achieve synchronization mechanisms in a multi-threaded application. Object Level Lock Every object in Java has a unique lock. If a thread wants to execute a synchronized method on a given object, first it has to get a lock of that object. Once thread got the lock then it is allowed to execute any synchronized method on that object. Once method execution completes automatically thread releases the lock. Acquiring and release lock internally is taken care of by the JVM. Object level lock is a mechanism when we want to synchronize a non-static ... Read More

3K+ Views
Yes! we can override the start() method of the Thread class in Java. But, if we do so, we must call it using super.start(), which will create a new thread; otherwise, no new thread will be created, and the run() method will not execute in parallel for the other threads. Overriding the start() Method In Java, the start() method is used to begin (start) the execution of a new Thread. When this method is called, it invokes the run() method, which executes in parallel with other threads. Example In the following example, we override the start() method within the subclass of ... Read More

568 Views
Regular functions vs Arrow functionsAn arrow function is used to write the code concisely. Both functions regular and arrow work in a similar manner but there are some differences between them. Let's discuss those differences in a nutshell.syntax of an arrow functionlet x = (params) => { // code };syntax of a regular functionlet x = function functionname(params){ // code };Usage of "this" keywordIt is unable to use "this" keyword in arrow functions whereas in regular functions it can be used without any disturbance.ExampleIn the following example, both regular(rectangle) and arrow(square) functions were used inside the object "num", which consists of len(length) ... Read More

554 Views
No, we cannot call the wait() method without acquiring the lock. In Java, once the lock has been acquired then we need to call wait() method (with timeout or without timeout) on that object. If we are trying to call the wait() method without acquiring a lock, it can throw java.lang.IllegalMonitorStateException. Example public class ThreadStateTest extends Thread { public void run() { try { wait(1000); } catch(InterruptedException ie) { ie.printStackTrace(); ... Read More

437 Views
A JPasswordField is a subclass of JTextField and each character entered in a JPasswordField can be replaced by an echo character. This allows confidential input for passwords. The important methods of JPasswordField are getPassword(), getText(), getAccessibleContext() and etc. By default, we can enter any number of digits inside JPasswordField. If we want to restrict the digits entered by a user by implementing a DocumentFilter class and need to override the replace() method.Syntaxpublic void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationExceptionExampleimport java.awt.*; import java.awt.*; import javax.swing.*; import javax.swing.text.*; public class JPasswordFieldDigitLimitTest extends JFrame { private JPasswordField passwordField; private JPanel ... Read More

2K+ Views
No, a constructor cannot be synchronized in Java. If you try to use the synchronized keyword before a constructor, it may throw a compile-time error in the IDE. Synchronization is a mechanism used to control the access of multiple threads to any shared resource. When multiple threads access any shared resources, the synchronization prevents data corruption by coordinating access, avoiding race conditions (i.e., occurs when multiple threads concurrently access and modify shared data), and ensuring that operations are performed atomically. The JVM ensures that only one thread can invoke a constructor call at a given point in time. That is ... Read More

16K+ Views
The threads can communicate with each other through wait(), notify(), and notifyAll() methods in Java. These are the final methods defined in the Object class and can be called only from within a synchronized context. The wait() method causes the current thread to wait until another thread invokes the notify() or notifyAll() methods for that object. These methods will throw an IllegalMonitorStateException if the current thread is not the owner of the object's monitor. The wait() Method In Java, the wait() method of the Object class allows threads to pause their execution and wait for a specific condition to be ... Read More