Java SQL Date setTime Method with Example

Arushi
Updated on 29-Sep-2024 02:50:39

985 Views

In this program, we will connect to a MySQL database using JDBC, insert a new record into the dispatches table, and retrieve all records from the table. The setTime() method from Date class of java.util package that accepts a variable of long type, representing the number of milliseconds from the epoch time (January 1, 1970, 00:00:00.000 GMT) to the required time, and sets the specified time value to the current Date object. //Setting time date.setTime(time_value_in_long); The goal of the program is to demonstrate how to interact with a database using JDBC and handle Date and Time objects in Java. ... Read More

Binary Search Implementation on Char Array in Java

Anvi Jain
Updated on 29-Sep-2024 02:49:49

1K+ Views

In this article, we will learn to implement binary search on char array using Java. The binary search on a char array can be implemented by using the Arrays.binarySearch() method of java.util package. This method returns the index of the required char element if it is available in the array, otherwise, it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array. Problem Statement Write a program in Java to implement binary search on char array Input 'b', 's', 'l', 'e', 'm' Output The sorted array is: b ... Read More

Increase Row Height in JTable

George John
Updated on 29-Sep-2024 02:48:44

2K+ Views

In the given article, we will learn to write a program in Java to increase the row height in a JTable. The example creates a table with different languages and their difficulty levels and then modifies the row height using the setRowHeight() method. Steps to increase the row height in a JTable  Following are the steps to increase the row height in a JTable − Import the necessary classes from javax.swing package. Initialize a DefaultTableModel and create a JTable with it. Add columns to represent languages and ... Read More

Iterate Through Each Character of a String in Java

AmitDiwan
Updated on 29-Sep-2024 02:48:31

2K+ Views

In this article, we will understand how to iterate through each character of the string using Java. The string is a datatype that contains one or more characters and is enclosed in double quotes (“ ”). Char is a datatype that contains an alphabet an integer or a special character. Problem Statement Write a program to Iterate through each character of the string. Below is a demonstration of the same − Input The string is defined as: Java Program Output The characters in the string are: J, a, v, a, , P, r, o, g, r, a, m, Different approaches ... Read More

Sort ArrayList in Ascending Order in Java

AmitDiwan
Updated on 29-Sep-2024 02:48:17

1K+ Views

In this article, we will learn how to sort an ArrayList in ascending order using Java. Sorting allows us to arrange elements in a specific order. We will use the Collections.sort() method, which simplifies sorting, whether you're dealing with integers or strings. The program will demonstrate sorting an ArrayList of numbers and names in ascending order. Problem Statement Write a Java program that sorts an ArrayList of elements in ascending order. We'll look at two examples—one with integer values and another with string values. Input 1 Points[50, 29, 35, 11, 78, 64, 89, 67] Output 1 Points (ascending)[11, 29, 35, ... Read More

Find Area of a Trapezium in Java

AmitDiwan
Updated on 29-Sep-2024 02:48:03

911 Views

In this article, we will understand how to find the area of a trapezium using Java. The trapezium is a type of quadrilateral that has at least one pair of sides parallel to each other. The parallel sides of a trapezium are called bases and the non-parallel sides of a trapezium are called legs. It is also called a trapezoid. The area of a trapezium is calculated using the formula − (height/2 * (side_1 + side_2). i.e. Area = ½ x (sum of the lengths of the parallel sides) x perpendicular distance between parallel sides Below is a demonstration of ... Read More

Check if None of the Strings in the List Matches a Condition in Java

Nancy Den
Updated on 29-Sep-2024 02:47:46

916 Views

In this article, you will learn how to check if none of the strings in a list start with a specific letter using Java. This approach is useful for validating or filtering data. We will use the Stream API to evaluate the condition and return a boolean result based on whether any string starts with the given letter. Problem Statement Write a program in Java to check if none of the strings in the list matches the condition. Input pqr, stu, vwx, yza, vwxy Output No match for the starting letter as f? = true Steps to check if none of ... Read More

Adjust LocalDate to First Day of Month using TemporalAdjusters Class

karthikeya Boyini
Updated on 29-Sep-2024 02:47:31

2K+ Views

In this article, we will learn how to adjust a LocalDate object to find the first day of the month in Java. The program demonstrates how to take a given date and use the TemporalAdjusters class to easily get the first day of that month. This functionality is useful in various applications, such as scheduling events or generating monthly reportsTemporalAdjusters provides utility methods for common date adjustments. We will learn how to set a specific date and adjust it to find the first day of the month. Problem Statement Write a Java program that adjusts a LocalDate to find and ... Read More

Set JComboBox in JOptionPane

George John
Updated on 29-Sep-2024 02:47:14

2K+ Views

In this article, we will explore how to create a graphical user interface (GUI) in Java using JComboBox and JOptionPane. The program will display a pop-up dialog that contains a drop-down list, allowing the user to select their favorite sport from a list. By default, one of the options will be pre-selected, but users can change the selection.  Steps to set JComboBox in JOptionPane Following are the steps to set JComboBox in JOptionPane − Create a JPanel by initializing a JPanel to hold the components. Create a JComboBox by setting up a JComboBox ... Read More

Get First Friday in a Month - Java Program

Samual Sam
Updated on 29-Sep-2024 02:47:00

767 Views

In this article, we'll explore how to get the first Friday of any given month in Java. The program will use Java's LocalDate class and TemporalAdjusters to automatically calculate the first Friday based on the input date. We will walk through how this works step by step and see how the code performs this task. Problem Statement Write a program in Java to get the first Friday in a month. Below is a demonstration of the same − Input Current date = 2019-04-01 Output Current date = 2019-04-01 First Friday date = 2019-04-05 Steps to get the first Friday in a ... Read More

Advertisements