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
Java Articles - Page 221 of 745
91K+ Views
Sorting a string alphabetically means rearranging its characters in order, from A to Z. For example, the string "java" becomes "aajv" after sorting. Different ways to sort a String Alphabetically There are two ways to do this in Java using different approaches - Using toCharArray() and Arrays.sort() Method Sorting the array manually Using toCharArray() and Arrays.sort() Method The toCharArray() method of this ... Read More
3K+ Views
In Java, the collections framework provides various classes like ArrayList, HashSet, and LinkedList to store groups of elements. But once data is stored, how do you access or retrieve it? Java provides multiple ways to retrieve elements from collections, depending on whether you're reading values, modifying them during traversal, or iterating forward or backward. You can retrieve the elements of a collection in four ways- Using For-Loop Using For-Each Loop ... Read More
371 Views
When working with collections in Java, you might need to convert an array to an ArrayList. This is useful because ArrayList offers more flexibility, such as dynamic sizing and built-in methods for adding, removing, and searching elements. Need for Converting an Array to an ArrayList Arrays in Java have a fixed size and provide limited functionality. ArrayList, on the other hand, is part of the Java Collections Framework and provides methods to modify data dynamically. It is useful when - Need to use dynamic Collections. ... Read More
2K+ Views
When you are working with strings in Java, you may want to keep only the alphabetic characters (A-Z, a-z) and remove everything else, like numbers, punctuation, and symbols. Java gives you multiple ways to do this for different cases or scenarios. Removing non-alphabetical characters from a string There are different methods, and they are - Using split() method Using replaceAll() method ... Read More
857 Views
The ArrayList and LinkedList classes implement the List interface of the java.util package. This interface provided two variants of the remove() method to remove particular elements, as shown below - Using remove(int index) Using remove(Object o) There are two additional removal approaches provided by the Collection and Iterator interfaces. They are - ... Read More
923 Views
A collection is an object that holds a reference to other objects. A Java array list is one of the collections. it is a resizable array and is represented by the class named ArrayList. This java.util.Collections class provides methods to manipulate the collection objects in Java. We can make an ArrayList read-only using the Collections.unmodifiableList() method. Need to make a ArrayList Read-Only Sometimes we may need to make the ArrayList object read-only - To protect data from unnecessary or unwanted changes. ... Read More
739 Views
RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing/running in one system (JVM) to access/invoke an object running on another JVM. RMI is used to build distributed applications; it provides remote communication between Java programs. It is provided in the package java.rmi. To create an RMI Java application, you need to follow the steps given below - Step 1: Define the Remote Interface A remote interface provides the description of all the methods of a particular remote object. The client communicates with this remote interface. Therefore, you need to create an interface that extends ... Read More
423 Views
The URL class in the java.net package represents a web address or URL (Uniform Resource Locator), which points to a web resource such as a file, page, or directory in the World Wide Web (internet). The URL class provides various constructors, one of which accepts a String parameter (representing a URL) and constructs an object of the URL class. Reading From a URL You can read content from a URL using the openStream() method. This method opens a connection to the web address specified by the current URL object and gives you an InputStream object. The Java InputStream is an ... Read More
1K+ Views
While reading the contents of a file using a Java program, we may reach the end of the file abruptly; in such cases, EOFException (End Of File) is thrown. Especially, this exception occurs while reading data using the InputStream objects, such as DataInputStream. In other scenarios, a specific value will be thrown when the end of the file is reached. Why Does the EOFException Occur The EOFException occurs when a stream reaches the end of the file while reading its contents. If we consider the DataInputStream class, it provides various methods such as readBoolean(), readByte(), readChar(), etc, to read primitive ... Read More
5K+ Views
Static Methods and Static Blocks Static methods belong to the class and they will be loaded into memory along with the class; you can invoke them without creating an object. (using the class name as reference). Whereas a static block is a block of code with a static keyword. In general, these are used to initialize the static members. JVM executes static blocks before the main method at the time of class loading. Example The following example demonstrates the usage of static blocks and static methods in Java - public class Sample { ... Read More