Maruthi Krishna has Published 952 Articles

How can we add an underscore before each capital letter inside a java String?

Maruthi Krishna

Maruthi Krishna

Updated on 04-Dec-2023 11:35:02

2K+ Views

Using the StringBuffer class To add underscore before each capital letter in a String using StringBuffer − Create an empty StringBuffer object. The isUpperCase() method of Character class accepts a character and verifies whether it is in upper case, if so, this method returns true. Using this method, verify each character in the ... Read More

Can I import same package twice? Will JVM load the package twice at runtime?

Maruthi Krishna

Maruthi Krishna

Updated on 23-Nov-2023 10:04:58

1K+ Views

In Java classes and interfaces related to each other are grouped under a package. Package is nothing but a directory storing classes and interfaces of a particular concept. For example, all the classes and interfaces related to input and output operations are stored in java.io package. Creating a Package You can group ... Read More

Can we declare an interface with in another interface in java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Nov-2023 12:56:18

828 Views

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you can define an interface. To create an object of this type you need to implement this interface, provide ... Read More

How to create date object in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Sep-2023 02:38:59

26K+ Views

Using the Date classYou can create a Date object using the Date() constructor of java.util.Date constructor as shown in the following example. The object created using this constructor represents the current time.ExampleLive Demoimport java.util.Date; public class CreateDate {    public static void main(String args[]) {             ... Read More

How convert an array of Strings in a single String in java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Sep-2023 02:33:17

27K+ Views

Using StringBufferCreate an empty String Buffer object.Traverse through the elements of the String array using loop.In the loop, append each element of the array to the StringBuffer object using the append() method.Finally convert the StringBuffer object to string using the toString() method.Examplepublic class ArrayOfStrings {    public static void main(String ... Read More

How to get list of all files/folders from a folder in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 12-Sep-2023 03:22:52

33K+ Views

The class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.To get the list of all the existing files in a directory this class provides the files class provides list() (returns names) ... Read More

How to get the current date in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Sep-2023 21:38:15

36K+ Views

You can get the current date in Java in various ways. Following are some of them −The constructor of Date classThe no-arg constructor of the java.util.Date class returns the Date object representing the current date and time, using this you can print the current date as shown below −ExampleLive Demoimport java.text.SimpleDateFormat; ... Read More

How to convert Java object to JSON using Jackson library?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Sep-2023 11:49:04

42K+ Views

JSON or JavaScript Object Notation is a lightweight text-based open standard designed for human-readable data interchange. Conventions used by JSON are known to programmers, which include C, C++, Java, Python, Perl, etc.There are several Java libraries available to handle JSON objects. Jackson is a simple java based library to serialize ... Read More

How to measure execution time for a Java method?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Sep-2023 15:19:24

49K+ Views

In general, the elapsed time is the time from the starting point to ending point of an event. Following are various ways to find elapsed time in Java −The currentTimeMillis() method returns the current time in milliseconds. To find the elapsed time for a method you can get the difference ... Read More

Converting a StringBuilder to String in Java

Maruthi Krishna

Maruthi Krishna

Updated on 02-Sep-2023 15:06:14

49K+ Views

The toString() method of the StringBuilder class reruns String value of the current object. To convert a StringBuilder to String value simple invoke the toString() method on it.Instantiate the StringBuilder class.Append data to it using the append() method.Convert the StringBuilder to string using the toString() method.ExampleIn the following Java program ... Read More

Advertisements