Alshifa Hasnain

Alshifa Hasnain

Converting Code to Clarity

About

A professional technical content writer with Java programming skills. I have a desire to write informative and detailed Java articles for both beginner and professional developers. Having a strong background in HTML, CSS, JavaScript, Java, JDBC, JSP, Spring, and Hibernate.

221 Articles Published

Articles by Alshifa Hasnain

Page 5 of 23

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 810 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

How can we highlight the selected tab of a JTabbedPane in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Jun-2025 972 Views

In this article, we will learn to highlight the selected tab of a JTabbedPane in Java. JTabbedPane is a common Swing component that is used to organize content into multiple tabs, while highlighting a selected tab will improve the GUI and make the interface interactive. What is a JTabbedPane? A JTabbedPane is a subclass of the JComponent class, and it can provide easy access to more than one panel. Each tab is associated with a single component that can be displayed when the tab is selected. A JTabbedPane can generate a ChangeListener interface when a tab is selected. What do ...

Read More

Java program to check the birthday and print happy birthday message

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

In this article, we will understand how to check the birthday and print Happy Birthday message. Checking the birthday is achieved by comparing the present day and the given birthday. Problem Statement Write a program that checks if today's date matches a predefined birthday date. If the dates match, the program should print a "Happy Birthday" message otherwise, it should indicate that today is not the birthday. Below is a demonstration of the same − Input Birthday Date: 15 July Output Today’s Date is 20-12-2021 Today is not my birthday Different ways to check the birthday ...

Read More

How to implement the Fibonacci series in JShell in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Jun-2025 235 Views

In this article, we will learn to implement the Fibonacci series in JShell in Java 9. First, we will learn how the Fibonacci series works, then learn two approaches(iterative and recursive) to implement this sequence in the JShell environment. JShell JShell is a Java shell tool introduced in Java 9 that allows us to execute Java code and print the result immediately. It is a REPL (Read-Evaluate-Print-Loop) tool that runs from the command-line prompt. What is a Fibonacci Series? A number is said to be in the Fibonacci series if each subsequent number is the sum of the previous two ...

Read More

Java Program to Create Pyramid and Pattern

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Jun-2025 4K+ Views

In this article, we will learn to create pyramid patterns using Java. It will help us to understand how loops work.  for loop while loop Java program to create pyramid patterns We are going to print the following pyramid patterns:  Half Star Pyramid Inverted Half Star Pyramid Star Pyramid Inverted Star Pyramid Numeric Pyramid Pattern 1: Half Star Pyramid We will initialize the row to 5 and a loop runs from i-1 to i

Read More

Can we declare a constructor as private in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 05-Jun-2025 11K+ Views

Java constructor is a special method used to initialize objects. It has the same name as the class and is automatically called when an object is created. You can also declare a constructor as private to restrict object creation from outside the class. What is a Private Constructor? A private constructor is a constructor that is declared using the private access modifier. It restricts object creation from outside the class i.e., the class having a private constructor cannot be subclassed. Private constructors are used in design patterns like Singleton, or to prevent subclassing or instantiation. Purpose of a Private ...

Read More

Can we define a method name same as class name in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 05-Jun-2025 5K+ Views

A method is a collection of statements that are grouped together to perform an operation. In Java, you can define a method having the same name as the class but it is not recommended as per the coding standard. Can We define a Method Having Same as Class? Yes, It is allowed to define a method with the same name as that of a class. There is no compile-time or runtime error will occur. But this is not recommended as per coding standards in Java. Normally the constructor name and class name always the same in Java. Example of a ...

Read More

How can we show a popup menu when the user right-clicks on a JComboBox in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 21-May-2025 601 Views

A JComboBox is a Swing component that has a built-in left-click menu. In this article, we will learn how to show a popup menu when the user right-clicks on a JComboBox in Java.  What is a JComboBox? A JComboBox is a subclass of the JComponent class that displays a drop-down list and gives users options that they can select only one item at a time. A JComboBox can be editable or read-only. The getSelectedItem() Method A getSelectedItem() method can be used to get the selected or entered item from a combo box. What is a Popup Menu? A popup menu is ...

Read More
Showing 41–50 of 221 articles
« Prev 1 3 4 5 6 7 23 Next »
Advertisements