- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4338 Articles for Java 8
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
8K+ Views
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", "Banana", "Grapes", "Oranges"}; try { for(int i=0; i
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
856 Views
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 method.When a piece of code in a method throws an exception (compile time) we must either handle it by wrapping it within the try-catch pair or, throw it (postpone) to the calling method using the throws keyword else a compile time error occurs.In the following Java example the code in ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
1K+ Views
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) and performing division between them. We are wrapping this code in try block with three catch blocks catching ArithmeticException, InputMismatchException and, ArrayIndexOutOfBoundsException. In each of them we are invoking the writeToFile() method.This method accepts an exception object, and appends it to a file using the write() method of the Files ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
124 Views
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 end of the try block still, the statements in the finally block gets executed. Live Demopublic class FinallyExample { public static void main(String args[]) { int a[] = new int[2]; try { System.out.println("Access element three :" + a[3]); ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
100 Views
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 provides 3 types of wild cards namely upper-bounded, lower-bounded, un-bounded. There are two types of wildcards in Java −Upper-bounded wildcards − Upper bounds in wild cards is similar to the bounded type in generics. Using this you can enable the usage of all the subtypes of a particular class as a ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
1K+ Views
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 as generic you are making it type-safe i.e. it can act up on any datatype.To define a generic class you need to specify the type parameter you are using in the angle brackets “” after the class name and you can treat this as datatype of the instance variable an ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
246 Views
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 as generic you are making it type-safe i.e. it can act up on any datatype.To define a generic class you need to specify the type parameter you are using in the angle brackets “” after the class name and you can treat this as datatype of the instance variable an ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
279 Views
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 as generic you are making it type-safe i.e. it can act up on any datatype.To define a generic class you need to specify the type parameter you are using in the angle brackets “” after the class name and you can treat this as datatype of the instance variable an ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
1K+ Views
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 com.opencsv opencsv 4.4 org.apache.commons commons-lang3 3.9 The CSVReader class of the com.opencsv package represents a simple csv reader. While instantiating this class you need to pass a Reader object representing the file to be read as a parameter to its constructor. It provides methods named readAll() and readNext() to read the contents of a .csv fileUsing the readNext() ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
4K+ Views
You can write data into a .csv file using the OpenCSV library and, you can communicate with MySQL database through a Java program using the mysql-java-connector.Maven dependencyThe following are the dependencies you need to include in your pom.xml file to write data to a .csv file from a database table. com.opencsv opencsv 4.4 org.apache.commons commons-lang3 3.9 mysql mysql-connector-java 5.1.6 Writing data to a CSV fileThe CSVWriter class of the com.opencsv package represents a simple CSV writer. While instantiating this class you need to pass a Writer object ... Read More