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

214 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

725 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

717 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

296 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

420 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

Set Printing Double-Sided Documents with CSS

Chandu yadav
Updated on 26-Jun-2020 07:07:38

584 Views

When printing double-sided documents, the page boxes on the left and right pages should be different.ExampleIt can be expressed through two CSS pseudo-classes as follows −    

Stack in Java

Samual Sam
Updated on 26-Jun-2020 07:05:40

2K+ Views

A stack class is provided by the Java collection framework and it implements the Stack data structure. The stack implements LIFO i.e. Last In First Out. This means that the elements pushed last are the ones that are popped first.The following are some of the methods.Sr.NoMethods & Description1boolean empty()Tests if this stack is empty. Returns true if the stack is empty, and returns false if the stack contains elements.2Object peek( )Returns the element on the top of the stack, but does not remove it.3Object pop( )Returns the element on the top of the stack, removing it in the process.4Object push(Object ... Read More

Permutation and Combination in Java

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

6K+ Views

Permutation and Combination are a part of Combinatorics. Permutation is the different arrangements that a set of elements can make if the elements are taken one at a time, some at a time or all at a time. Combination is is the different ways of selecting elements if the elements are taken one at a time, some at a time or all at a time.An example of this is given as follows −Permutation = factorial(n) / factorial(n-r); Combination = factorial(n) / (factorial(r) * factorial(n-r)); n = 5 r = 3 Permutation = 60 Combination = 10A program that demonstrates this ... Read More

Advertisements