Krantik Chavan has Published 278 Articles

How to get the duration between two Instant timestamps in Java

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

21K+ Views

Let us first set two Instants with ofEpochSeconds() method using seconds from the epoch of 1970-01- 01T00:00:00Z.Now get the duration between the above two Instant:Duration res = Duration.between(one, two);Exampleimport java.time.Duration; import java.time.Instant; public class Demo {    public static void main(String[] args) {       Instant one = Instant.ofEpochSecond(1845836728); ... Read More

How to get the seconds and minutes between two Instant timestamps in Java

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

3K+ Views

The following are the two Instant timestamps:Instant one = Instant.ofEpochSecond(1355836728); Instant two = Instant.ofEpochSecond(1355866935);Get the Duration between both the Instant:Duration res = Duration.between(one, two);Now, get the seconds between the two timestamps:long seconds = res.getSeconds();Now, get the minutes between the two timestamps:long minutes = res.abs().toMinutes();Exampleimport java.time.Duration; import java.time.Instant; public class Demo ... Read More

How to SELECT records if the absolute value of the difference between two values is greater than a certain number?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

221 Views

To SELECT records if the absolute value of the difference between two values is greater than a certain number, following is the syntax:select *from yourTableName where abs(yourColumnName1-yourColumnName2) >= yourCertainNumber;Let us first create a table:mysql> create table DemoTable (    Number1 int ,    Number2 int ); Query OK, 0 rows ... Read More

How to display only 200 characters from total value in MySQL?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

397 Views

You can use LEFT() from MySQL to display some character from the entire value in MySQL. Following is the syntax:select left(yourColumnName ,200 ) AS anyAliasName from yourTableName;Let us first create a table:mysql> create table DemoTable (Paragraph longtext); Query OK, 0 rows affected (0.71 sec)Following is the query to insert records ... Read More

How to skip blank and null values in MySQL?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

4K+ Views

To skip blank and null in MySQL, use the following syntax:select *from yourTableName where yourColumnName IS NOT NULL AND yourColumnName '';Let us first create a table:mysql> create table DemoTable (Id int, FirstName varchar(20)); Query OK, 0 rows affected (0.66 sec)Following is the query to insert records in the table ... Read More

How to convert Long array list to long array in Java?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

4K+ Views

Firstly, declare a Long array list and add some elements to it:ArrayList < Long > arrList = new ArrayList < Long > (); arrList.add(100000 L); arrList.add(200000 L); arrList.add(300000 L); arrList.add(400000 L); arrList.add(500000 L);Now, set the same size for the newly created long array:final long[] arr = new long[arrList.size()]; int index ... Read More

Java Program to convert mathematical string to int

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

339 Views

To evaluate mathematical string to int, use Nashorn JavaScript in Java i.e. scripting. Nashorn invoke dynamics feature, introduced in Java 7 to improve performance.For scripting, use the ScriptEngineManager class for the engine:ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("nashorn");Now, use put() to set a key/value pair in the state ... Read More

MonthDay isBefore() Method in Java

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

130 Views

It can be checked if a particular MonthDay is before the other MonthDay in a timeline using the isBefore() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object that is to be compared. It returns true if the MonthDay object is before ... Read More

MonthDay isAfter() Method in Java

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

126 Views

It can be checked if a particular MonthDay is after the other MonthDay in a timeline using the isAfter() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object that is to be compared. It returns true if the MonthDay object is after ... Read More

What is the most efficient way to check the presence of a row in a MySQL table?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

276 Views

The most efficient want to check the presence of a row, use the count():select count(1) from yourTableName where yourCondition;Let us first create a table:mysql> create table DemoTable (    Id int,    FirstName varchar(20) ); Query OK, 0 rows affected (0.73 sec)Following is the query to insert some records in ... Read More

Advertisements