Can we throw an Unchecked Exception from a static block in java?

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
A static block is a block of code with a static keyword. In general, these are used to initialize the static members. JVM executes static blocks before the main method at the time of class loading.Example Live Demopublic class MyClass {    static{       System.out.println("Hello this is a static ... Read More

How do you throw an Exception without breaking a for loop in java?

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
Whenever an exception occurred in a loop the control gets out of the loop, by handling the exception the statements after the catch block in the method will get executed. But, the loop breaks.Example Live Demopublic class ExceptionInLoop{    public static void sampleMethod(){       String str[] = {"Mango", "Apple", ... Read More

Can we to override a catch block in java?

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
DescriptionWhen a piece of code in particular method throws an exception, and is handled using try-catch pair. If we are calling this method from another one and, the calling line is wrapped within try-catch pair. Now, how can I override the catch block by the catch block of the calling ... Read More

How to get Exception log from a console and write it to external file in java?

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
There are several logging frame works available to log your data in to files. You can also define your own method.Example − Using I/O packageFollowing Java program has an array storing 5 integer values, we are letting the user to choose two elements from the array (indices of the elements) ... Read More

Does code form Java finally block

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
The finally block follows a try block or a catch block. A finally block of code always executes, irrespective of occurrence of an Exception.The return statement in the method too does not stop the finally block from getting executed.ExampleIn the following Java program we are using return statement at the ... Read More

What are the guide lines to be followed while using wildcards in Java?

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
Instead of the typed parameter in generics (T) you can also use “?”, representing an unknown type. You can use a wild card as a −Type of parameter.Field.Local field.The only restriction on wilds cards is that you cannot it as a type argument of a generic method while invoking it.Java ... Read More

What are Unbounded wildcard w.r.t Generics method in Java?

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
Generics is a concept in Java where you can enable a class, interface and, method, accept all (reference) types as parameters. In other words it is the concept which enables the users to choose the reference type that a method, constructor of a class accepts, dynamically. By defining a class ... Read More

What are lower-bounded wildcard w.r.t Generics method in Java?

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
Generics is a concept in Java where you can enable a class, interface and, method, accept all (reference) types as parameters. In other words it is the concept which enables the users to choose the reference type that a method, constructor of a class accepts, dynamically. By defining a class ... Read More

What are upper-bounded wildcard w.r.t Generics method in Java?

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
Generics is a concept in Java where you can enable a class, interface and, method, accept all (reference) types as parameters. In other words it is the concept which enables the users to choose the reference type that a method, constructor of a class accepts, dynamically. By defining a class ... Read More

Write data from/to a .csv file in java

Krishna Kasyap
Published on 15-Sep-2019 19:04:43
How to read/A library named OpenCSV provides API’s to read and write data from/into a.CSV file. Here it is explained how to read the contents of a .csv file using a Java program.Maven dependency<dependency>    <groupId>com.opencsv</groupId>    <artifactId>opencsv</artifactId>    <version>4.4</version> </dependency> <dependency>    <groupId>org.apache.commons</groupId>    <artifactId>commons-lang3</artifactId>    <version>3.9</version> </dependency>The CSVReader ... Read More
1 2 3 4 5 6 7 ... 2505 Next
Advertisements