
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 9150 Articles for Object Oriented Programming

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

192 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

158 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

2K+ 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

324 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

409 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

2K+ 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

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

366 Views
This writes data into a specific file or, a file descriptor (byte by byte). It is usually used to write the contents of a file with raw bytes, such as images.To write the contents of a file using this class −First of all, you need to instantiate this class by passing a string variable or a File object, representing the path of the file to be read.FileOutputStream outputStream = new FileOutputStream("file_path"); or, File file = new File("file_path"); FileOutputStream outputStream = new FileOutputStream (file);You can also instantiate a FileOutputStream class by passing a FileDescriptor object.FileDescriptor descriptor = new FileDescriptor(); FileOutputStream outputStream ... Read More

1K+ Views
The BufferedWriter class of Java is used to write a stream of characters to the specified destination (character-output stream). It initially stores all the characters in a buffer and pushes the contents of the buffer to the destination, making the writing of characters, arrays and Strings efficient.You can specify the required size of the buffer at the time of instantiating this class.ExampleIn the following Java program, we are trying to print a line on the console (Standard Output Stream). Here we are invoking the write() method by passing the required String. Live Demoimport java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; public class BufferedWriterExample ... Read More