Raja has Published 760 Articles

Can we define an abstract class with no abstract methods in Java?

raja

raja

Updated on 22-Nov-2023 09:15:56

9K+ Views

Yes, we can declare an abstract class with no abstract methods in Java. An abstract class means that hiding the implementation and showing the function definition to the user. An abstract class having both abstract methods and non-abstract methods. For an abstract class, we are not able to create an object directly. But ... Read More

How to resolve a NullPointerException in Java?

raja

raja

Updated on 21-Nov-2023 16:37:50

2K+ Views

A NullPointerException is a runtime exception thrown by the JVM when our application code, other referenced API or the middleware encounters the following conditions. Attempting to invoke an instance method of a null object. Attempting to access or modify a particular field of a null object. Attempting to obtain the length of a ... Read More

How to use the SimpleDateFormat class to convert a Java Date to a formatted String?

raja

raja

Updated on 21-Nov-2023 16:11:34

104 Views

The Java SimpleDateFormat class provides convert between a Java String to a Date or Date to String. Example import java.util.Date; import java.text.SimpleDateFormat; import java.util.Calendar; public class SimpleDateFormatTest { public static void main(String[] args) { // get today's date Date today = Calendar.getInstance().getTime(); ... Read More

What are the differences between while loop and do-while loop in Java?

raja

raja

Updated on 21-Nov-2023 14:41:27

8K+ Views

The while loop in java executes one or more statements after testing the loop continuation condition at the start of each iteration. The do-while loop, however, tests the loop continuation condition after the first iteration has completed. Therefore, the do-while loop guarantees one execution of the loop logic whereas the ... Read More

Can we have a try block without a catch block in Java?

raja

raja

Updated on 21-Nov-2023 10:08:40

24K+ Views

Yes, It is possible to have a try block without a catch block by using a final block. As we know, a final block will always execute even there is an exception occurred in a try block, except System.exit() it will execute always. Example 1 public class TryBlockWithoutCatch { public static ... Read More

Can we have a return statement in the catch or, finally blocks in Java?

raja

raja

Updated on 17-Nov-2023 16:33:50

11K+ Views

Yes, we can write a return statement of the method in catch and finally block. There is a situation where a method will have a return type and we can return some value at any part of the method based on the conditions. If we return a value in the catch block ... Read More

What are the differences between printStackTrace() method and getMessage() method in Java?

raja

raja

Updated on 17-Nov-2023 14:35:43

3K+ Views

There are two ways to find the details of the exception, one is the printStackTrace() method and another is the getMessage() method. printStackTrace() method This is the method which is defined in java.lang.Throwable class and it is inherited into java.lang.Error class and java.lang.Exception class. This method will display the name of the exception ... Read More

Is it possible to create a class without a name in Java?

raja

raja

Updated on 17-Nov-2023 14:26:55

779 Views

Yes, we can create a class without a name using the Anonymous class. Anonymous class is an inner class which does not have a name and whose instance is created at the time of the creation of class itself and these classes are somewhat different from normal classes in its creation. Example public ... Read More

Why String class is immutable or final in Java?

raja

raja

Updated on 17-Nov-2023 14:21:41

7K+ Views

The string is immutable means that we cannot change the object itself, but we can change the reference to the object. The string is made final to not allow others to extend it and destroy its immutability. Security Parameters are typically represented as String in network connections, database connection URLs, usernames/passwords, ... Read More

Why String literal is stored in String Constant Pool in Java?

raja

raja

Updated on 17-Nov-2023 14:10:14

2K+ Views

There are two ways to create a String object in Java By using the new operator String str = new String("Tutorials Point"); By using String literal String str = "Tutorials Point"; Whenever we call new String() in Java, it will create an object in the heap memory and String literals will go into String Constant ... Read More

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