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
Programming Articles - Page 2544 of 3363
846 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 background.A SwingWorker instance interacts with 3 threads, Current thread, the Worker thread, and the Event Dispatch thread(EDT).The Current thread calls the execute() method to kick off the task to the background and returns immediately.The Worker thread executes our own version of the doInBackground() method continuously in the background.The Event Dispatch Thread (EDT) wakes up from time to ... Read More
2K+ Views
In this article, we will learn about the differences between a MouseListener and a MouseMotionListener in Java. We can implement a MouseListener interface when the mouse is stable while handling the mouse event, whereas we can implement a MouseMotionListener interface when the mouse is in motion while handling the mouse event. Mouse Listener A MouseListener is fired when we press, release or click (press followed by release) a mouse button (left or right button) at the source object or position the mouse pointer at (enter) and away (exit) from the source object. Abstract Methods A MouseListener interface declares the following five ... Read More
11K+ Views
The JOptionPane is a subclass of the JComponent class, which includes static methods for creating and customizing modal dialog boxes using a simple code. The JOptionPane is used instead of JDialog to minimize the complexity of the code. The JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning, and error) or the custom icons specified by the user. Types of Dialogue Boxes in JOptionPane The JOptionPane class is used to display four types of dialog boxes: MessageDialog ConfirmDialog InputDialog ... Read More
2K+ Views
The double data type in Java stores double-precision 64-bit IEEE 754 floating point number. It is used as the default type for decimal value in Java.Like all other primitive variables double also have a wrapper class (Double) wrapping the primitive data type. Since java supports auto boxing, the primitive value and the object can be used interchangeably.You can convert a double value into String in various different ways in Java −Using the “+” operator −The + operator is an addition operator but when used with Strings it acts as a concatenation operator. It concatenates the other operand to String and ... Read More
349 Views
Static variables − Static variables are also known as class variables. You can declare a variable static using the keyword. Once you declare a variable static there would only be one copy of it in the class, regardless of how many objects are created from it.public static int num = 39;final − Once you declare a variable final you cannot reassign value to it. When you declare a variable of a class static and final we are making it constant.Rules to be followedInitialization is mandatory − It is not mandatory to initialize the instance variables of a class in java. ... Read More
1K+ Views
A constant variable is the one whose value is fixed and only one copy of it exists in the program. Once you declare a constant variable and assign value to it, you cannot change its value again throughout the program.You can create a constant in c language using the constant keyword (one way to create it) as −const int intererConstant = 100; or, const float floatConstant = 16.254; ….. etcConstants in javaUnlike in C language constants are not supported in Java(directly). But, you can still create a constant by declaring a variable static and final.Static − Once you declare a ... Read More
11K+ Views
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.Syntaxswitch(expression) { case value : // Statements break; case value : // Statements break; // You can have any number of case statements. default : // Statements }Strings in switchYes, we can use a switch statement with Strings in Java. While doing so you need ... Read More
2K+ Views
The “+” operator with a String acts as a concatenation operator.Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object.In-fact adding a double value to String is the easiest way to convert a double value to Strings.Exampleimport java.util.Scanner; public class StringsExample { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter a double value: "); double d = sc.nextDouble(); System.out.println("Enter a String value: "); ... Read More
313 Views
Since JSE1.5 you can pass a variable number of values as argument to a method. These arguments are known as var args and they are represented by three dots (…)Syntaxpublic myMethod(int ... a) { // method body }Rules to follow while using varargs in JavaWe can have only one variable argument per method. If you try to use more than one variable arguments a compile time error is generated.ExampleIn the following Java example we are trying to accepts two varargs from the method sample().public class VarargsExample{ void demoMethod(int... ages), String... names) { ... Read More
631 Views
A method can accept a variable number of parameters thanks to a Java feature called variable arguments, or varargs. This can be helpful for methods that need to be able to manage an unknown or variable number of inputs. We had two ways to handle methods that needed to take a variable number of arguments prior to introduction of varargs in Java 5. One way was to use overloaded methods. The method has to be developed in numerous iterations, each with a different number of arguments. If the process had many arguments, it might become complicated and challenging ... Read More