Found 33676 Articles for Programming

How to display Java Runtime Environment (JRE) version

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

771 Views

Use the System.getProperty() method in Java to get the Java Runtime Environment.It’s syntax is −String getProperty(String key)Above, the key is the name of the system property. Since, we want the Java Runtime Environment name, therefore we will add the key as −java.versionThe following is an example −Example Live Demopublic class Demo { public static void main(String[] args) { System.out.print("Java Specification Version: "); System.out.println(System.getProperty("java.specification.version")); System.out.print("java Runtime Environment (JRE) version: "); System.out.println(System.getProperty("java.version")); } ... Read More

Display Java Specification Version

Samual Sam
Updated on 30-Jul-2019 22:30:24

418 Views

Use the System.getProperty() method in Java to get the Java Specification Version.It’s syntax is −String getProperty(String key)Above, the key is the name of the system property. Since, we want the Java Specification Version name, therefore we will add the key as −java.specification.versionThe following is an example −Example Live Demopublic class Demo { public static void main(String[] args) { System.out.print("Java Specification Version: "); System.out.println(System.getProperty("java.specification.version")); } }OutputJava Specification Version: 1.8

Java program to print the initials of a name with last name in full

Samual Sam
Updated on 30-Jul-2019 22:30:24

10K+ Views

When the full name is provided, the initials of the name are printed with the last name is printed in full. An example of this is given as follows −Full name = Amy Thomas Initials with surname is = A. ThomasA program that demonstrates this is given as follows −Example Live Demoimport java.util.*; public class Example {    public static void main(String[] args) {       String name = "John Matthew Adams";       System.out.println("The full name is: " + name);       System.out.print("Initials with surname is: ");       int len = name.length();       ... Read More

Comparison of Float in Java

karthikeya Boyini
Updated on 26-Jun-2020 12:34:33

334 Views

To compare Float in Java, use the following methods −Method 1 − compareTo(newFloat) method in JavaThe java.lang.Float.compareTo() method compares two Float objects. This method returns the value 0 if the new float value is numerically equal to this Float; a value less than 0 if this Float is numerically less than new float; and a value greater than 0 if this Float is numerically greater than new float.Here is an example −Example Live Demoimport java.lang.*; public class Demo {    public static void main(String args[]) {       Float f1 = new Float("25.2");       Float f2 = new ... Read More

Apply modulus operator to floating-point values in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

761 Views

To apply modulus (%) operator to floating-point values in an effortless task. Let us see how.We have the following two values −double one = 9.7; double two = 1.2;Let us now apply the modulus operator −one % twoThe following is the complete example that displays the output as well −Example Live Demopublic class Demo { public static void main(String args[]) { double one = 9.7; double two = 1.2; System.out.println( one % two ); } }Output0.09999999999999964

Java Program to return the hexadecimal value of the supplied byte array

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

156 Views

The following is the supplied byte array −byte[] b = new byte[]{'x', 'y', 'z'};We have created a custom method “display” here and passed the byte array value. The same method converts byte array to hex string −public static String display(byte[] b1){    StringBuilder strBuilder = new StringBuilder();    for(byte val : b1){     strBuilder.append(String.format("%02x", val&0xff)); } return strBuilder.toString(); }Let us see the entire example now −Example Live Demopublic class Demo { public static void main(String args[]) { byte[] b = new byte[]{'x', 'y', ... Read More

Format date with DateFormat.LONG in Java

Alshifa Hasnain
Updated on 15-Jan-2025 18:58:25

2K+ Views

In this article, we will learn to use DateFormat.LONG to format dates in Java. Handling dates and times efficiently is crucial for most applications. The Java Date and DateFormat classes provide a flexible and simple way to format dates and times. What is DateFormat.LONG? DateFormat.LONG is a constant provided by the DateFormat class in Java. It represents a predefined style for formatting dates in a long, readable format. When you use DateFormat.LONG, Java will format the date in a verbose format, typically displaying the day, month, and year in a comprehensive, localized form.DateFormat.LONG is a constant for long-style patterns. For ... Read More

Format date with DateFormat.MEDIUM in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

3K+ Views

DateFormat.MEDIUM is a constant for medium style pattern.Firstly, we will create date object −Date dt = new Date(); DateFormat dateFormat;Let us format date for different locale with DateFormat.MEDIUM −// CHINESE dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.CHINESE); // CANADA dateFormat = DateFormat.getDateInstance(DateFormat. MEDIUM, Locale.CANADA);The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt = new Date(); DateFormat dateFormat; // Date Format MEDIUM constant ... Read More

Java Program to Parse and Format a Number into Binary

Alshifa Hasnain
Updated on 26-Dec-2024 20:42:49

709 Views

In this article, we will learn to parse and format a number into binary using Java. Binary representation plays a crucial role, especially when working with low-level operations, data storage, or network communication. Java, a widely used object-oriented programming language, provides several tools to manipulate numbers and convert them into different formats. What is Binary Representation? A binary number is a base-2 numeral system that uses two digits: 0 and 1. Every number in the Decimal System (base-10) can be converted into binary by representing it as a sum of powers of 2.For example − ... Read More

Java program to get the current value of the system timer in nanoseconds

karthikeya Boyini
Updated on 18-Nov-2024 22:30:20

354 Views

In this article, we use the System.nanoTime() method in Java to get the current value of the system timer in nanoseconds. It returns the current value of the most precise available system timer, in nanoseconds. Problem StatementGiven that you need to get the current value of the system timer in nanoseconds, write a Java program that retrieves this value using the System.nanoTime() method.Input There is no specific input as the program retrieves the system's current time in nanoseconds directly.Output Current Value: 49908709882168 nanoseconds Steps to get the current value of the system timer in nanosecondsThe following are the ... Read More

Advertisements