Raja has Published 760 Articles

Importance of a Locale class in Java?

raja

raja

Updated on 01-Dec-2023 10:43:28

175 Views

A Locale class is used to perform locale operations and supply locale information to the user. A Locale is defined as a set of parameters that represents a geographical location or place where some operation occurs. The important methods of Locale class are getAvailableLocales(), getCountry(), getDefault(), getDisplayLanguage(), getDisplayCountry(), getUnicodeLocaleKeys() etc. The ... Read More

How to serialize and deserialize an object in Java?

raja

raja

Updated on 01-Dec-2023 10:38:28

1K+ Views

The Serialization is a process of changing the state of an object into a byte stream, an object is said to be serializable if its class or parent classes implement either the Serializable or Externalizable interface and the Deserialization is a process of converting the serialized object back into a ... Read More

How can we implement a Custom HashSet in Java?

raja

raja

Updated on 01-Dec-2023 10:02:50

2K+ Views

A HashSet implements Set interface which does not allow duplicate values. A HashSet is not synchronized and is not thread-safe. When we can add any duplicate element to a HashSet, the add() method returns false and does not allow to add a duplicate element to HashSet. Syntax public class HashSet extends AbstractSet ... Read More

How can we stop a thread in Java?

raja

raja

Updated on 01-Dec-2023 09:32:48

23K+ Views

Whenever we want to stop a thread from running state by calling stop() method of Thread class in Java. This method stops the execution of a running thread and removes it from the waiting threads pool and garbage collected. A thread will also move to the dead state automatically when ... Read More

How do threads communicate with each other in Java?

raja

raja

Updated on 29-Nov-2023 11:11:33

4K+ Views

Inter-thread communication involves the communication of threads with each other. The three methods that are used to implement inter-thread communication in Java. wait() This method causes the current thread to release the lock. This is done until a specific amount of time has passed or another thread calls the notify() or notifyAll() ... Read More

How to compare two dates in Java?

raja

raja

Updated on 29-Nov-2023 11:05:25

77K+ Views

In Java, two dates can be compared using the compareTo() method of Comparable interface. This method returns '0' if both the dates are equal, it returns a value "greater than 0" if date1 is after date2 and it returns a value "less than 0" if date1 is before date2. Syntax int compareTo(T ... Read More

Can a "this" keyword be used to refer to static members in Java?

raja

raja

Updated on 29-Nov-2023 10:58:08

556 Views

No, the "this" keyword cannot be used to refer to the static members of a class. This is because the “this” keyword points to the current object of the class and the static member does not need any object to be called. The static member of a class can be ... Read More

Which collection classes are thread-safe in Java?

raja

raja

Updated on 29-Nov-2023 10:31:28

11K+ Views

A thread-safe class is a class that guarantees the internal state of the class as well as returned values from methods, are correct while invoked concurrently from multiple threads. The collection classes that are thread-safe in Java are Stack, Vector, Properties, Hashtable, etc. Stack The Stack class in Java implements the stack ... Read More

How can we get the name of the Enum constant in Java?

raja

raja

Updated on 29-Nov-2023 10:25:32

5K+ Views

An Enum is a special datatype which is added in Java 1.5 version and it can be used to define a collection of constants, when we need a predefined list of values that do not represent some kind of numeric or textual data, we can use an Enum. The enums ... Read More

How to print the first character of each word in a String in Java?

raja

raja

Updated on 29-Nov-2023 10:10:45

5K+ Views

A String class can be used to represent the character strings, all the string literals in a Java program are implemented as an instance of a String class. The Strings are constants and their values cannot be changed (immutable) once created. We can print the first character of each word in ... Read More

Advertisements