The final static field variable is a constant variable. There is only one copy of this variable available. It is mandatory to initialize the final static field variable explicitly as the default value for it is not provided by the JVM. Also, this variable cannot be reinitialized.A program that initializes the final static field variable using a static initialization block is given as follows:Example Live Demopublic class Demo { final static int num; static { System.out.println("Running static initialization block."); num = 6; } public static void main(String[] args) { ... Read More
This error can occur if you try to set data higher than the allowed limit. As an example, you cannot store a string in a column of type bit because varchar or string takes size higher than bit data type.You need to use the following syntax for bit type column:anyBitColumnName= b ‘1’ OR anyBitColumnName= b ‘0’To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table IncasesensitiveDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(10), -> PRIMARY KEY(Id) -> ); Query OK, ... Read More
Firstly, set the double values −double d1 = 1.39876; double d2 = 2.39876; double d3 = 0.66920;Now, format the double values with new DecimalFormat("0.#####E0") −System.out.println(new DecimalFormat("0.#####E0").format(d1)); System.out.println(new DecimalFormat("0.#####E0").format(d2)); System.out.println(new DecimalFormat("0.#####E0").format(d3));The following is an example −Example Live Demoimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { double d1 = 1.39876; double d2 = 2.39876; double d3 = 0.66920; System.out.println(new DecimalFormat("0.#####E0").format(d1)); System.out.println(new DecimalFormat("0.#####E0").format(d2)); ... Read More
You can use IFNULL() function from MySQL to return a value even if there is not result. Let us create a table. Te query to create a table.mysql> create table IfNullDemo −> ( −> Id int, −> Name varchar(100) −> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table with the help of insert command. The query is as follows −mysql> insert into IfNullDemo values(1, 'John'); Query OK, 1 row affected (0.18 sec) mysql> insert into IfNullDemo values(200, 'Sam'); Query OK, 1 row affected (0.21 sec) mysql> insert into IfNullDemo ... Read More
To change the year in MySQL date, you need to use DATE_FORMAT() function with UPDATE command. The syntax is as follows.UPDATE yourTableName SET yourDateColumnName = DATE_FORMAT(yourDateColumnName ,'yourYearValue-%m-%d');To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ChangeYear -> ( -> id int not null auto_increment, -> ArrivalTime date, -> PRIMARY KEY(id) -> ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into ChangeYear(ArrivalTime) values(date_add(now(), interval -2 year)); Query OK, 1 row affected, 1 warning ... Read More
There are many interesting answers to this question. But I found one very fascinating and amazing phenomenon. When it rains suddenly in the Atacama desert in Chile, which is the driest non-polar desert on Earth, there will be a sudden spur of life in the desert.If the desert gets heavy rainfall during their spring season which is October and November, there will be a sudden bloom of the flowers ‘hibernating’ beneath its surface. It fills the entire desert with an explosion of color by the flowers coming to their full bloom which is eagerly waiting for the rain, leaving the place ... Read More
To find the nth highest value of a column, you need to use ORDER BY DESC with LIMIT clause. If you want the second highest value of a column, use the below syntax:SELECT *FROM yourTableName ORDER BY DESC yourColumnName LIMIT 1, 1;If you want the fourth highest value of a column, use the below syntax:SELECT *FROM yourTableName ORDER BY DESC yourColumnName LIMIT 3, 1;If you want the first highest value of a column, use the below syntax:SELECT *FROM yourTableName ORDER BY DESC yourColumnName LIMIT 1;As discussed in the above syntax, you need to change only in LIMIT clause. To understand ... Read More
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("000000E0") and use the format() method as well.new DecimalFormat("000000E0").format(199) new DecimalFormat("000000E0").format(29089)Since we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete example −Example Live Demoimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { System.out.println(new DecimalFormat("000000E0").format(199)); System.out.println(new DecimalFormat("000000E0").format(29089)); System.out.println(new DecimalFormat("000000E0").format(398987)); System.out.println(new DecimalFormat("000000E0").format(498989)); ... Read More
The Z means "zero hour offset", also known as "Zulu time" (UTC) in the ISO 8601 time representation. However, ACP 121 standard defines the list of military time zones and derives the "Zulu time" from the Greenwich Mean Time (GMT).TimeZone can be formatted in z, Z or zzzz formats.The following is an example that displays how to implement SimpleDateFormat(“Z”) −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More
To delete all the records from a MySQL table, you can use the TRUNCATE statement.The syntax is as follows −TRUNCATE TABLE yourTableName;The above syntax deletes all the records from the table. To understand the above syntax, let us create a table. The following is the query to create a table −mysql> create table DeleteAllFromTable −> ( −> PersonId int, −> PersonName varchar(200) −> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table with the help of insert command.The query is as follows −mysql> insert ... Read More