How to compare two Dates in Java.

Java
This code snippet shows you how to compare a Date to another in Java. In order to do this check, we use the compareTo operator of the java.util.Date class. The java.util.Date.compareTo(Date anotherDate) compares a Date Object with the specified Date value. The default usage is [crayon-5a377fc7c0f80174347026/] where is one of these six comparison operators: [ , >=, !=,
Read More

How to compare two BigDecimals in Java.

Java
This code snippet shows you how to compare a BigDecimal to another in Java. In order to do this check, we use the compareTo operator of the java.math.BigDecimal class. The java.math.BigDecimal.compareTo(BigDecimal val) compares a BigDecimal Object with the specified BigDecimal value. The default usage is [crayon-5a377fc7c1d78759054540/] where is one of these six comparison operators: [ , >=, !=,
Read More

java.io.File.mkdirs() Example

Java
java.io.File.mkdirs() Method description: Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Show method details. Declaration: [crayon-5a377fc7c240f315465688/] Parameters: The method has no parameters. Return value: true if and only if the directory was created, along with all necessary parent directories; false otherwise Exceptions: SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method does not permit verification of the existence of the named directory and all necessary parent directories; or if the SecurityManager.checkWrite(java.lang.String) method does not permit the named directory and all necessary parent directories to be created Example: The following example illustrates the usage of the java.io.File.mkdirs() method. [crayon-5a377fc7c241b141984202/] Output: If we compile and run this code sample, it will give the following result: [crayon-5a377fc7c2422945678667/] See also: java.io.file.mkdir()
Read More

java.io.File.listRoots() Example

Java
java.io.File.listRoots() Method description: List the available filesystem roots. Show method details. Declaration: [crayon-5a377fc7c2a1b732172805/] Parameters: The method has no parameters. Return value: An array of File objects denoting the available filesystem roots, or null if the set of roots could not be determined. The array will be empty if there are no filesystem roots. Exceptions: Example: The following example illustrates the usage of the java.io.File.listRoots() method. [crayon-5a377fc7c2a26132698119/] Output: If we compile and run this code sample, it will give the following result: [crayon-5a377fc7c2a2d063016576/]
Read More

java.io.File.mkdir() Example

Java
java.io.File.mkdir() Method description: Creates the directory named by this abstract pathname. Show method details. Declaration: [crayon-5a377fc7c3026352938625/] Parameters: The method has no parameters. Return value: true if and only if the directory was created; false otherwise Exceptions: SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created Example: The following example illustrates the usage of the java.io.File.mkdir() method. [crayon-5a377fc7c302e240398296/] Output: If we compile and run this code sample, it will give the following result: [crayon-5a377fc7c3032599853996/] See also: java.io.file.mkdirs()
Read More

java.io.File.setReadOnly() Example

Java
java.io.File.setReadOnly() Method description: Marks the file or directory named by this abstract pathname so that only read operations are allowed. Show method details. Declaration: [crayon-5a377fc7c35ed463009360/] Parameters: The method has no parameters. Return value: true if and only if the operation succeeded; false otherwise Exceptions: SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the named file Example: The following example illustrates the usage of the java.io.File.setReadOnly() method. [crayon-5a377fc7c3610566890755/] Output: If we compile and run this code sample, it will give the following result: [crayon-5a377fc7c3625055662480/] See also: java.io.file.canWrite()
Read More

java.io.File.toPath() Example

Java
java.io.File.toPath() Method description: Returns a java.nio.file.Path object constructed from the this abstract path. Show method details. Declaration: [crayon-5a377fc7c3ce8358608807/] Parameters: The method has no parameters. Return value: a Path constructed from this abstract path Exceptions: InvalidPathException - if a Path object cannot be constructed from the abstract path (see FileSystem.getPath) Example: The following example illustrates the usage of the java.io.File.toPath() method. [crayon-5a377fc7c3cf3670331811/] Output: If we compile and run this code sample, it will give the following result: [crayon-5a377fc7c3cfa662417909/]
Read More

java.io.File.toString() Example

Java
java.io.File.toString() Method description: Returns the pathname string of this abstract pathname. Show method details. Declaration: [crayon-5a377fc7c4357198660951/] Parameters: The method has no parameters. Return value: The string form of this abstract pathname Exceptions: Example: The following example illustrates the usage of the java.io.File.toString() method. [crayon-5a377fc7c4362661438962/] Output: If we compile and run this code sample, it will give the following result: [crayon-5a377fc7c4369476887946/]
Read More

java.io.File.length() Example

Java
java.io.File.length() Method description: Returns the length of the file specified by this abstract pathname. Show method details. Declaration: [crayon-5a377fc7c49cb248682819/] Parameters: The method has no parameters. Return value: The length, in bytes, of the file specified by this abstract pathname, or 0L if the file does not exist. Some operating systems may return 0L for pathnames denoting system-dependent entities such as devices or pipes. Exceptions: SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file Example: The following example illustrates the usage of the java.io.File.length() method. [crayon-5a377fc7c49eb806845430/] Output: If we compile and run this code sample, it will give the following result: [crayon-5a377fc7c49f3997816486/]
Read More

java.io.File.lastModified() Example

Java
java.io.File.lastModified() Method description: Returns the time that the file specified by this abstract pathname was last modified. Show method details. Declaration: [crayon-5a377fc7c5256254104868/] Parameters: The method has no parameters. Return value: A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs Exceptions: SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file Example: The following example illustrates the usage of the java.io.File.lastModified() method. [crayon-5a377fc7c525f905891759/] Output: If we compile and run this code sample, it will give the following result: [crayon-5a377fc7c526f362002481/]
Read More