Raja has Published 469 Articles

Can we extend an enum in Java?

raja

raja

Updated on 07-Feb-2020 05:58:29

4K+ Views

No, we cannot extend an enum in Java. Java enums can extend java.lang.Enum class implicitly, so enum types cannot extend another class.Syntaxpublic abstract class Enum> implements Comparable, Serializable {    // some statements }EnumAn Enum type is a special data type which is added in Java 1.5 version.An Enum is used to define ... Read More

When can we use intern() method of String class in Java?

raja

raja

Updated on 07-Feb-2020 05:45:33

471 Views

The intern() method of String class can be used to deal with the string duplication problems in Java. Using intern() we can save a lot of memory consumed by duplicate string instances. A string is duplicate if it contains the same content as another string but it can be occupied different memory ... Read More

How to use the substring() method of java.lang.String class in Java?

raja

raja

Updated on 07-Feb-2020 05:41:38

234 Views

The substring() method returns a String datatype which corresponds to the original String starting from the begin index until the end Index. If the end index is not specified, it is imperative that the endIndex is the String length. Since we are dealing with the String, the index starts at '0' ... Read More

Can we write any statements between try, catch and finally blocks in Java?

raja

raja

Updated on 06-Feb-2020 11:53:15

3K+ Views

No, we cannot write any statements in between try, catch and finally blocks and these blocks form one unit.  The functionality of try keyword is to identify an exception object and catch that exception object and transfer the control along with the identified exception object to the catch block by suspending the execution ... Read More

How to create an immutable class with mutable object references in Java?

raja

raja

Updated on 06-Feb-2020 11:48:17

12K+ Views

Immutable objects are those objects whose states cannot be changed once initialized. Sometimes it is necessary to make an immutable class as per the requirement. For example, All primitive wrapper classes (Integer, Byte, Long, Float, Double, Character, Boolean and Short) are immutable in Java. String class is also an immutable ... Read More

What is the importance of the Throwable class and its methods in Java?

raja

raja

Updated on 06-Feb-2020 11:30:26

515 Views

The Throwable class is a superclass of all errors and exceptions in Java. Objects that are instances of this class are thrown by the Java Virtual Machine or can be thrown by a throw statement. Similarly, this class or one of its subclasses can be the argument type in a catch clause.Instances of ... Read More

Can we declare the main () method as final in Java?

raja

raja

Updated on 06-Feb-2020 11:11:06

5K+ Views

Yes, we can declare the main () method as final in Java. The compiler does not throw any error.If we declare any method as final by placing the final keyword then that method becomes the final method.The main use of the final method in Java is they are not overridden.We can not ... Read More

Why AWT components are heavy-weight while Swing components are light-weight in Java?

raja

raja

Updated on 06-Feb-2020 10:46:30

2K+ Views

AWT stands for Abstract Window ToolKit and it supports Java GUI programming. It is a portable GUI library for Stand-alone Java applications/applets. The AWT provides the connection between our application and the native GUI while Java Swing implements a set of GUI components that build on AWT technology and it can ... Read More

What are the differences between an application and an applet in Java?

raja

raja

Updated on 06-Feb-2020 10:13:32

2K+ Views

A Java program can be classified into two types, one is an Application and another is an Applet.ApplicationAn application is a stand-alone java program that runs with the support of a virtual machine in a client or server-side.A java application is designed to perform a specific function to run on ... Read More

Scope and lifetime of variables in Java?

raja

raja

Updated on 06-Feb-2020 09:24:32

10K+ Views

Instance VariablesA variable which is declared inside a class and outside all the methods and blocks is an instance variable. The general scope of an instance variable is throughout the class except in static methods. The lifetime of an instance variable is until the object stays in memory.Class VariablesA variable ... Read More

Advertisements