Samual Sam has Published 2492 Articles

How to display numbers in scientific notation in Java?

Samual Sam

Samual Sam

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

4K+ Views

To display number in scientific notation, create NumberFormat object first −NumberFormat numFormat = newDecimalFormat();Now, let’s say you need to format the minimum value of Integer −int i = Integer.MIN_VALUE; System.out.println(i); numFormat = newDecimalFormat("0.######E0"); System.out.println(numFormat.format(i)); numFormat = newDecimalFormat("0.#####E0"); System.out.println(numFormat.format(i));Above, we have used format() method of the NumberFormat class.Example Live Demoimport java.text.DecimalFormat; import ... Read More

How to check whether column value is NULL or having DEFAULT value in MySQL?

Samual Sam

Samual Sam

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

436 Views

You can use the concept of IFNULL() for this. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100) DEFAULT 'Larry',    Age int DEFAULT NULL ); Query OK, 0 rows affected (0.73 sec)Insert records in the table ... Read More

ByteBuffer asFloatBuffer() method in Java

Samual Sam

Samual Sam

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

107 Views

A view of the ByteBuffer can be created as a FloatBuffer using the asFloatBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a float buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is ... Read More

How to write a while loop in a JSP page?

Samual Sam

Samual Sam

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

1K+ Views

Following is the while loop example −           WHILE LOOP Example                           JSP Tutorial                           The above code will generate the following result −JSP Tutorial JSP Tutorial JSP Tutorial

How to extract multiple integers from a String in Java?

Samual Sam

Samual Sam

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

484 Views

Let’s say the following is our string with integer and characters −String str = "(29, 12; 29, ) (45, 67; 78, 80)";Now, to extract integers, we will be using the following pattern −\dWe have set it with Pattern class −Matcher matcher = Pattern.compile("\d+").matcher(str);Example Live Demoimport java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import ... Read More

How to alter the data type of a MySQL table’s column?

Samual Sam

Samual Sam

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

124 Views

You can use modify command for this. Let us first us create a table.mysql> create table DemoTable (    StudentId varchar(200) not null,    StudentName varchar(20),    StudentAge int,    StudentAddress varchar(20),    StudentCountryName varchar(20) ); Query OK, 0 rows affected (0.73 sec)Now check the description of table.mysql> desc DemoTable;This ... Read More

Getting a subvector from a vector in C++

Samual Sam

Samual Sam

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

4K+ Views

This is a C++ program for getting a subvector from a vector in C++AlgorithmBegin   Declare s as vector s(vector const &v, int m, int n) to    initialize start and end position of vector to constructor.       auto first = v.begin() + m.         ... Read More

CharBuffer equals() method in Java

Samual Sam

Samual Sam

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

86 Views

The equality of two buffers can be checked using the method equals() in the class java.nio.CharBuffer. Two buffers are equal if they have the same type of elements, the same number of elements and the same sequence of elements. The method equals() returns true if the buffers are equal and ... Read More

Java Program to change a file attribute to writable

Samual Sam

Samual Sam

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

77 Views

Let’s say our file is “input.txt”, which is set read-only −File myFile = new File("input.txt"); myFile.createNewFile(); myFile.setReadOnly();Now, set the above file to writable −myFile.setWritable(true);After that, you can use canWrite() to check whether the file is writable or not.Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) ... Read More

Mark file or directory Read Only in Java

Samual Sam

Samual Sam

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

743 Views

A file can be set to read-only by using the method java.io.File.setReadOnly(). This method requires no parameters and it returns true if the file is set to read-only and false otherwise. The method java.io.File.canWrite() is used to check whether the file can be written to in Java and if not, ... Read More

Advertisements