Found 34494 Articles for Programming

Locale-specific formatting in Java

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

98 Views

For locale-specific formatting, firstly import the following packages.import java.util.Calendar; import java.util.Formatter; import java.util.Locale;Create a Formatter and Calendar object −Formatter f = new Formatter(); Calendar c = Calendar.getInstance();We are formatting for different Locales −f.format(Locale.TAIWAN, "Locale.TAIWAN: %tc", c); f.format(Locale.ITALY, "Locale.ITALY: %tc", c);The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; import java.util.Locale; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar c = Calendar.getInstance(); f.format(Locale.TAIWAN, "Locale.TAIWAN: %tc", c); ... Read More

Get Operating System temporary directory / folder in Java

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

862 Views

To get the temporary directory in Java, use the System.getProperty() method. Use theIt’s syntax is −String getProperty(String key)Above, the key is the name of the system property. Since, we want the Java Home Directory name, therefore we will add the key as −java.io.tmpdirThe following is an example −Example Live Demopublic class Demo { public static void main(String []args){ String strTmp = System.getProperty("java.io.tmpdir"); System.out.println("OS current temporary directory: " + strTmp); System.out.println("OS Name: " + System.getProperty("os.name")); ... Read More

Java Program to return a Date set to the last possible millisecond of the minute

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

53 Views

Let us first set the calendar object −Calendar calendar = Calendar.getInstance();Use the getMaximum() method in Java to returns the maximum value for the given calendar field. We will use it to set the minute, second and milliseconds.For seconds −calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));For milliseconds −calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));The following is an example that returns a Date set to the last possible millisecond of the minute −Example Live Demoimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo {    public static void main(String[] argv) throws Exception {       Calendar calendar = Calendar.getInstance();       // seconds       calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));       // milliseconds ... Read More

Java Program to return a Date set to the first possible millisecond of the month after midnight

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

114 Views

Use the getMaximum() method in Java to returns the maximum value for the given calendar field. We will use it to set the minute, second and milliseconds.Let us first declare a calendar object −Calendar dateNoon = Calendar.getInstance();Now, we will set the hour, minute, second and millisecond to the first possible millisecond of the month after midnight −// hour, minute and second calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); // millisecond calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));The following is an example that return a Date set to the first possible millisecond of the month after midnight −Example Live Demoimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo { ... Read More

Java Program to return a Date set to the last possible millisecond of the month before midnight

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

244 Views

Use the getMaximum() method in Java to returns the maximum value for the given calendar field. We will use it to set the minute, second and millisecond.Let us first declare a calendar object −Calendar dateNoon = Calendar.getInstance();Now, we will set the hour, minute, second and millisecond to the last possible millisecond on the month before midnight.// hour, minute and second calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); // millisecond calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));Now, do the following for month and day of month −calendar.set(Calendar.DAY_OF_MONTH, 1); // first day of month calendar.add(Calendar.MONTH, 1); calendar.add(Calendar.DAY_OF_MONTH, -1);The following is an example to return a Date set to ... Read More

Get Java Home Directory

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

791 Views

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

Display path separator in Java

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

152 Views

To display the path separator, use the Properties class and import the following package −import java.util.Properties;Use the getProperties() method first and create an object −Properties p = System.getProperties();Now, set the key for path separator −p.getProperty("path.separator")The following is an example −Example Live Demoimport java.util.Properties; public class Demo { public static void main(String[] args) { Properties p = System.getProperties(); System.out.println("Separator is "+p.getProperty("path.separator")); } }OutputSeparator is :

Java Program to get Operating System name and version

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

2K+ Views

Use the System.getProperty() method in Java to get the Operating System name and version.It’s syntax is −String getProperty(String key)Above, the key is the name of the system property. Since, we want the OS name and version, therefore we will add the key as −Operating System name - os.name Operating System version - os.versionThe following is an example −Example Live Demopublic class Demo { public static void main(String []args){ System.out.println("OS Name: " + System.getProperty("os.name")); System.out.println("OS Version: " + System.getProperty("os.version")); } }OutputOS Name: Linux OS ... Read More

How to display Java Runtime Environment (JRE) version

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

509 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

289 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

Advertisements