Medium Length Date Format with Java MessageFormat Class

Krantik Chavan
Updated on 26-Jun-2020 07:28:36

189 Views

To format message with medium 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 class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. ... Read More

Count Matching Characters in a Pair of Java Strings

Chandu yadav
Updated on 26-Jun-2020 07:28:27

2K+ Views

In order to find the count of matching characters in two Java strings the approach is to first create character arrays of both the strings which make comparison simple.After this put each unique character into a Hash map.Compare each character of other string with created hash map whether it is present or not in case if present than put that character into other hash map this is to prevent duplicates.In last get the size of this new created target hash map which is equal to the count of number of matching characters in two given strings.Example Live Demoimport java.util.HashMap; public class ... Read More

Create Immutable Class in Java

George John
Updated on 26-Jun-2020 07:27:35

370 Views

An immutable class object's properties cannot be modified after initialization. For example String is an immutable class in Java. We can create a immutable class by following the given rules below.Make class final − class should be final so that it cannot be extended.Make each field final − Each field should be final so that they cannot be modified after initialization.Create getter method for each field. − Create a public getter method for each field. fields should be private.No setter method for each field. − Do not create a public setter method for any of the field.Create a parametrized constructor ... Read More

Create Your Own Helper Class in Java

Arjun Thakur
Updated on 26-Jun-2020 07:26:54

4K+ Views

A helper class serve the following purposes.Provides common methods which are required by multiple classes in the project.Helper methods are generally public and static so that these can be invoked independently.Each methods of a helper class should work independent of other methods of same class.Following example showcases one such helper class.Examplepublic class Tester {    public static void main(String[] args) {       int a = 37;       int b = 39;       System.out.println(a + " is prime: " + Helper.isPrime(a));       System.out.println(b + " is prime: " + Helper.isPrime(b));    } } ... Read More

Short Length Format for Date with Java MessageFormat Class

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

220 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 class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. ... Read More

Convert Octal Number to Decimal Number in Java

karthikeya Boyini
Updated on 26-Jun-2020 07:26:09

735 Views

To convert octal to decimal number, use the Integer.parseInt() method with radix 8. Here, the radix is for Octal i.e. 8.Let’s say we have the following octal string.String myOctal = "25";To convert it to decimal, use the Integer.parseInt() method.int val = Integer.parseInt(myOctal, 8);The following is the complete example.Example Live Demopublic class Demo {    public static void main(String []args) {       String myOctal = "25";       System.out.println("Octal = "+myOctal);       int val = Integer.parseInt(myOctal, 8);       System.out.println("Decimal = "+val);    } }OutputOctal = 25 Decimal = 21

Difference Between TreeMap, HashMap, and LinkedHashMap in Java

George John
Updated on 26-Jun-2020 07:25:35

735 Views

HashMap, TreeMap and LinkedHashMap all implements java.util.Map interface and following are their characteristics.HashMapHashMap has complexity of O(1) for insertion and lookup.HashMap allows one null key and multiple null values.HashMap does not maintain any order.TreeMapTreeMap has complexity of O(logN) for insertion and lookup.TreeMap does not allow null key but allow multiple null values.TreeMap maintains order. It stores keys in sorted and ascending order.LinkedHashMapLinkedHashMap has complexity of O(1) for insertion and lookup.LinkedHashMap allows one null key and multiple null values.LinkedHashMap maintains order in which key-value pairs are inserted.Example Live Demoimport java.util.HashMap; import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; public class Tester { ... Read More

CSS Stress Property

Lakshmi Srinivas
Updated on 26-Jun-2020 07:14:27

189 Views

This property specifies the height of "local peaks" in the intonation contour of a voice. English is a stressed language, and different parts of a sentence are assigned primary, secondary, or tertiary stress. The possible values are −number − A value between '0' and '100'. The meaning of values depends on the language being spoken. For example, a level of '50' for a standard, English-speaking male voice (average pitch = 122Hz), speaking with normal intonation and emphasis would have a different meaning than '50' for an Italian voice.

Check If Value Is ASCII 7-Bit Control Character in Java

karthikeya Boyini
Updated on 26-Jun-2020 07:13:37

300 Views

To check whether the entered value is ASCII 7-bit control character, check the characters ASCII value before 32 and 127. These are the control characters.Here, we have a character.char one = ' n ';Now, we have checked a condition with if-else to check for character less than 32 (ASCII) and equal to 127.if (one < 32 || one == 127) { System.out.println("Given value is a control character!"); } else {    System.out.println("Given value is not a control character!"); }Example Live Demopublic class Demo {    public static void main(String []args) {       char one = '';       ... Read More

Check Whether Character is ASCII 7-bit in Java

Samual Sam
Updated on 26-Jun-2020 07:11:17

425 Views

To check whether the character is ASCII 7 bit or not, check whether given value’s ASCII value is less than 128 or not.Here, we have a character.char one = '-';Now, we have checked a condition with if-else for ASCII 7-bit character.if (c < 128) { System.out.println("Given value is ASCII 7 bit!"); } else {    System.out.println("Given value is not an ASCII 7 bit!"); }The following is an example wherein we check a character for ASCII 7-bit.Example Live Demopublic class Demo {    public static void main(String []args) {       char c = '-';       System.out.println("Given value = ... Read More

Advertisements