To fetch rows where a field value is less than 5 chars, you need to use LENGTH() function. The syntax is as follows −SELECT *FROM yourTableName WHERE LENGTH(yourColumnName) < 5;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table fieldLessThan5Chars -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> yourZipCode varchar(10) -> ); Query OK, 0 rows affected (0.52 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into fieldLessThan5Chars(yourZipCode) values('35801'); Query ... Read More
This Integer.numberOfLeadingZeros() method in Java returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified int value.We have the following decimal as an example.int dec = 294;Calculated binary using Integer.toBinaryString() as shown below −Integer.toBinaryString(dec);Now let us see the implementation of Integer.numberOfLeadingZeros() method.Example Live Demopublic class Demo { public static void main(String []args) { int dec = 294; System.out.println("Decimal = " + dec); System.out.println("Binary = " + Integer.toBinaryString(dec)); System.out.println("Count of one bits = " + Integer.bitCount(dec)); ... Read More
The Integer.numberOfTrailingZeros() method returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified int value.We have the following decimal as an example.int dec = 199;Calculated binary using Integer.toBinaryString() as shown below −Integer.toBinaryString(dec);Now let us see the implementation of Integer.numberOfTrailingZeros() method.Example Live Demopublic class Demo { public static void main(String []args) { int dec = 199; System.out.println("Binary = " + Integer.toBinaryString(dec)); System.out.println("Count of one bits = " + Integer.bitCount(dec)); System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(dec)); } ... Read More
You can easily add more than one column that does not exist in a query using multiple AS keywords.Let us first create a table. The query to create a table is as follows −mysql> create table ColumnDoesNotExists -> ( -> UserId int, -> UserName varchar(20) -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ColumnDoesNotExists(UserId, UserName) values(100, 'Larry'); Query OK, 1 row affected (0.14 sec) mysql> insert into ColumnDoesNotExists(UserId, UserName) values(101, 'Sam'); Query OK, 1 row affected (0.22 sec) mysql> ... Read More
Every data type in Java has a minimum as well as maximum range, for example, for Integer.Minimum = -2147483648 Maximum = 2147483647Let’s say for Integer, if the value extends the maximum range display above, it leads to Overflow. However, if the value is less than the minimum range displayed above, it leads to Underflow.The following program displays the limits on datatypes in Java.Example Live Demopublic class Demo { public static void main(String[] args) { System.out.println("Limits of primitive DataTypes"); System.out.println("Byte Datatype values..."); System.out.println("Min = " + Byte.MIN_VALUE); System.out.println("Max = ... Read More
To display default initial values of a datatype, you need to just declare a variable of the same datatype and display it.The following is a Java program to display initial values of DataTypes.Example Live Demopublic class Demo { boolean t; byte b; short s; int i; long l; float f; double d; void Display() { System.out.println("boolean (Initial Value) = " + t); System.out.println("byte (Initial Value) = " + b); System.out.println("short (Initial Value) = " + s); System.out.println("int (Initial Value) = " ... Read More
To check whether the entered value is a digit or not in Java, use the Character.isDigit() method.We have a character to be checked.char val = '5';Now let us use the Character.isDigit() method.if (Character.isDigit(val)) { System.out.println("Character is a digit!"); } else { System.out.println("Character is not a digit!"); }Let us see the complete example now to check for Uppercase in Java.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking for digit..."); char val = '5'; System.out.println("Value: "+val); if (Character.isDigit(val)) { ... Read More
Add a column that does not exist in a query, with the help of AS keyword. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ....N, yourValue AS yourColumnName, ....N' FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ColumnDoesNotExists -> ( -> UserId int, -> UserName varchar(20) -> ); Query OK, 0 rows affected (0.67 sec)ExampleInsert some records in the table using insert command. The query is as follows −mysql> insert into ColumnDoesNotExists(UserId, UserName) values(100, 'Larry'); Query OK, ... Read More
To convert hex string to byte array, you need to first get the length of the given string and include it while creating a new byte array.byte[] val = new byte[str.length() / 2];Now, take a for loop until the length of the byte array.for (int i = 0; i < val.length; i++) { int index = i * 2; int j = Integer.parseInt(str.substring(index, index + 2), 16); val[i] = (byte) j; }Let us see the complete example.Example Live Demopublic class Demo { public static void main(String args[]) { String str = "p"; ... Read More
To convert byte[] to String, firstly let us declare and initialize a byte array.// byte array byte[] arr = new byte[] {78, 79, 33};Now take a String and include the array in it.String str = new String(arr);Let us see the complete example to convert byte array to String.Example Live Demopublic class Demo { public static void main(String args[]) { // byte array byte[] arr = new byte[] {78, 79, 33}; String str = new String(arr); // string System.out.println("String = "+str); } }OutputString = NO!
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP