Maruthi Krishna has Published 951 Articles

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

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 08:04:43

3K+ Views

Abstract classA class which contains 0 or more abstract methods is known as abstract class. If it contains at least one abstract method, it must be declared abstract.If you want to use the concrete method in an abstract class you need to inherit the class, provide implementation to the abstract ... Read More

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

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 08:00:58

1K+ Views

In general, while reading or writing data to a file, you can only read or, write data 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 ... Read More

How to resolve "Could not find or load main class package" in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:59:08

5K+ Views

Once you write a Java program you need to compile it using the javac command, this shows you the compile time errors occurred (if any).Once you resolve them and compile your program success fully, an executable file with the same name as your class name is generated in your current ... Read More

How to overwrite a line in a .txt file using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:55:25

16K+ Views

API’s usedThe replaceAll() method of the String class accepts two strings representing a regular expression and a replacement String and replaces the matched values with given String.The java.util class (constructor) accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) ... Read More

Program to replace all the characters in of a file with '#' except a particular word in Java

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:51:55

477 Views

The split() method of the String class. splits the current string around matches of the given regular expression. The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string.The ... Read More

How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:46:50

13K+ Views

The java.text package provides a class named SimpleDateFormat which is used to format and parse dates in required manner (local).One of the constructors of this class accepts a String value representing the desired date format and constructors SimpleDateFormat object.The format() method of this class accepts a java.util.Date object and returns ... Read More

Is it possible to check if a String only contains ASCII in java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:37:37

1K+ Views

Using regular expressionYou can find whether a particular String value contains ASCII characters using the following regular expression −\A\p{ASCII}*\zThe matches() method of the String class accepts a regular expression and verifies whether the current string matches the given expression if so, it returns true, else it returns false.Therefore, Invoke the ... Read More

How do we initialize an array within object parameters in java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:33:00

4K+ Views

You can initialize the array variable which is declared inside the class just like any other value, either using constructor or, using the setter method.ExampleIn the following Java example, we are declaring an instance variable of array type and initializing it from the constructor. Live Demopublic class Student {    String ... Read More

How to parse for words in a string for a specific word in java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Oct-2019 08:30:04

615 Views

There are various methods in Java using which you can parse for words in a string for a specific word. Here we are going to discuss 3 of them.The contains() methodThe contains() method of the String class accepts a sequence of characters value and verifies whether it exists in the ... Read More

How do we make my string comparison case insensitive in java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Oct-2019 08:25:47

656 Views

We can compare Strings in Java in various ways −Using the comapareTo() method − The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence ... Read More

Advertisements