Maruthi Krishna has Published 870 Articles

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

2K+ 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

1K+ 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

33K+ 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 to get list of all files/folders from a folder in Java?

Maruthi Krishna

Maruthi Krishna

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

43K+ 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

40K+ 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

51K+ 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

62K+ 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

59K+ 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

How to add an image as label using JavaFX?

Maruthi Krishna

Maruthi Krishna

Updated on 19-Apr-2022 15:35:29

3K+ Views

You can display a text element/image on the User Interface using the Label component. It is a not editable text control, mostly used to specify the purpose of other nodes in the application.In JavaFX you can create a label by instantiating the javafx.scene.control.Label class. To create a label, you need ... Read More

Can we declare interface members as private or protected in java8?

Maruthi Krishna

Maruthi Krishna

Updated on 04-Feb-2022 06:05:47

6K+ Views

Interface in Java is similar to a class but, it contains only abstract methods and fields which are final and static.Since all the methods are abstract you cannot instantiate it. To use it, you need to implement this interface using a class and provide body to all the abstract methods ... Read More

Previous 1 ... 4 5 6 7 8 ... 87 Next
Advertisements