Krantik Chavan has Published 308 Articles

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

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

169 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

286 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

C++ Program to Implement Park-Miller Random Number Generation Algorithm

Krantik Chavan

Krantik Chavan

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

353 Views

Park-Miller Random Number Generation Algorithm is another method of generating random numbers.A general formula of a random number generator (RNG) of this type is: X_{k+1} = g X(k) mod nWhere the modulus n is a prime number or a power of a prime number, the multiplier g is an element ... Read More

Java Program to get the beginning and end date of the week

Krantik Chavan

Krantik Chavan

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

1K+ Views

At first, set a date:LocalDate date = LocalDate.of(2019, 4, 16);Now, get the date for the beginning of the week:LocalDate start = date; while (start.getDayOfWeek() != DayOfWeek.MONDAY) {    start = start.minusDays(1); }Now, get the date for the end of the week:LocalDate end = date; while (end.getDayOfWeek() != DayOfWeek.SUNDAY) {   ... Read More

How to skip blank and null values in MySQL?

Krantik Chavan

Krantik Chavan

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

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

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

C++ Program to Implement Naor-Reingold Pseudo Random Function

Krantik Chavan

Krantik Chavan

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

115 Views

Naor-Reingold Pseudo Random Function is another method of generating random numbers.Moni Naor and Omer Reingold described efficient constructions for various cryptographic primitives in private key as well as public-key cryptography, in 1997. Let p and l be prime numbers with l |p−1. Select an element g ε Fp* of multiplicative ... Read More

Java Program to convert mathematical string to int

Krantik Chavan

Krantik Chavan

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

245 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

73 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

Advertisements