Maruthi Krishna has Published 1025 Articles

How to search a file in a directory in java

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:09:15

The List() method of the File class returns a String array containing the names of all the files and directories in the path represented by the current (File) object.In order to search for a file you need to compare the name of each file in the directory to the name ... Read More

How to get the list of jpg files in a directory in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:06:23

The String[] list(FilenameFilter filter) method of a File class returns a String array containing the names of all the files and directories in the path represented by the current (File) object. But the retuned array contains the filenames which are filtered based on the specified filter. The FilenameFilter is an interface in ... Read More

How to create Directories using the File utility methods in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:05:09

Since Java 7 the File.02s class was introduced this contains (static) methods that operate on files, directories, or other types of files.The createDirectory() method of the Files class accepts the path of the required directory and creates a new directory.ExampleFollowing Java example reads the path and name of the directory to be created, ... Read More

How to convert primitive data into wrapper class using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:37:48

Java provides certain classes called wrapper classes in the java.lang package. The objects of these classes wrap primitive datatypes within them.Using wrapper classes, you can also add primitive datatypes to various Collection objects such as ArrayList, HashMap etc. You can also pass primitive values over network using wrapper classes.ExampleLive Demoimport ... Read More

How to inherit multiple interfaces in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:34:58

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Just like classes you can extend one interface from another using the extends keyword. You can also extend multiple interfaces from an interface using the extends keyword, by separating the ... Read More

What do you mean by default constructor in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:33:31

A constructor is similar to method and it is invoked at the time creating an object of the class, it is generally used to initialize the instance variables of a class. The constructors have same name as their class and, have no return type.The default constructor in Java initializes the ... Read More

What is Java reg ex to check for date and time?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:32:21

To match a regular expression with the given string You need to:.Compile the regular expression of the compile() method of the Pattern class.Get the Matcher object bypassing the required input string as a parameter to the matcher() method of the Pattern class.The matches() method of the Matcher class returns true ... Read More

How to get Time in Milliseconds for the Given date and time in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:31:49

The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string.One of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat object. To parse/convert a string as a Date object Instantiate this class by passing desired format string.Parse ... Read More

How to get current date/time in milli seconds in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:29:11

The getTime() method of the Date class retrieves and returns the epoch time (number of milliseconds from Jan 1st 1970 00:00:00 GMT0.ExampleLive Demoimport java.util.Date; public class Sample {    public static void main(String args[]){         //Instantiating the Date class       Date date = new Date(); ... Read More

What are date temporal fields in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:26:06

A temporal field is a field of date-time, such as month-of-year or hour-of-minute. These fields are represented by the TemporalField interface and the ChronoField class implements this interface.Following are the list of various temporal fields regarding date supported by the ChronoField class −FieldDescriptionALIGNED_DAY_OF_WEEK_IN_MONTHThis field represents the day of the week ... Read More

Advertisements