Smita Kapse has Published 560 Articles

Long style format for Date with Java MessageFormat class

Smita Kapse

Smita Kapse

Updated on 26-Jun-2020 07:31:20

161 Views

To format message with long style format of date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat ... Read More

Short Length format for Date with Java MessageFormat class

Smita Kapse

Smita Kapse

Updated on 26-Jun-2020 07:26:44

112 Views

To format message with short length format for date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat ... Read More

How to compile assert in Java?

Smita Kapse

Smita Kapse

Updated on 26-Jun-2020 06:50:33

498 Views

In order to compile assert in Java, we simply set the boolean expression as false.Let us see an example program −Example Live Demopublic class Example {    public static void main(String[] args) {       assert false;       System.out.println("Compiled and executed successfully!!!");    } }OutputCompiled and executed successfully!!!

Validate city and state with Java Regular Expressions

Smita Kapse

Smita Kapse

Updated on 25-Jun-2020 15:12:20

811 Views

In order to match the city and state using regular expression, we use the matches method in Java. The java.lang.String.matches() method returns a boolean value which depends on the matching of the String with the regular expression.Declaration − The java.lang.String.matches() method is declared as follows −Example Live Demopublic class Example { ... Read More

Replace one string with another string with Java Regular Expressions

Smita Kapse

Smita Kapse

Updated on 25-Jun-2020 15:00:57

7K+ Views

To replace one string with another string using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String ... Read More

Get the list of all the public fields in Java

Smita Kapse

Smita Kapse

Updated on 25-Jun-2020 14:59:28

514 Views

An array of field objects is returned by the method java.lang.Class.getFields(). These field objects include the accessible public fields of the class that is represented by the class object.Also, the getFields() method returns a zero length array if the class or interface has no public fields that are accessible or ... Read More

Display the maximum amount of memory in Java

Smita Kapse

Smita Kapse

Updated on 25-Jun-2020 14:55:44

197 Views

In order to display the maximum amount of memory in Java, we use the maxMemory() method. It is a method of the java.lang.Runtime Class. It returns the maximum amount of memory that the Java Virtual Machine will try to use.Declaration − The java.lang.Runtime.maxMemory() method is declared as follows −public long ... Read More

Generate Random bytes in Java

Smita Kapse

Smita Kapse

Updated on 25-Jun-2020 14:52:19

6K+ Views

In order to generate random bytes in Java, we use the nextBytes() method. The java.util.Random.nextBytes() method generates random bytes and provides it to the user defined byte array.Declaration − The java.util.Random.nextBytes() method is declared as follows −public void nextBytes(byte[] bytes)where bytes is the byte array.Let us see a program to ... Read More

Sort items of an ArrayList with Collections.reverseOrder() in Java

Smita Kapse

Smita Kapse

Updated on 25-Jun-2020 13:19:27

320 Views

In order to sort items of an ArrayList with Collections.reverseOrder() in Java, we need to use the Collections.reverseOrder() method which returns a comparator which gives the reverse of the natural ordering on a collection of objects that implement the Comparable interface.Declaration − The java.util.Collections.reverseOrder() method is declared as follows -public ... Read More

Working with Array.setInt to fill an array in Java

Smita Kapse

Smita Kapse

Updated on 25-Jun-2020 13:04:06

68 Views

In order to fill an array in Java, we use the Array.setInt() method. The java.lang.reflect.Array.setInt(Object array, int index, int value) method assigns the value of the component with a particular index of the given array object to the specified integer value.Declaration − The java.lang.reflect.Array.setInt(Object array, int index, int value) is ... Read More

Advertisements