Found 7442 Articles for Java

How to read the data from a CSV file in Java?

raja
Updated on 01-Jul-2020 12:10:16

24K+ Views

A CSV stands for Comma Separated Values. In a CSV file, each line contains words that are separated with a comma(, ) and it is stored with a .csv extension.We can read a CSV file line by line using the readLine() method of BufferedReader class. Split each line on comma character to get the words of the line into an array. Now we can easily print the contents of the array by iterating over it or by using an appropriate index.CSV FileExampleimport java.io.*; public class CSVReaderTest {    public static final String delimiter = ", ";    public static void read(String csvFile) {   ... Read More

How can we print all the capital letters of a given string in Java?

Vivek Verma
Updated on 14-May-2025 11:57:53

6K+ Views

The Character class is a subclass of the Object class, and it wraps a value of the primitive type char in an object. An object of type Character class contains a single field whose type is char. We can print all the capital letters of a given string using the following approaches - Using isUpperCase() Method Using ASCII Comparison Using isUpperCase() Method The isUpperCase() is the method of the Character class. It accepts a character as a parameter and returns true if it is an uppercase letter and false if not.To ... Read More

How can we implement a custom iterable in Java?

raja
Updated on 23-Nov-2023 11:23:04

2K+ Views

An Iterable interface is defined in java.lang package and introduced with Java 5 version. An object that implements this interface allows it to be the target of the "for-each" statement. This for-each loop is used for iterating over arrays and collections. An Iterable interface can also be implemented to create custom behavior. Syntax public interface Iterable Example import static java.lang.String.format; import java.util.*; // Person class class Person { private String firstName, lastName; private int age; public Person(){ } public Person(String firstName, String lastName, int age) { this.firstName = firstName; ... Read More

Importance of return type in Java?

Vivek Verma
Updated on 29-May-2025 15:48:02

26K+ Views

A method in Java is a set of statements that can be reused in the program whenever we want. We can write a method once and call it multiple times. We can return values from a method; the datatype of the value we return is known as the return type.  We return values from a Java method using a return statement. A return statement causes the program control to transfer back to the caller of a method. Every method in Java is declared with a return type, ... Read More

How to read the data from a properties file in Java?

Vivek Verma
Updated on 23-Jun-2025 11:31:51

34K+ Views

Java supports file-handling; it provides various classes that provide various methods to read, write, update, and delete data from files in our local system. A properties file is a simple text file with a ".properties" extension that contains configuration data in the form of key-value pairs. It is mostly used in Java applications to manage settings such as database configuration, application messages, or environment variables. How to read Data from a Properties File in Java? To read data from the properties file, you can use the Properties class in Java. This is a subclass of the Hashtable class and it represents a persistent ... Read More

How to instantiate a static inner class with reflection in Java?

raja
Updated on 24-Nov-2023 09:18:44

2K+ Views

A static inner class can be instantiated without the need for an instance of the outer class. In general, an Inner class is a part of nested class, called Non-static nested classes in Java. The types of inner classes are member inner class, anonymous inner class, and local inner class. We can instantiate a static inner class with reflection using InnerClass.class.newInstance(). If we need an instance of the outer class to instantiate a non-static inner class, we can specify it before a new operator. Example import java.lang.reflect.*; public class InnerclassWithReflectionTest { public static void main(String args[]) { ... Read More

Will a finally block execute after a return statement in a method in Java?

Vivek Verma
Updated on 14-May-2025 19:25:38

20K+ Views

Yes, the finally block will be executed even after a return statement within a try or catch block in a Java method. Finally Block after the Return Statement Usually, the return statement will be the last in a Java method. If you try to add any statements after the return in Java, an error will be generated.  public class Sample { public String demoMethod() { System.out.println(); return null; System.out.println("This statement will generate an error"); } ... Read More

Importance of XOR operator in Java?

Vivek Verma
Updated on 14-May-2025 19:35:13

12K+ Views

Bitwise XOR (exclusive or) "^" is an operator in Java that provides the answer '1' if both of the bits in its operands are different; if both of the bits are the same, then the XOR operator gives the result '0'. XOR is a binary operator that is evaluated from left to right. The operator "^" is undefined for the argument of type String. Importance of the XOR (^) Operator in Java In Java, the XOR (^) operator is important for both bitwise and boolean operations. It returns true or 1 only when the two operands "differ". XOR is commonly ... Read More

How to convert an OutputStream to a Writer in Java?

Vivek Verma
Updated on 14-May-2025 19:09:21

2K+ Views

Input and output Streams in Java are objects that accepts sequence of information and sends them further. These are used to read and write data from/to various sources.What are Output Streams & WritersA Java output streams accept output data (bytes) from a source and sends it to the destination. An output stream is represented by an abstract class known as OutputStream. This is the super class of all the OutputStream classes. There are various output streams in Java namely, ByteArrayOutputStream, FileOutputStream, FilterOutputStream, ObjectOutputStream, PipedOutputStream.Writers are objects that are used to write data to character streams. These are represented by the abstract ... Read More

How to find the unicode category for a given character in Java?

Vivek Verma
Updated on 14-May-2025 14:12:22

5K+ Views

A Character class is a subclass of the class named Object, and it wraps a value of the primitive type char. An object of type Character contains a single field whose type is char. Unicode Category of a Character In Java, the Unicode category of a character refers to the classification of characters based on their general type or usage, such as letters, digits, punctuation, symbols, etc. The java.lang.Character class provides methods to find the category of a character according to the Unicode standard. Unicode Category of a Character using getType() One of the basic ways to find the Unicode ... Read More

Advertisements