Samual Sam has Published 2310 Articles

Java program to multiply long integers and check for overflow

Samual Sam

Samual Sam

Updated on 02-Sep-2024 19:29:01

2K+ Views

To check for Long overflow, we need to check the Long.MAX_VALUE with the multiplied long result, Here, Long.MAX_VALUE is the maximum value of the Long type in Java. Let us see an example wherein long values are multiplied and if the result is more than the Long.MAX_VALUE, then an exception ... Read More

Java program to list short month names

Samual Sam

Samual Sam

Updated on 28-Aug-2024 21:18:31

2K+ Views

In this article, we will learn to list up the short month names in Java. To do so we will be using DateFormatSymbols class from java.text package. java.text: This package offers classes and interfaces for managing text, dates, numbers, and messages in a way that is not dependent on any specific ... Read More

Check whether the String contains only digit characters in Java

Samual Sam

Samual Sam

Updated on 27-Aug-2024 18:49:01

2K+ Views

Introduction In this article, we'll explore how to check whether a given string contains only digits or a mix of digits and other characters in Java. We'll achieve this by using the String class and its matches() method. Problem Statement Given a string write a Java program to check ... Read More

Java program to get operating system name and version

Samual Sam

Samual Sam

Updated on 27-Aug-2024 18:48:33

2K+ Views

In this article, we will discuss how to get the operating system name and version in Java. To get the name and version of the operating system we will be using the System.getProperty() method. Steps to get the operating system name and version The following are the steps to get the operating ... Read More

Java program to subtract year from current date

Samual Sam

Samual Sam

Updated on 27-Aug-2024 18:47:50

2K+ Views

In this article, we will learn to subtract a year from the current date using Java. We will be using the Calender class of java.util package. Calendar class in Java is an abstract class that provides different methods to convert between a specific instant in time and a set of ... Read More

Java program to get highest key stored in TreeMap

Samual Sam

Samual Sam

Updated on 16-Aug-2024 23:24:59

2K+ Views

In this article, we will learn how to retrieve the highest key stored in a TreeMap. We will create a simple Java program that demonstrates how to create a TreeMap, add key-value pairs to it, and then use the lastKey() method to find the highest key in the map. ... Read More

Java program to get Milliseconds between two time instants

Samual Sam

Samual Sam

Updated on 12-Aug-2024 23:13:17

3K+ Views

In this article, we will demonstrate how to calculate the difference in milliseconds between two Instant objects using the ChronoUnit class. It shows how to work with time-based classes in the java.time package, specifically focusing on creating and manipulating time instants and calculating durations between them. ChronoUnit: A standard set of ... Read More

Java program to sort short array

Samual Sam

Samual Sam

Updated on 06-Aug-2024 22:46:38

2K+ Views

In this article, we will learn to sort a short array in Java using the Arrays.sort() method. Begin by declaring and initializing an unsorted short array, then sort it and display the sorted array. Arrays.sort() method : This method sorts the elements of array in ascending order which have specified ... Read More

Java program to display previous month from GregorianCalendar

Samual Sam

Samual Sam

Updated on 25-Jul-2024 19:36:40

3K+ Views

The GregorianCalendar class in Java allows us to manipulate dates and times easily. In this example, we will create a GregorianCalendar object and use it to display the current date and the date of the previous month. Problem Statement Write a Java program and create a GregorianCalendar object, display the ... Read More

Java program to calculate the factorial of a given number using while loop

Samual Sam

Samual Sam

Updated on 18-Jul-2024 14:22:45

4K+ Views

The factorial of a number is a fundamental concept in mathematics, representing the product of all positive integers up to that number. Calculating the factorial of a given number is a common problem in programming, and Java provides a straightforward way to achieve this using a while loop. ... Read More

Previous 1 ... 4 5 6 7 8 ... 231 Next
Advertisements