- 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
10K+ Views
The .properties is an extension in java which is used to store configurable application. It is represented by the Properties class in Java, you can store a properties file and read from it using the methods of this class. This class inherits the HashTable class.Creating a .properties file −To create a properties file −Instantiate the Properties class.Populate the created Properties object using the put() method.Instantiate the FileOutputStream class by passing the path to store the file, as a parameter.ExampleThe Following Java program creates a properties file in the path D:/ExampleDirectory/ Live Demoimport java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; public class CreatingPropertiesFile { ... Read More
5K+ Views
An exception is an issue (run time error) that 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.Multiple exceptions in a codeWhenever we have a code that may generate more than one exception and if you need to handle them specifically you can use multiple catch blocks on a single try.try{ //code } catch(Exception1 ex1) { // } catch(Exception2 ex2) { // }Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class MultipleCatchBlocks { public static void main(String [] ... Read More
6K+ Views
Following Java program accepts a String value from the user, verifies whether a file contains the given String and prints the number of occurrences of the word too.Example Live Demoimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class FindingWordFromFile { public static void main(String args[]) throws FileNotFoundException { //Reading the word to be found from the user Scanner sc1 = new Scanner(System.in); System.out.println("Enter the word to be found"); String word = sc1.next(); boolean flag = false; int count = 0; ... Read More
285 Views
The readUTF() method of the java.io.DataOutputStream reads data that is in modified UTF-8 encoding, into a String and returns it.ExampleThe following Java program reads a UTF-8 text from a .txt file using the readUTF() method.import java.io.DataInputStream; import java.io.EOFException; import java.io.FileInputStream; import java.io.IOException; public class UTF8Example { public static void main(String args[]) { StringBuffer buffer = new StringBuffer(); try { //Instantiating the FileInputStream class FileInputStream fileIn = new FileInputStream("D:\test.txt"); //Instantiating the DataInputStream class DataInputStream inputStream = new DataInputStream(fileIn); ... Read More
3K+ Views
In general, data is stored in a computer in the form of bits (1 or, 0). There are various coding schemes available specifying the set of bytes represented by each character.Unicode (UTF) − Stands for Unicode Translation Format. It is developed by The Unicode Consortium. if you want to create documents that use characters from multiple character sets, you will be able to do so using the single Unicode character encodings. It provides 3 types of encodings.UTF-8 − It comes in 8-bit units (bytes), a character in UTF8 can be from 1 to 4 bytes long, making UTF8 variable width.UTF-16 ... Read More
3K+ Views
In general, data is stored in a computer in the form of bits (1 or, 0). There are various coding schemes available specifying the set of bytes represented by each character.Unicode (UTF) − Stands for Unicode Translation Format. It is developed by The Unicode Consortium. if you want to create documents that use characters from multiple character sets, you will be able to do so using the single Unicode character encodings. It provides 3 types of encodings.UTF-8 − It comes in 8-bit units (bytes), a character in UTF8 can be from 1 to 4 bytes long, making UTF8 variable width.UTF-16 ... Read More
255 Views
You can verify whether a particular file exists in the system in two ways using the File class and using the Files class.Using The File classThe class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.This class provides various methods to manipulate files, The exists a () method of it verifies whether the file or directory represented by the current File object exists if so, it returns true else it returns false.ExampleThe following Java program verifies whether a specified file exists in ... Read More
16K+ Views
The BufferedReader class of Java is used to read the stream of characters from the specified source (character-input stream). The constructor of this class accepts an InputStream object as a parameter.This class provides a method known as readLine() which reads and returns the next line from the source and returns it in String format.The BufferedReader class doesn’t provide any direct method to read an integer from the user you need to rely on the readLine() method to read integers too. i.e. Initially you need to read the integers in string format.The parseInt() method of the Integer class accepts a String ... Read More
234 Views
Converting one data type to others in Java is known as casting.Up casting − If you convert a higher datatype to lower datatype, it is known as narrowing (assigning higher data type value to the lower data type variable).Example Live Demoimport java.util.Scanner; public class NarrowingExample { public static void main(String args[]){ char ch = (char) 67; System.out.println("Character value of the given integer: "+ch); } }OutputCharacter value of the given integer: CDown casting − If you convert a lower datatype to a higher data type, it is known as widening (assigning lower data type ... Read More
5K+ Views
When you declare the instance variables of a class private, you cannot access them in another class if you try to do so a compile-time error will be generated.But, if you inherit a class that has private fields, including all other members of the class the private variables are also inherited and available for the subclass.But, you cannot access them directly, if you do so a compile-time error will be generated.Example Live Democlass Person{ private String name; public Person(String name){ this.name = name; } public void displayPerson() { System.out.println("Data of the ... Read More