Raja has Published 760 Articles

Can Enum implements an interface in Java?

raja

raja

Updated on 22-Nov-2023 12:35:44

9K+ Views

Yes, Enum implements an interface in Java, it can be useful when we need to implement some business logic that is tightly coupled with a discriminatory property of a given object or class. An Enum is a special datatype which is added in Java 1.5 version. The Enums are constants, ... Read More

How can we convert a hexadecimal value to a byte in Java?

raja

raja

Updated on 22-Nov-2023 12:19:46

111 Views

A Byte class is a subclass of Number class and it can wrap a value of primitive type byte in an object. An object of type Byte contains a single field whose type is a byte. The important methods of Byte class are byteValue(), compare(), compareTo(), decode(), parseByte(), valueOf() and ... Read More

How can we implement a timer thread in Java?

raja

raja

Updated on 22-Nov-2023 12:13:21

3K+ Views

The Timer class schedules a task to run at a given time once or repeatedly. It can also run in the background as a daemon thread. To associate Timer with a daemon thread, there is a constructor with a boolean value. The Timer schedules a task with fixed delay as ... Read More

How to make a singleton enum in Java?

raja

raja

Updated on 22-Nov-2023 12:08:04

2K+ Views

The singleton pattern restricts the instantiation of a class to one object. INSTANCE is a public static final field that represents the enum instance. We can get the instance of the class with the EnumSingleton.INSTANCE but it is better to encapsulate it in a getter in case if we want ... Read More

What is the importance of a StringWriter in Java?

raja

raja

Updated on 22-Nov-2023 12:03:35

92 Views

The StringWriter class is s subclass of Writer class and it writes the String to an output stream. To write a string, this character stream collects the string into a string buffer and then constructed a string. The buffer of StringWriter automatically grows according to data. The important methods of ... Read More

What is the importance of Runtime class in Java?

raja

raja

Updated on 22-Nov-2023 09:53:24

922 Views

The java.lang.Runtime class is a subclass of Object class, can provide access to various information about the environment in which a program is running. The Java run-time environment creates a single instance of this class that is associated with a program. The Runtime class does not have any public constructors, so ... Read More

What is the use of StrictMath class in Java?

raja

raja

Updated on 22-Nov-2023 09:39:02

67 Views

The java.lang.StrictMath is a final class and it is a subclass of Object class. The StrictMath class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. We need not create an instance for StrictMath class because all the methods in StrictMath class ... Read More

What are the steps to read static members in a Java class?

raja

raja

Updated on 22-Nov-2023 09:34:23

270 Views

A static variable gets created at the time of class loading even before the execution of a static block and the purpose of the static block is to assign value to the static variables. A static variable stores a value that is shared between all instances of the class it ... Read More

Why an interface cannot implement another interface in Java?

raja

raja

Updated on 22-Nov-2023 09:29:18

9K+ Views

An interface cannot implement another interface in Java. An interface in Java is essentially a special kind of class. Like classes, the interface contains methods and variables. Unlike classes, interfaces are always completely abstract. An interface is defined just like a class except for the keyword interface in place of a class, ... Read More

Why an interface doesn't have a constructor whereas an abstract class have a constructor in Java?

raja

raja

Updated on 22-Nov-2023 09:23:10

7K+ Views

A Constructor is to initialize the non-static members of a particular class with respect to an object. Constructor in an Interface An Interface in Java doesn't have a constructor because all data members in interfaces are public static final by default, they are constants (assign the values at the time of declaration). There ... Read More

Previous 1 ... 5 6 7 8 9 ... 76 Next
Advertisements