Object Oriented Programming Articles

Page 359 of 589

Java program to add 3 months to the calendar

Samual Sam
Samual Sam
Updated on 16-Sep-2024 1K+ Views

In this article, we will learn to add 3 months to the calendar. We will take the current date and add 3 months to it using Calendar class in Java. You’ll see how to handle date manipulation and update the date accordingly. Problem Statement Write a program in Java to add 3 months to the calendar. Below is the demonstration of the same − Input Current Date = Fri Nov 23 06:38:56 UTC 2018 Output Updated Date = Sat Feb 23 06:38:56 UTC 2019 Different approaches Below are the different approaches to add 3 months to the calendar − ...

Read More

Java program to change JLabel text after creation

Samual Sam
Samual Sam
Updated on 16-Sep-2024 3K+ Views

In this article, we will learn to change JLabel text after creation in Java. We'll cover two scenarios: changing the label text immediately after creation and updating it in response to a button click. Different approaches to change JLabel text after creation Below are the different approaches to change JLabel text after the creation − Using setText() Method Using a button click Update JLabel text using setText() method Following are the steps to update JLabel text immediately after creation − First we will import JFrame, JLabel, and ...

Read More

Java program to extract a single quote enclosed string from a larger string using Regex

Pranay Arora
Pranay Arora
Updated on 16-Sep-2024 1K+ Views

Regex or Regular Expression is the language used for pattern-matching and string manipulation. It consists of a sequence of characters that define a search pattern and can be used for performing actions like search, replace, and even validate on text input. A regular expression consists of a series of characters and symbols that amount to form a search pattern. In this article, we are going to see how to write a Java program to extract a single quote-enclosed string from a larger string using Regex. Java provides support for regex from the java.util.regex package. The pattern class represents a compiled ...

Read More

Java program to check whether a number is positive or negative

Shriansh Kumar
Shriansh Kumar
Updated on 13-Sep-2024 1K+ Views

In this article, we will learn to check whether the number is positive or negative in Java. To check whether the specified number is positive or negative can be determined with respect to 0. A number greater than 0 is considered a positive number whereas a number less than 0 is considered a negative number, we can use Java conditional statements like if-else-if blocks or ternary operators. Before that let's discuss the problem statement with the help of examples − Problem Statement Given an integer number as an input, write a Java program to check whether the number is positive ...

Read More

Java program to find whether given character is vowel or consonant

karthikeya Boyini
karthikeya Boyini
Updated on 13-Sep-2024 14K+ Views

In this article, we will learn to find whether a given character is a vowel or consonant using Java. In the English alphabet, the characters 'a', 'e', 'i', 'o', and 'u' are vowels and the remaining letters are consonants. To find whether the given letter is a vowel or consonant. Using a loop and or operator verify whether the given character is 'a' or 'e' or 'i' or 'o' or 'u' else it is consonant. Steps to find whether given character is vowel or consonant Following are the steps to find whether given character is a vowel or consonant− ...

Read More

Java program to find if the given number is a leap year?

Chandu yadav
Chandu yadav
Updated on 13-Sep-2024 80K+ Views

In this article, we will learn to find if a year is a leap year or not using Java. Finding whether a year is a leap or not is a bit tricky. We generally assume that if a year number is evenly divisible by 4 is a leap year. But it is not the only case. A year is a leap year if − It is evenly divisible by 100 If it is divisible by 100, then it should also be divisible by 400 Except this, all ...

Read More

Java program to print diamond star pattern

Alshifa Hasnain
Alshifa Hasnain
Updated on 13-Sep-2024 1K+ Views

In this article, we will understand how to print the Diamond Star pattern using Java. The pattern is formed by using multiple for-loops and print statements. Output Below is the demonstration of the diamond star pattern − The diamond star pattern : * *** ***** ******* ********* *********** ************* *************** ************* *********** ********* ******* ***** ...

Read More

Java program to set title position

George John
George John
Updated on 11-Sep-2024 2K+ Views

In this article, you'll learn how to position the title of a border in a Java Swing application using the setTitlePosition() method. We'll position the title above the border's top line by utilizing the TitledBorder.ABOVE_TOP constant. This technique is useful for customizing the appearance of your Swing components. To set title position, use the setTitlePosition() method in Java. Let’s say we have to position the title above the border's top line. For that, use the constant ABOVE_TOP for the border − setTitlePosition(TitledBorder.ABOVE_TOP); Steps to set title position Following are the steps to set title position in Java − ...

Read More

Java sql.Time toString() method with example

Vikyath Ram
Vikyath Ram
Updated on 11-Sep-2024 1K+ Views

In this article, you'll learn how to convert a Time object into a String using the toString() method from the java.sql.Time class. This method allows us to easily transform a Time object into its JDBC escape format, which can then be handled as a string. //Retrieving the Time object Time timeObj = rs.getTime("DeliveryTime"); //Converting the Time object to String format String time = timeObj.toString(); Steps for using Java sql.Time toString() Method Following are the steps for using Java sql.Time toString() Method − Create a MySQL table named dispatches. Insert some sample records into ...

Read More

Java Program to initialize a HashMap with Lambda Expressions

Shriansh Kumar
Shriansh Kumar
Updated on 11-Sep-2024 2K+ Views

Initialization of a Java HashMap means creating an instance of the HashMap class and adding elements to it. The standard way to initialize a HashMap is by using the new keyword. However, we will use the lambda expression in this article. Lambda expressions are methods without any names. It was introduced with the release of Java8. And, HashMap is a class of Java Collection Framework that implements Map Interface. It stores its element in key-value pairs. The Key is an object that is used to retrieve value associated with it. Example 1 The following Java program explains how to initialize ...

Read More
Showing 3581–3590 of 5,881 articles
« Prev 1 357 358 359 360 361 589 Next »
Advertisements