Maruthi Krishna has Published 870 Articles

What happens if an exception is not handled in a java program?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:28:11

3K+ Views

An exception is an issue (run time error) occurred during the execution of a program. For understanding purpose let us look at it in a different manner.Generally, when you compile a program, if it gets compiled without a .class file will be created, this is the executable file in Java, ... Read More

What is a MalformedURLException and how to fix it in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:26:42

21K+ Views

While working with client-server programming in Java (JSE), if you are using java.net.URL class object in your program, you need to instantiate this class by passing a string representing required URL to which you need to establish connection. If the url you have passed in the string which cannot be ... Read More

What are the modifiers allowed to use along with local variables in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:24:08

1K+ Views

In Java you can declare three types of variables namely, instance variables, static variables and, local variables.Local variables − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has ... Read More

What is blank final variable? What are Static blank final variables in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:19:27

2K+ Views

Static variables − Static variables are also known as class variables. You can declare a variable static using the keyword. Once you declare a variable static there would only be one copy of it in the class, regardless of how many objects are created from it.public static int num = ... Read More

How to call another enum value in an enum's constructor using java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:16:29

3K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum ... Read More

How can an exception be thrown manually by a programmer in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:11:35

5K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {   ... Read More

Is it possible to have multiple try blocks with only one catch block in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:10:01

9K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {   ... Read More

How to read DataInputStream until the end without need to catch an EOFException in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:09:12

1K+ Views

While reading the contents of a file in certain scenarios the end of the file will be reached in such scenarios a EOFException is thrown.Especially, this exception is thrown while reading data using the Input stream objects. In other scenarios a specific value will be thrown when the end of ... Read More

Does static factory method internally use new keyword to create object in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:00:04

197 Views

Factory pattern is a design pattern (creational pattern) which is used to create multiple objects based on the data we provide. In it we create an object abstracting the process of creation.ExampleBelow given is the example implementation of the factory pattern. Here, we have an interface with name Employee and ... Read More

How static class Object is created without reference of outer class in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:59:06

1K+ Views

A static member (method/variable) belongs to the class and it will be loaded into the memory along with the class. You can invoke it without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value ... Read More

Advertisements