Programming Articles - Page 2456 of 3363

When can a .class file get created in Java?

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 is compiled into a separate class file if the ".java " file has more than one class.Exampleclass A {    A() {       System.out.println("This is class A");    } } class B {    B() {       System.out.println("This is class B");    } } class C { ... Read More

How can we check an underflow occurs in Java?

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

426 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 UnderlowTest {    public static void main(String[] args) {       int num1 = -2147483648;       int num2 = -1;       System.out.println("Number 1: " + num1);       System.out.println("Number 2: " + num2);       long sum = (long)num1 + (long)num2;     ... Read More

How can we filter a JTable in Java?

raja
Updated on 12-Feb-2020 07:54:44

5K+ Views

A JTable provides a very flexible possibility to create and display tables. The TableModel interface defines methods for objects that specify the contents of a table. The AbstractTableModel class is typically extended to provide a custom implementation of a model table. A JTable class provides the ability to edit tables using the method setCellEditor() allows an object of the TableCellEditor interface.We can filter a table using the setRowFilter() method of TableRowSorter class.Exampleimport java.awt.*; import java.awt.event.*; import java.util.regex.*; import javax.swing.*; import javax.swing.table.*; public class FilterTableTest extends JFrame {    private JTable table;    private TableModel model;    public FilterTableTest() {       setTitle("FilterTable Test");       ... Read More

Can a "this" keyword be used to refer to static members in Java?

raja
Updated on 29-Nov-2023 10:58:08

946 Views

No, the "this" keyword cannot be used to refer to the static members of a class. This is because the “this” keyword points to the current object of the class and the static member does not need any object to be called. The static member of a class can be accessed directly without creating an object in Java. Example public class StaticTest { static int a = 50; static int b; static void show() { System.out.println("Inside the show() method"); b = a + 5; ... Read More

How to compare two dates in Java?

Vivek Verma
Updated on 20-Jun-2025 17:05:55

82K+ Views

In Java, we can compare two dates using the compareTo() method of the Comparable interface. This is a common way to compare two dates, and this method returns an integer value based on which you can specify which date occurs before, after, or if it is equal. Here are the return values by this method, based on which you verify the date appearance: ... Read More

How do threads communicate with each other in Java?

raja
Updated on 29-Nov-2023 11:11:33

6K+ Views

Inter-thread communication involves the communication of threads with each other. The three methods that are used to implement inter-thread communication in Java. wait() This method causes the current thread to release the lock. This is done until a specific amount of time has passed or another thread calls the notify() or notifyAll() method for this object. notify() This method wakes a single thread out of multiple threads on the current object’s monitor. The choice of thread is arbitrary. notifyAll() This method wakes up all the threads that are on the current object’s monitor. Example class BankClient { int balAmount = 5000; synchronized void withdrawMoney(int ... Read More

How does a ClassLoader work in Java?

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

969 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 delegated to the parent class loader.The types of ClassLoader in Java are given as followsBootstrap ClassLoaderExtensions ClassLoaderSystem ClassLoaderExamplepublic class ClassLoaderTest {    public static void main(String[] args) {       System.out.println("class loader for this class: " + ClassLoaderTest.class.getClassLoader());       System.out.println("class loader for DNSNameService: " + sun.net.spi.nameservice.dns.DNSNameService.class.getClassLoader());     ... Read More

Importance of the getCause() method in Java?

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 its constructors or that was determined by the formation of the initCause() method of Throwable class.Syntaxpublic Throwable getCause()Examplepublic class GetCauseMethodTest {    public static void main(String[] args) throws Exception {       try {          myException();       } catch(Exception e) {          System.out.println("Cause ... Read More

Windows 10 Toast Notifications with Python

Pavitra
Updated on 30-Aug-2019 12:55:21

1K+ Views

We can create a notifier for the events that occurred in Windows using Python. This is very simple with the win10toast module. If you are familiar with the Toast in Android then understanding the Toast notifications with Python is a piece of cake. We can generate notifications whenever an event occurs as a remainder. Let's see.Run the following command in command-line to install win10toast modulepip install win10toastIf the module successfully installed then, you will get the following result when you run the command.Collecting win10toast Downloading https://files.pythonhosted.org/packages/d4/ba/95c0ea87d9bcad68b90d8cb130a313b939c88d8338a2fed7c11eaee972fe/win10toast-0.9-py2.py3-none-any.whl Collecting pypiwin32 (from win10toast) Downloading https://files.pythonhosted.org/packages/d0/1b/2f292bbd742e369a100c91faa0483172cd91a1a422a6692055ac920946c5/pypiwin32-223-py3-none-any.whl Requirement already satisfied: setuptools in c:\users\hafeezulkareem\anaconda3\lib\site-packages (from win10toast) ... Read More

How to generate an UnsupportedOperationException in Java?

Vivek Verma
Updated on 18-Jun-2025 18:31:11

530 Views

In Java, an exception is an event that occurs during the execution of a program. When an Exception occurs, the normal flow of the program is disrupted, and the program/application terminates abnormally, which is not recommended; therefore, these exceptions can be handled. What is UnsupportedOperationException in Java? An UnsupportedOperationException is a subclass of the RuntimException class in Java, and it can be thrown to indicate that the requested operation is not supported. The UnsupportedOperationException class is a member of the Java Collections Framework. This exception is thrown by almost all of the concrete collections like List, Queue, Set, and Map. ... Read More

Advertisements