
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

1K+ Views
A Treeset is a subclass of AbstractSet class and implements NavigableSet Interface. By Default, a Treeset gives an ascending order of output and it will use a Comparable interface for sorting the set elements. Inside a Treeset, we can add the same type of elements otherwise it can generate a ClassCastException because by default TreeSet uses a Comparable interface. Syntax public class TreeSet extends AbstractSet implements NavigableSet, Cloneable, Serializable We can iterate a TreeSet in two ways. Using Iterator We can iterate the elements of a TreeSet using Iterator interface. Example import java.util.*; public class IteratingTreeSetTest { public static void main(String[] args) { ... Read More

2K+ Views
A JTable is a subclass of JComponent class for displaying complex data structures. A JTable can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. A JTable will generate TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener and RowSorterListener interfaces.We can validate whether the JTable cell is empty or not by implementing the getValueAt() method of JTable class. If we click on the "Click Here" button, it will generate an action event and display a popup message like "Field is Empty" to the user.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class JTableEmptyValidateTest extends JFrame { private JPanel panel; private JTable table; ... Read More

466 Views
A JTable is a subclass of JComponent class and it can be used to create a table with information displayed in multiple rows and columns. When a value is selected from a JTable, a TableModelEvent is generated, which is handled by implementing a TableModelListener interface.In the below program, we can display "No records available" text if the rows are not available in a JTable.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class NoRecordTableTest extends JFrame { private JPanel panel; private JTable table; private JScrollPane scrollPane; public NoRecordTableTest() { panel = new JPanel(); panel.setLayout(new BorderLayout()); ... Read More

7K+ Views
This article will discuss how to print the first character of each word in a given string. For example, if we have the string "Hello John", the output should be H J. In Java, the String class is used to represent character strings. All string literals in a Java program are implemented as instances of the String class. Strings in Java are immutable, which means that once a string is created, its value cannot be changed. To print the first character of each word in a String, we have the following approaches - Using split() ... Read More

7K+ Views
What are Generic Collections in Java? In Java, the Generic collections were introduced in Java 5. These collections disable the type-casting, and there is no need for explicit type-casting if we use generic collections. The generic collections are type-safe and detect type-related errors at compile time. It allows the datatypes to pass as parameters to classes or interfaces. The Compiler is responsible for checking the compatibility of the types. Syntax Following is the way to create generic collections in Java: class or interface Where type specifies the type of the object, such as: Integer, String, Character, etc.. You can create generic ... Read More

393 Views
A JTree is a component that presents a hierarchical view of data. The user has the ability to expand or collapse individual sub-trees. A TreeNode interface defines the methods that must be implemented nodes of a JTree object. The DefaulMutableTreeNode class provides a default implementation of a TreeNode interface. We can disable the leaf of JTree by overriding the getTreeCellRendererComponent() method of DefaultTreeCellRenderer class.Syntaxpublic Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)Exampleimport java.awt.*; import javax.swing.tree.*; import javax.swing.*; public class JTreeLeafNodeDisableTest extends JFrame { private TreeNode treeNode; private JTree tree; public JTreeLeafNodeDisableTest() { setTitle("JTreeLeafNodeDisable Test"); ... Read More

3K+ Views
In Java, a HashMap is a subclass of the AbstractMap class and is used to store key-value pairs. Each key in the map is mapped to a single value in the map, and the keys are unique.Printing Java HashMap Elements We can insert a key only once in a map, and duplicate keys are not allowed, but the value can be mapped to multiple keys. We can add the elements using the put() method of the HashMap class and iterate over the elements using the Iterator interface. Java HashMap provides various ways to print its elements as follows: ... Read More

9K+ Views
In Java, Collection and Collections are important components of the Collections Framework. The Collection has various sub-interfaces such as Set, List, and Queue. The Collections provides static methods to perform various operations on collections, such as sorting, searching, and synchronization. Let's learn them one by one with proper definitions, syntax, and a suitable example. The Collection Interface In Java, the Collection is an interface, which is considered the root interface in the collection hierarchy. It represents a group of objects, which are known as its elements. Some collections allow duplicate values and specific orders, whereas some do not allow duplicates ... Read More

931 Views
A JTree is a subclass of JComponent class that can be used to display the data with the hierarchical properties by adding nodes to nodes and keeps the concept of parent and child node. Each element in the tree becomes a node. The nodes are expandable and collapsible. We can implement the mouse right-click on each node of a JTree using the mouseReleased() method of MouseAdapter class and need to call show() method of JPopupMenu class to show the popup menu on the tree node.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; public class JTreeRightClickTest extends JFrame { public JTreeRightClickTest() { ... Read More

3K+ Views
Yes, we can synchronize a run() method in Java using the synchronized keyword before this method. If this method is synchronized, only one thread can execute this on a given instance of the object at any point in time. Here is a code snippet that shows how to define the run() method as synchronized: @Override synchronized run(){ //code implementation } Here, the @Override annotation specifies that the run() method overrides a method from the Runnable interface, and synchronized is a reserved keyword in Java used to define a method or block as synchronized. Synchronization of a run() ... Read More