To format year in yyyy format is like displaying the entire year. For example, 2018.Use the yyyy format like this −SimpleDateFormat("yyyy");Let us see an example −// year in yyyy format SimpleDateFormat simpleformat = new SimpleDateFormat("yyyy"); String strYear = simpleformat.format(new Date()); System.out.println("Current Year = "+strYear);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;The following is an example −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
Let us learn some points about TINYINT type in MySQL −The TINYINT type takes 1 byte i.e. 8 bits.The TINYINT(N), where N indicates the display width you want.For example, TINYINT(1) can be used to display width which is 1.Let us learn about the minimum and maximum values −The maximum value for tinyint is= (2(8-1)-1) = 127 The minimum value for tinyint is = -(2(8-1)) = -128.The value will be between -128 to 127. This means TINYINT (1) does not affect the maximum and minimum value of tinyint.Let us check it −Firstly, create a table with a column set as TINYINT ... Read More
You can check multiple columns for one value with the help of IN operator. The syntax is as follows −select *from yourTableName where value IN(yourColumnName1, yourColumnName2, ......N);To understand the above concept, let us create a table with some columns. The query to create a table is as follows −mysql> create table OneValueFromAllColumns −> ( −> StudentId int, −> StudentFirstname varchar(200), −> StudentLastname varchar(200), −> StudentAge int −> ); Query OK, 0 rows affected (1.41 sec)Insert some records in the table with the ... Read More
The Prime Minister of India is the head of government and pioneer of the executive branch of the Government of India. The Prime Minister is likewise the chief counselor to the President of India and is also the leader of the Council of Ministers.The Prime Minister can be an individual from any of the two places of Parliament (the Lok Sabha or the Rajya Sabha), however, must be the chief of the political party, having a superiority in the Lok Sabha.The Prime Minister is the senior individual from the bureau in the official branch of government in a parliamentary framework. ... Read More
Before getting into example, we should know what is Recycler view in android. Recycler view is more advanced version of list view and it works based on View holder design pattern. Using recycler view we can show grids and list of items.This example demonstrate about how to build a horizontal list view with Recycler View by creating a beautiful student records app that displays student name with age.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Open build.gradle and add Recycler ... Read More
To delete all rows containing string “foo” in table “bar”, you need to use LIKE operator.To understand the above syntax, let us create a sample table with name “bar”. The query to create a table is as follows. We will always insert records with string “foo” using INSERT command after creating the below table −mysql> create table bar -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Words longtext, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.61 sec)Now you can insert some records in the table using insert command. The string “foo” ... Read More
Use the System.getProperty() method in Java to get the Java Runtime Environment.It’s syntax is −String getProperty(String key)Above, the key is the name of the system property. Since, we want the Java Runtime Environment name, therefore we will add the key as −java.versionThe following is an example −Example Live Demopublic class Demo { public static void main(String[] args) { System.out.print("Java Specification Version: "); System.out.println(System.getProperty("java.specification.version")); System.out.print("java Runtime Environment (JRE) version: "); System.out.println(System.getProperty("java.version")); } ... Read More
First, we have taken a double variable and displayed it twice.double d = 399.8877; System.out.printf("d1 = %2$f d2 = %1$g", d, d);After that, we have formatted numerical int data −int val1 = 90, val2 = 35, val3 = 88, val4 = 600; System.out.printf("val1 = %d, val2 = %x, val3 = %o, val4 = %d", val1, val2, val3, val4); System.out.printf("val2 = %4$d, val2 = %3$d, val3 = %2$o, val4 = %1$d", val1, val2, val3, val4);Above, we have displayed %o for octal, %x for hexadecimal, %d for integer, etc.The following is the complete example −Example Live Demopublic class Demo { public static ... Read More
To order by relevance, use the case statement. To understand the concept, let us create a table. The query to create a table is as follows −mysql> create table OrderByRelevance -> ( -> UserId int, -> UserName varchar(200) -> ); Query OK, 0 rows affected (0.51 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into OrderByRelevance values(101, 'Carol Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into OrderByRelevance values(102, 'Carol Adams'); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More
To not allow any duplicate entry to be entered in a MySQL table, you need to add unique key. The syntax is as follows −alter ignore table yourTableName add constraint unique key(yourColumName);The above syntax sets unique key. To understand the above syntax, let us create a table.The following is the query to create a table −mysql> create table RemoveDuplicateEntry −> ( −> Id int, −> Name varchar(100) −> )ENGINE = MyISAM; Query OK, 0 rows affected (0.15 sec)Now you can implement the syntax discussed in the beginning. The query is as follows −mysql> alter table ... Read More