Found 9150 Articles for Object Oriented Programming

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

Value of the class attribute node of an element in JavaScript?

vineeth.mariserla
Updated on 08-Aug-2019 14:37:37

387 Views

Javascript has provided the getAttributeNode() method to find the attribute node with the specified name of an element, as an attribute object. If the attribute does not exist, the return value is null or an empty string ("").syntaxelement.getAttributeNode(attributename);It returns the attribute object representing the specified attribute node ExampleIn the following example, there are two heading tags with different classes. Those tags when accessed by the getAttributeNode() can return the attribute class with which they attached. It works the same as an array. We can access the multiple classes only by providing their index numbers.Live Demo Tutorix Tutorialspoint var elmnt ... 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

How to print a formatted text using printf() method in Java?

Vivek Verma
Updated on 29-May-2025 19:07:30

598 Views

In Java, formatted text refers to those text that has been processed and arranged according to a specific format. According to the article, we will use the printf() method to learn how to print the formatted text. Formatted Text using printf() Method In Java, to print the formatted output or text we have a printf() method. The printf() method allows us to format output to a java.io.PrintStream or java.io.PrintWriter. These classes also contain a method called format() which can produce the same results, so whatever we read here for the printf() method can also be applied to the format() method. ... Read More

Advertisements