Raja has Published 469 Articles

How can we use the StringTokenizer class in Java?

raja

raja

Updated on 01-Dec-2023 14:52:22

267 Views

A StringTokenizer is a subclass of Object class and it can allow an application to break a string into tokens. A set of delimiters can be specified either at creation time or on a per-token basis. An instance of StringTokenizer behaves in two ways depending on whether it was created ... Read More

How to save the elements of a TreeSet to a file in Java?

raja

raja

Updated on 01-Dec-2023 14:47:10

477 Views

A TreeSet is a subclass of AbstractSet class and it does not allow duplicate elements. By default, TreeSet stores the elements in an ascending order and retrieval speed of an element out of a TreeSet is faster. The TreeSet class internally uses a TreeMap to store elements. The elements in ... Read More

When can we use the getClass() method in Java?

raja

raja

Updated on 01-Dec-2023 14:43:00

222 Views

The getClass() method is from Object class and it returns an instance of the Class class. When we declare a new instance of an object, it will be referring to a class. There can only be one class per JVM but multiple object referring to it. So when we get ... Read More

What is the purpose of using a dumpStack() method in Java?

raja

raja

Updated on 01-Dec-2023 14:39:39

683 Views

The dumpStack() method is a static method of Thread class and it can be used to print or display stack tracing of the current thread to System.err. The purpose of the dumpStack() method is basically for debugging and Internally this method is calling the printStackTrace() method of Throwable class. This ... Read More

How to check if the string begins with specific substring in Java?

raja

raja

Updated on 01-Dec-2023 14:34:36

2K+ 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 use the startsWith() method of String class to ... Read More

Can we override a protected method in Java?

raja

raja

Updated on 01-Dec-2023 11:07:06

7K+ Views

Yes, the protected method of a superclass can be overridden by a subclass. If the superclass method is protected, the subclass overridden method can have protected or public (but not default or private) which means the subclass overridden method can not have a weaker access specifier. Example class A { ... Read More

Importance of a Locale class in Java?

raja

raja

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

262 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

2K+ 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

3K+ 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

25K+ 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

Advertisements