Karthikeya Boyini has Published 2383 Articles

Format integer values with java.text.DecimalFormat

karthikeya Boyini

karthikeya Boyini

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

77 Views

Here, we are using the DecimalFormat class in Java to format integer value, which is the java.text.DecimalFormat package.Let us take the following format: DecimalFormat("0.######E0") and use the format() method for this purpose −new DecimalFormat("0.#####E0").format(5089) new DecimalFormat("0.#####E0").format(608)Since, we have used DecimalFormat class in Java, therefore importing the following package in a ... Read More

SimpleDateFormat(“hh:mm:ss a”) in Java

karthikeya Boyini

karthikeya Boyini

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

3K+ Views

The following format displays time from −hh:mm:ssThe following format displays time with AM/ PM marker −hh:mm:ss aHere, we are using the SimpleDateFormat class to display date and time. Let us set it for the format we want i.e time and AM/PM Marker −Format f = new SimpleDateFormat("hh:mm:ss a"); String strResult ... Read More

Display a percentage in Java

karthikeya Boyini

karthikeya Boyini

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

1K+ Views

To display a percentage in Java, use the following DecimalFormat.DecimalFormat decFormat = new DecimalFormat("#%");Since, we have used the DecimalFormat class, therefore do not forget to import the following package −import java.text.DecimalFormat;Now, let us learn how to display percentage −decFormat.format(0.80) decFormat.format(-0.19) decFormat.format(1.88)The above will be displayed as −80% -19% 188%The following ... Read More

SimpleDateFormat(“HH:mm:ss Z”) in Java

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

The Z means "zero hour offset", also known as "Zulu time" (UTC) in the ISO 8601 time representation. However, ACP 121 standard defines the list of military time zones and derives the "Zulu time" from theGreenwich Mean Time (GMT).Let us see the usage of SimpleDateFormat(“HH:mm:ss Z”) −Format f = new ... Read More

DecimalFormat("00.00E0") in Java

karthikeya Boyini

karthikeya Boyini

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

243 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("00.00E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("00.00E0"); System.out.println(decFormat.format(-289.8787)); System.out.println(decFormat.format(8.19));Since, we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete example ... Read More

DecimalFormat("###E0") in Java

karthikeya Boyini

karthikeya Boyini

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

74 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("###E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("##E0"); System.out.println(decFormat.format(-267.9965)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88));Since we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete ... Read More

SimpleDateFormat('E, dd MMM yyyy HH:mm:ss Z') in Java

karthikeya Boyini

karthikeya Boyini

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

4K+ Views

Using the SimpleDateFormat(“E, dd MMM yyyy HH:mm:ss Z”), wherein E is for Day of Week −// displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); System.out.println("Today's date and time = "+simpleformat.format(cal.getTime()));Since we have used the Format and SimpleDateFormat class above, ... Read More

MySQL concat() to create column names to be used in a query?

karthikeya Boyini

karthikeya Boyini

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

646 Views

To create column names to be used in a query, you need to use a user-defined variable with the set command. The syntax is as follows −SET @anyVariableName := (    SELECT CONCAT    (       "SELECT",    GROUP_CONCAT(CONCAT(" 1 as ", COLUMN_NAME) SEPARATOR ', '), " FROM ... Read More

Display three letter-month value with SimpleDateFormat('MMM') in Java

karthikeya Boyini

karthikeya Boyini

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

3K+ Views

Using the SimpleDateFormat(“MMM”) to display three-letter month −Format f = new SimpleDateFormat("MMM"); String strMonth = f.format(new Date()); System.out.println("Month (Three-letter format) = "+strMonth);Since, we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The ... Read More

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

karthikeya Boyini

karthikeya Boyini

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

231 Views

Use System.nanoTime() method in Java to get the current value of the system timer in nanoseconds. It d returns the current value of the most precise available system timer, in nanoseconds.We are getting the system timer value in a long type −long res = System.nanoTime();The following is an example −Example Live ... Read More

Advertisements