Check if a Float is Infinite or Not a Number (NaN) in Java

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

2K+ Views

To check if a Float is isInfinite, use the isInfinite() method and to check for NAN, use the isNaN() method.Example Live Demopublic class Demo {    public static void main(String[] args) {       float value1 = (float) 1 / 0;       boolean res1 = Float.isInfinite(value1);       System.out.println("Checking for isInfinite? = "+res1);       float value2 = (float) Math.sqrt(9);       boolean res2 = Float.isNaN(value2);       System.out.println("Checking for isNan? = "+res2);    } }OutputChecking for isInfinite? = true Checking for isNan? = false

Set TIME Data Type to HH:MM in MySQL

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

3K+ Views

You can use DATE_FORMAT() to set time data type to be only HH:MM. Following is the syntax −select DATE_FORMAT(yourColumnName, "%H:%i") AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable (    Arrivaltime time ); Query OK, 0 rows affected (0.61 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('08:20'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('05:40'); Query OK, 1 row affected (0.12 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------------+ | Arrivaltime ... Read More

Add Items in a JComboBox at Runtime in Java

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

2K+ Views

The following is an example to add items on runtime on a JComboBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JComboBox combo = new JComboBox(new String[] { "One", "Two", "Three", "Four", "Five", "Six" });       JButton add = new JButton("Add");       add.addActionListener(new ActionListener() {          @Override          public void actionPerformed(ActionEvent e) {         ... Read More

ByteBuffer asDoubleBuffer Method in Java

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

157 Views

A view of the ByteBuffer can be created as a DoubleBuffer using the asDoubleBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a double buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          DoubleBuffer bufferD = bufferB.asDoubleBuffer();       ... Read More

Filter Data Using WHERE Clause and IN in Android SQLite

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

217 Views

Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to filter data using where Clause and “IN” in Android sqlite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill ... Read More

Use INTERSECT Operator in Android SQLite

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

177 Views

Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to use INTERSECT operator in Android sqliteStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More

What are JSP Literals

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

776 Views

The JSP expression language defines the following literals −Boolean − true and falseInteger − as in JavaFloating point − as in JavaString − with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \.Null − null

Retrieve CLOB Value Using getCharacterStream Method in JDBC

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

729 Views

The ResultSet interface provides the method named getClob() to retrieve clob datatype from a table in a database. In addition to this it also provides a method named getCharacterStream()Like getClob() this method also accepts an integer representing the index of the column (or, a String value representing the name of the column) and retrieves the value at the specified column. The difference is unlike the getClob() method (which returns a Clob object) this method returns an object of the Reader class.ExampleAssume we have created a table named MyData in the database with the following description.+---------+--------------+------+-----+---------+-------+ | Field   | Type ... Read More

IntStream forEachOrdered Method in Java

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

418 Views

The forEachOrdered() method in Java assures that each element is processed in order for streams that have a defined encounter order.The syntax is as followsvoid forEachOrdered(IntConsumer action)Here, the action parameter is a non-interfering action to be performed on the elements.Create an IntStream and add elements to the streamIntStream intStream = IntStream.of(50, 70, 80, 100, 130, 150, 200);Now, use the forEachOrdered() method to display the stream elements in orderintStream.forEachOrdered(System.out::println);The following is an example to implement IntStream forEachOrdered() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { ... Read More

Create Decade Tuple in Java

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

109 Views

Create Decade Tuple in Java using a constructor or with() method. Here, we will see how to create a Decade of Tuple using constructor.Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following package −import org.javatuples.Decade;Note − Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples −Steps − How ... Read More

Advertisements