- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34494 Articles for Programming
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
863 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
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
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
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
792 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
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 :
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
512 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
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