Raja has Published 760 Articles

How can we make JTextField accept only numbers in Java?

raja

raja

Updated on 11-Feb-2020 10:41:56

12K+ Views

By default, a JTextField can allow numbers, characters, and special characters. Validating user input that is typed into a JTextField can be difficult, especially if the input string must be converted to a numeric value such as an int.In the below example, JTextField only allows entering numeric values.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class ... Read More

What is the importance of a SwingWorker class in Java?

raja

raja

Updated on 11-Feb-2020 10:36:25

563 Views

A SwingWorker class enables us to perform an asynchronous task in a worker thread (such as a long-running task) then update Swing components from the Event Dispatch Thread (EDT) based on the task results. It was introduced in Java 1.6 Version.SwingWorker classThe java.swing.SwingWorker class is a task worker, which performs time-consuming tasks in the ... Read More

How to change/increase the heap size of the Java Virtual Machine in Java?

raja

raja

Updated on 11-Feb-2020 10:21:05

1K+ Views

A Java program can execute in the Java Virtual Machine (JVM) uses the heap memory to manage the data. If our Java program requires more memory, there is a possibility that the Java Virtual Machine(JVM) will begin to throw OutOfMemoryError instances when attempting to instantiate an object in Java.To Change/increase the JVM Heap ... Read More

What are the differences between a static block and a constructor in Java?

raja

raja

Updated on 11-Feb-2020 10:10:35

2K+ Views

Static blockThe static blocks are executed at the time of class loading.The static blocks are executed before running the main () method.The static blocks don't have any name in its prototype.If we want any logic that needs to be executed at the time of class loading that logic needs to placed inside the static ... Read More

What are the differences between import and static import statements in Java?

raja

raja

Updated on 11-Feb-2020 09:29:38

4K+ Views

We can use an import statement to import classes and interface of a particular package. Whenever we are using import statement it is not required to use the fully qualified name and we can use short name directly. We can use static import to import static member from a particular class ... Read More

How many types of anonymous inner classes are defined in Java?

raja

raja

Updated on 11-Feb-2020 09:26:32

989 Views

An anonymous inner class is an inner class which is declared without any class name at all. In other words, a nameless inner class is called an anonymous inner class. Since it does not have a name, it cannot have a constructor because we know that a constructor name is the ... Read More

How to instantiate member inner class in Java?

raja

raja

Updated on 11-Feb-2020 09:21:14

1K+ Views

A class that is declared inside a class but outside a method is known as member inner class.We can instantiate a member Inner class in two waysInvoked within the classInvoked outside the classRules for Inner ClassThe outer class (the class containing the inner class) can instantiate as many numbers of ... Read More

How to call an interface method in Java?

raja

raja

Updated on 11-Feb-2020 08:06:59

18K+ Views

In order to call an interface method from a java program, the program must instantiate the interface implementation program. A method can then be called using the implementation object.Examplepublic interface InterfaceDemo{     default public void displayNameDefault(String name){        System.out.println("Your name is : " + name);    } ... Read More

Why should we use a StringBuffer instead of a String in Java?

raja

raja

Updated on 11-Feb-2020 08:04:56

719 Views

A StringBuffer is a thread-safe, mutable sequence of characters.Unlike a String class (immutable), the StringBuffer class is mutable. That is, we can change the contents of a StringBuffer object.When we modify a string of StringBuffer class, we are not creating a new String object, but rather operating directly on the ... Read More

What are the main features and enhancements introduced in Java 9?

raja

raja

Updated on 11-Feb-2020 08:00:28

106 Views

Oracle has released Java 9 version with a rich set of new features and brings a lot of new enhancements.Below are a few important features and enhancements introduced in Java 9.Factory Methods for Collections: Factory methods are special kinds of static methods that can be used to create unmodifiable instances of collections, ... Read More

Advertisements