Date comparison is a fundamental requirement for any application. Often when displaying data on a page, you need to display the latest record at the top and then the records that were created later. For that, the records should be compared based on their date of creation. Javascript provides different ways to compare dates using its Date object and this article will discuss them with examples. Method 1: Using relational operator comparison Two date objects can directly be compared using <, >, ==, <=, >= and != operators. Behind the scenes, their values are compared and the result is determined. Example, // create two dateRead More →

You can check for the presence of vowels(a, e, i, o, u) in a string and list them using a java program. There are following two ways in which this can be done. Method 1: Iteration over the string Follow the below steps to write a program to check the vowels in a string using iteration. Initialize a string with all the vowels. Iterate over the characters of the string in which you want to check the vowels. In very iteration, check if the current character is from among the characters of string in Step 1(all vowels). If it is, then it is a vowelRead More →

What is a clone A clone is an exact copy of something. Object cloning is required when you want to create a new object with the same values of properties and containing all methods as an existing object. A practical scenario would be when creating a new entity whose most of the property values are common as all other entities except for a couple of properties. Instead of copying each property value one by one, you can clone the object and then change the properties having different values. This article will explain how to make a clone of an object along with the concepts ofRead More →

What are command line arguments Command line arguments are the values that are supplied to a shell script as input while executing it from the command line. Using command line arguments your script can read values directly from command line or terminal. Command line arguments are also called positional parameters. Command line arguments make a shell script dynamic and maintainable in that you can execute a shell script with different values supplied from outside and you do not need to write them inside the script. This means that for each set of values, you do not need to go and change the script. Passing argumentsRead More →

Read user input in shell script Getting user input is important for creating interactive and dynamic shell scripts so that they execute as user wants. For example, a file reader shell script which reads the file location from the user or a menu based script which performs actions based on user input. Linux and unix systems provide read command that can be used to capture user input and store it in variable. Syntax for reading user input in a shell script is given below read message Above command will wait for the user to enter characters and will keep on reading till enter key(or newRead More →

What is ajax AJAX stands for Asynchronous Javascript and XML and is used to fetch or send data from or to a server. AJAX is used for creating fast and dynamic web pages since it allows fetching data in the background after or during the page is loaded. In traditional applications, web pages were loaded completely. This means that entire page data will be fetched from the server and then rendered on the browser. If the user clicks a link, then the same would happen with the next page. But, with the use of AJAX, HTML, CSS and Javascript, now, complete page is not loaded.Read More →

A file and directory in java can be deleted by using delete method on java.io.File object which points to the underlying physical file or directory. delete method will delete a directory only if it is empty otherwise it would not remove the directory. This post will discuss different methods to delete a non-empty directory in java. Method 1: Iterative method Create a java.io.File object which points to the directory to be deleted. Get a list of all files in this directory using listFiles method. This method returns an array of java.io.File objects each of which represents a file in the directory. Iterate over the filesRead More →

Many times you need to check the time a file or folder was last modified to ensure that you have the latest and required file in place. There are many ways to get the last modified date time of a file in linux, unix or mac systems from command line terminal and this article will list them out with examples. Method 1: Using stat command stat command is used for checking a file status and returns file details such as its size, permissions, date created, date on which it was last accessed and the last modified date of the file. stat command should be followedRead More →

In a multi-threaded application where multiple threads are accessing a resource at the same time, it becomes necessary to handle concurrent modifications. Suppose a file is being written by a thread and at the same time it is being read by another thread. In such case, the thread reading the file will not have the updated contents. Similarly, if two threads are writing a file at the same time, then there are chances of the file becoming corrupt. To avoid such situations, there should be a mechanism that locks the file while writing or reading in java. Fortunately, java NIO has the facility to lockRead More →