Found 9326 Articles for Object Oriented Programming

Display just hour and minute using Formatter in Java

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

164 Views

Firstly, create a Formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();To display hour using Formatter class, use the ‘l’ conversion a character −f = new Formatter(); System.out.println(f.format("Hour: %tl", c));To display minute using Formatter class, use the ‘M’ conversion character −f = new Formatter(); System.out.println(f.format("Minute: %1$tM", c));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar c = Calendar.getInstance(); ... Read More

Display complete date and time information using Formatter in Java

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

100 Views

Firstly, create a Formatter and Calendar object.Formatter f = new Formatter(); Calendar cal = Calendar.getInstance();Now display the current date and time. We have shown the date here in both lowercase and uppercase −f = new Formatter(); System.out.println(f.format("Date and Time (lowercase): %tc", cal)); f = new Formatter(); System.out.println(f.format("Date and Time (uppercase): %Tc", cal));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); ... Read More

Display minutes with SimpleDateFormat('mm') in Java

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

1K+ Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“mm”) to display minutes in two-digits.Format f = new SimpleDateFormat(‘”mm”);Now, get the minutes in a string.String strMinute = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); ... Read More

Display minutes with SimpleDateFormat(“m”) in Java

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

107 Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“m”) to display minutes.Format f = new SimpleDateFormat(‘”m”);Now, get the minutes in a string.String strMinute = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); ... Read More

Display hour with SimpleDateFormat(“H”) in Java

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

322 Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“H”) to display hour in a day.Format f = new SimpleDateFormat("H");Now, get the hour −String strHour = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); ... Read More

Display month by name and number in Java

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

322 Views

Use the ‘b’ conversion character for month name in Java.Use the ‘m’ conversion character for month number in Java.Here, we are using Formatter and Calendar class, therefore import the following packages.import java.util.Calendar; import java.util.Formatter;The following is an example to display month name and number −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); System.out.println("Current date and time: "+cal.getTime()); ... Read More

Get system start time from RuntimeMXBean in Java

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

187 Views

RuntimeMXBean in the management interface for the runtime system of the Java virtual machine.RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();To get the system start time, use the getStartTime() method −new Date(runtimeMX.getStartTime()The following is an example −Example Live Demoimport java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class Demo { public static void main(String args[]) throws Exception { RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean(); System.out.println("System Start Time = "+new Date(runtimeMX.getStartTime())); } }OutputSystem Start Time = Mon Nov 26 07:03:19 UTC 2018

Get Boot path from RuntimeMXBean in Java

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

126 Views

RuntimeMXBean in the management interface for the runtime system of the Java virtual machine.RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();To get the boot path, use the getBootClassPath() method −runtimeMX.getBootClassPath()The following is an example −Example Live Demoimport java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class Demo {    public static void main(String args[]) throws Exception {       RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();       System.out.println("Class path = "+runtimeMX.getClassPath());       System.out.println("Boot Class path = "+runtimeMX.getBootClassPath());     } }OutputClass path = /home/cg/root/GNUstep/Library/Libraries/Java:/usr/GNUstep/Local/Library/Libraries/Java:/usr/GNUstep/System/ Library/Libraries/Java::/usr/share/java/mysql-connector-java.jar:.:/var/www/html/lib:/var/www/html/lib/dom4j- 1.6.jar:/var/www/html/lib/guava-18.0.jar:/var/www/html/lib/jackson-all.jar:/var/www/html/lib/jaxen- 1.1.4.jar:/var/www/html/lib/jcommon.jar:/var/www/html/lib/jdom2- 2.0.5.jar:/var/www/html/lib/jfreechart.jar:/var/www/html/lib/junit-4.12.jar:/var/www/html/lib/spymemcached- 2.10.3.jar:/var/www/html/lib/stax-1.2.0.jar:/var/www/html/lib/xstream-1.4.7.jar:/var/www/html/lib/gson- 2.3.1.jar:/var/www/html/lib/hamcrest-core-1.3.jar Boot Class path = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141- 1.b16.fc26.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141- 1.b16.fc26.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141- 1.b16.fc26.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141- 1.b16.fc26.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141- 1.b16.fc26.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141- 1.b16.fc26.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141- 1.b16.fc26.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.fc26.x86_64/jre/classesRead More

Get ClassPath from RuntimeMXBean in Java

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

84 Views

RuntimeMXBean in the management interface for the runtime system of the Java virtual machine.RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();To get the class path, use the getClassPath() method −runtimeMX.getClassPath()The following is an example −Example Live Demoimport java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class Demo { public static void main(String args[]) throws Exception { RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean(); System.out.println("Class path = "+runtimeMX.getClassPath()); } }OutputClass path = /home/cg/root/GNUstep/Library/Libraries/Java:/usr/GNUstep/Local/Library/Libraries/Java:/usr/GNUstep/System/ Library/Libraries/Java::/usr/share/java/mysql-connector-java.jar:.:/var/www/html/lib:/var/www/html/lib/dom4j- 1.6.jar:/var/www/html/lib/guava-18.0.jar:/var/www/html/lib/jackson-all.jar:/var/www/html/lib/jaxen- 1.1.4.jar:/var/www/html/lib/jcommon.jar:/var/www/html/lib/jdom2- 2.0.5.jar:/var/www/html/lib/jfreechart.jar:/var/www/html/lib/junit-4.12.jar:/var/www/html/lib/spymemcached- 2.10.3.jar:/var/www/html/lib/stax-1.2.0.jar:/var/www/html/lib/xstream-1.4.7.jar:/var/www/html/lib/gson- 2.3.1.jar:/var/www/html/lib/hamcrest-core-1.3.jarRead More

Get the JVM uptime from RuntimeMXBean in Java

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

263 Views

RuntimeMXBean in the management interface for the runtime system of the Java virtual machine −RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();Let us get the JVM uptime using the getUptime() method −runtimeMX.getUptime()The following is an example −Example Live Demoimport java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class Demo { public static void main(String args[]) throws Exception { RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean(); System.out.println("JVM Uptime = "+runtimeMX.getUptime() + " ms"); } }OutputJVM Uptime = 81 msLet us run the code again, to get the following output −JVM Uptime = 78 ms

Advertisements