Raja has Published 469 Articles

How to set the color to alternate rows of JTable in Java?

raja

raja

Updated on 03-Jul-2020 11:48:46

3K+ 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.We can set the color to alternate rows of JTable by overriding ... Read More

When can a .class file get created in Java?

raja

raja

Updated on 03-Jul-2020 08:24:35

2K+ Views

A Java class file has a ".class" extension and contains the Java bytecode. This class file can be executed by the Java Virtual Machine (JVM). A  ".class" file is created as a result of successful compilation by the Java compiler from the ".java" file. Each class in the .java file ... Read More

How can we check an underflow occurs in Java?

raja

raja

Updated on 03-Jul-2020 08:19:34

393 Views

When a value is assigned to a variable that is less than the minimum allowed value for that variable, then an underflow occurs. There is no exception thrown by the JVM if an underflow occurs in Java and it is the responsibility of a programmer to handle the underflow conditions.Examplepublic class ... Read More

Importance of the getCause() method in Java?

raja

raja

Updated on 03-Jul-2020 07:40:44

2K+ Views

The getCause() method is from Throwable class and we can use this method which returns the cause of the exception or returns null if the cause of the exception is not known. The getCause() method doesn’t accept any arguments and doesn’t throw an exception. It returns the cause that was provided by one of ... Read More

How does a ClassLoader work in Java?

raja

raja

Updated on 03-Jul-2020 07:39:59

935 Views

A Java Class is stored in the form of byte code in a .class file after it is compiled. The ClassLoader loads the class of the Java program into memory when it is required. The ClassLoader is hierarchical and so if there is a request to load a class, it is ... Read More

Can we have an empty catch block in Java?

raja

raja

Updated on 03-Jul-2020 07:18:31

6K+ Views

Yes, we can have an empty catch block. But this is a bad practice to implement in Java.Generally, the try block has the code which is capable of producing exceptions, if anything wrong in the try block, for instance,  divide by zero, file not found,  etc. It will generate an exception that is ... Read More

How can we disable the leaf of JTree in Java?

raja

raja

Updated on 03-Jul-2020 05:46:15

389 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 ... Read More

How can we remove a selected row from a JTable in Java?

raja

raja

Updated on 02-Jul-2020 13:12:48

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 ... Read More

Importance of SerialVersionUID keyword in Java?

raja

raja

Updated on 02-Jul-2020 09:02:37

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 ... Read More

How can we call the invokeLater() method in Java?

raja

raja

Updated on 02-Jul-2020 08:12:57

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 ... Read More

Advertisements