Java Articles

Page 133 of 450

What are new methods added to the String class in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 332 Views

In this article, we will learn about the new methods added to the String class in Java 9. We will learn about Strings and the new methods in the String class, along with examples. Strings A String is the type of object that contains a collection of characters enclosed by double quotes (" "). The Java platform provides the String class to create and manipulate strings in Java. The String class is immutable, so that once it is created, a String object cannot be changed. String is the only class where operator overloading is supported in Java, we can concatenate ...

Read More

What will happen when we try to override final method of the superclass in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 2K+ Views

Any method that is declared as final in the superclass cannot be overridden by a subclass. If we try to override the final method of the super class, we will get a compile-time error.  Rules for Implementing Method Overriding The method declaration should be the same as that of the method that is to be overridden. The class (subclass) should extend another class (superclass), prior to even try overriding. The Sub Class can never override final methods of the Super Class. Final method A method is declared final when ...

Read More

How can we create an unmodifiable Map in Java 9?\\n

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 532 Views

In this article, we will learn to create an unmodifiable Map in Java 9. First, we will learn about Map and Unmodifiable Map and after that we will be knowing the different ways through which we can create an unmodifiable map (Map.of method and unmodifiableMap() Method). Map In Java, a Map is an interface in the Collections framework used to store data in the form of key-value pairs. Each key in the map is unique and maps to some value. Some of the implementations of the Map interface are: HashMap ...

Read More

Differences between orTimeout() and completeOnTimeOut() methods in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 2K+ Views

In this article, we will learn about the differences between the orTimeout() and the completeOnTimeout() methods in Java. Both the orTimeout() and completeOnTimeout() methods are defined in the CompletableFuture class, and these two methods were introduced in Java 9. CompletableFuture class The CompletableFuture class, introduced in Java 8, represents a Future that can have its value and status set explicitly. It also supports dependent functions and actions that are triggered upon the completion of the future. In Java 9, the CompletableFuture API received further enhancements. The following are some common methods of the CompletableFuture class: ...

Read More

How can we change the background and foreground color of a JTooltip in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 436 Views

In this article, we will learn to change the background and foreground color of a JTooltip. We will be using UIManager.put(), we customize the tooltip for a JLabel by setting a white background and green text, which will improve the appearance of the default tooltip. What is a JToolTip? A JToolTip is a subclass of the JComponent class, and we can create a tooltip for any Java component by using the setToolTipText() method. It can be used to set up a tooltip for the component. The important methods of a JToolTip class are getAccessibleContext(), getComponent(), paramString(), and updateUI(). How to ...

Read More

How can we implement a rounded JTextField in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 3K+ Views

In this article, we will learn to implement a rounded JTextField in Java. The JtextField is rectangular in shape, and to create a custom JTextField with rounded corners, we will use the RoundRectangle2D class and with the help of fillRoundRect() and drawRoundRect() methods in Java Swing. What is a JTextField? A JTextField is a subclass of the JTextComponent class, and it is one of the most important components that allows the user to an input text value in a single-line format.  Below is the graphical representation of a JTextField:  A JTextField class will generate an ActionListener interface when we ...

Read More

How can we show/hide the echo character of a JPasswordField in Java?\\n

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 2K+ Views

In this article, we will learn to show/hide the echo character of a JPasswordField in Java. The password in this will be hidden with *. And we will be using the setEchoChar() method to toggle between hidden and visible text in a Swing based application. What is a JPasswordField? A JPasswordField is a subclass of JTextField, and each character entered in a JPasswordField can be replaced by an echo character. This allows confidential input for passwords. By default, the echo character is the asterisk(*). The important methods of JPasswordField are get password(), getText(), getAccessibleContext() and etc. What is the echo ...

Read More

How can we catch a double click and enter key events for a JList in Java?\\n

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 1K+ Views

In this article, we will learn to catch a double click and enter key events for a JList in Java. We will be using Java Swing to detect double click and Enter key events on a JList. When we double click an item in the list or press "Enter" key after selecting an item, the selected item is displayed. What is a JList? A JList can extend the JComponent class, which allows us to choose either a single or multiple selections. A JList can generate a ListSelectionListener interface, and it includes one abstract method, valueChanged(). Below is the graphical representation ...

Read More

How can we implement the paintComponent() method of a JPanel in Java?\\n

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 8K+ Views

In this article, we will learn to implement the paintComponent() method of a JPanel in Java. In Swing, custom rendering of components is achieved by overriding the paintComponent() method. What is a JPanel? A JPanel is a lightweight container and it is an invisible component in Java. A JPanel's default layout is FlowLayout. After the JPanel has been created, other components can be added to the JPanel object by calling its add() method inherited from the Container class. What is a paintComponent() Method? The paintComponent() method is needed to draw something on a JPanel other than drawing the background color. This ...

Read More

How can we implement a splash screen using JWindow in Java?\\n

Alshifa Hasnain
Alshifa Hasnain
Updated on 09-Jun-2025 813 Views

JWindow is a Swing component that is used to create a splash screen easily as splash screen as it displays a screen without a title bar or window management buttons. In this article, we will learn to implement a splash screen using JWindow in Java.  What is a JWindow? A JWindow is a container that can be displayed anywhere on the user's desktop. It does not have the title bar, window management buttons, etc, like a JFrame. The JWindow contains a JRootPane as its only child class. The contentPane can be the parent of any children of the JWindow. Like a ...

Read More
Showing 1321–1330 of 4,496 articles
« Prev 1 131 132 133 134 135 450 Next »
Advertisements