
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 7442 Articles for Java

260 Views
The insert() method of the StringBuffer class inserts the String starting from an index specified in the parameter along with the stringThe syntax of the insert method is −original_string.insert( index , var)where var is the variable to be inserted and index is the position where the variable var is to be inserted.Let us see an example program −Example Live Demopublic class Example { public static void main(String[] args) { StringBuffer str = new StringBuffer("Hello World"); String a = "Wonderful "; str.insert(6, a); System.out.println(str); } }OutputHello Wonderful World

9K+ Views
Streams in Java have a few terminal operations. They are as follows −collect − The collect method returns the outcome of the intermediate operationsList id = Arrays.asList(“Classes", "Methods", "Members"); List output = id.stream().filter(s -> s.startsWith("M")).collect(Collectors.toList());reduce − The reduce method is reduces the elements of a stream into a single element having a certain value after computation. The BinaryOperator is an argument of the reduce method.List list1 = Arrays.asList(11, 33, 44, 21); int even = list1.stream().filter(x -> x % == 0).reduce(0, (ans, i) -> ans+i);forEach − This method iterates through every element in the streamList list1= Arrays.asList(1, 3, 5, 7); List ... Read More

2K+ Views
In Java, stream was introduced in Java 8. It represents a collection of elements and supports functional operations on those collections. Here, we are talking about collections like Array, List and Set. The Stream API simply channelizes the elements of sources through various built-in methods to return the desired result. In this article, we are going to discuss different operations that can be performed on the Java stream. Operations on Java 8 Streams There are two types of operations, we can perform on the Java streams − Intermediate Operations − They process the elements of an input stream ... Read More

9K+ Views
No, we cannot override private or static methods in Java.Private methods in Java are not visible to any other class which limits their scope to the class in which they are declared.ExampleLet us see what happens when we try to override a private method − Live Democlass Parent { private void display() { System.out.println("Super class"); } } public class Example extends Parent { void display() // trying to override display() { System.out.println("Sub class"); } public static void main(String[] args) { Parent obj = new Example(); ... Read More

6K+ Views
If a method is declared as static, it is a member of a class rather than belonging to the object of the class. It can be called without creating an object of the class. A static method also has the power to access static data members of the class.A static variable is a class variable. A single copy of the static variable is created for all instances of the class. It can be directly accessed in a static method.An abstract class in Java is a class that cannot be instantiated. It is mostly used as the base for subclasses to ... Read More

4K+ Views
If the static keyword is applied to any method, it becomes a static method.If a method is declared as static, it is a member of a class rather than belonging to the object of the class. It can be called without creating an object of the class. A static method also has the power to access static data members of the class.There are a few restrictions imposed on a static methodThe static method cannot use non-static data member or invoke non-static method directly.The this and super cannot be used in static context.The static method can access only static type data ... Read More

956 Views
Serialization is the process of changing the state of an object into the byte stream so that the byte stream can return back into a copy of the objectIn Java, an object is said to be serializable if its class or parent classes implement either the Serializable interface or the Externalizable interface.Deserialization is converting the serialized object back into a copy of the object.There are three cases of Object Serialization with inheritance.The child class is automatically serializable if the parent class is serializableA child class can still be serialized even if the parent class is not serializableIf we want the ... Read More

3K+ Views
To list weekday names, use the getWeekdays () from the DateFormatSymbols class in Java.DateFormatSymbols is a class for encapsulating localizable date-time formatting data.Get weekday month names in an array −String[] days = new DateFormatSymbols().getWeekdays ();Display the weekdays −for (int i = 0; i < days.length; i++) { String weekday = days[i]; System.out.println(weekday); }The following is an example −Example Live Demoimport java.text.DateFormatSymbols; public class Demo { public static void main(String[] args) { String[] days = new DateFormatSymbols().getWeekdays(); for (int i = 0; i < days.length; i++) { String weekday ... Read More

315 Views
The bits of an integer number can be reversed to obtain another number. An example of this is given as follows −Number = 11 Binary representation = 1011 Reversed binary representation = 1101 Reversed number = 13A program that demonstrates this is given as follows −Example Live Demopublic class Example { public static void main(String[] args) { int num = 14; int n = num; int rev = 0; while (num > 0) { rev = 1; } ... Read More

425 Views
The length of the longest consecutive 1s in the binary representation of a given integer involves converting the integer to its binary form and then identifying the longest run of contiguous 1s. Here, we can represent each integer in binary as a series of 0s and 1s. Bitwise operations allow efficient bit manipulation, making it easy to count and update the longest sequence of consecutive 1s. Consider special cases such as when the integer is 0 (binary representation 0) or when it contains only 1s (e.g., for the number 7, binary 111). To understand the concept clearly, Let's go through ... Read More