Maruthi Krishna has Published 464 Articles

Remove all non-alphabetical characters of a String in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:22:42

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 ... Read More

Why can\\\'t a Java class be both abstract and final?

Maruthi Krishna

Maruthi Krishna

Updated on 21-Apr-2025 16:24:01

4K+ Views

In Java, both abstract and final are class modifiers but they are completely opposite to each other. That's why Java class cannot be both abstract and final. Abstract class An abstract class in Java is a class that may contain both abstract methods (without implementation) and concrete methods (with ... Read More

Can Enum extend any class in java?

Maruthi Krishna

Maruthi Krishna

Updated on 21-Apr-2025 15:13:34

2K+ Views

If you’ve been coding in Java for some time, you might have wondered why you can't make an enum extend another class. It seems like it should, but Java won't let you. Let's break down why this happens Enumeration in Java Enumeration (enum) in Java is a user-defined datatype ... Read More

How to read a .txt file with RandomAccessFile in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 21-Apr-2025 12:59:09

2K+ Views

In general, while reading or writing data to a file, you can do so, from the start of the file. You cannot read/write from random position. The java.io.RandomAccessFile class in Java enables you to read/write data to a random-access file. This acts similar to a large array of bytes where ... Read More

What are the restrictions imposed on a static method or a static block of code in java?

Maruthi Krishna

Maruthi Krishna

Updated on 18-Apr-2025 18:32:45

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 ... Read More

How many types of memory areas are allocated by JVM in java?

Maruthi Krishna

Maruthi Krishna

Updated on 18-Apr-2025 18:17:44

2K+ Views

Java Virtual Machine is a program/software that runs Java applications. It takes Java bytecode (.class files) and converts the bytecode (line by line) into machine-understandable code, line by line so the processor can understand and execute it. JVM contains a module(components) known as a class loader. It is responsible for ... Read More

What are the key steps in read/write from/to a URL connection in java?

Maruthi Krishna

Maruthi Krishna

Updated on 16-Apr-2025 16:29:17

556 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 ... Read More

Pattern UNIX_LINES field in Java with Examples

Maruthi Krishna

Maruthi Krishna

Updated on 08-Aug-2024 12:56:52

347 Views

This flag enables Unix lines mode. In the Unix lines mode, only '' is used as a line terminator and ‘\r’ is treated as a literal character. Example 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class LTERAL_Example { public static void main(String[] args) { ... Read More

Java program to verify whether a given element exists in an array

Maruthi Krishna

Maruthi Krishna

Updated on 31-Jul-2024 17:29:29

1K+ Views

Given an array and one of its element as an input, write a Java program to check whether that element exists in given array or not. You can find any element from an array using search algorithms. In this article, we will use linear search and binary search algorithms. Using ... Read More

Java program to delete duplicate lines in text file

Maruthi Krishna

Maruthi Krishna

Updated on 08-Jul-2024 12:02:44

3K+ Views

The interface set does not allow duplicate elements. The add() method of this interface accepts elements and adds to the Set object, if the addition is successful it returns true, if you try to add an existing element using this method, the addition operations fails returning false. Problem Statement Given ... Read More

Advertisements