DEV Community

Cover image for One Commit at a Time ! Series - 19
Annapoorani Kadhiravan
Annapoorani Kadhiravan

Posted on

One Commit at a Time ! Series - 19

JAVA

public class Main {
  public static void main(String[] args) {
    String x = "10";
    int y = 20;
    String z = x + y;
    System.out.println(z);
  }
}
Enter fullscreen mode Exit fullscreen mode

Explanation :

This program demonstrates string concatenation and type coercion in Java. When a String is added to a primitive data type like an int using the + operator, Java automatically converts the integer into a string and concatenates them together rather than performing mathematical addition.

Step-by-step breakdown:

  1. String x = "10";: Declares a string variable named x holding the text "10".
  2. int y = 20;: Declares an integer variable named y holding the numeric value 20.
  3. String z = x + y;: Combines x and y. Because x is a String, the integer y is converted to the string "20" and joined with "10", resulting in the string "1020".
  4. System.out.println(z);: Prints the final value of z to the console.

The output of the program will be:

1020

Enter fullscreen mode Exit fullscreen mode

SQL

Text Fields vs. Numeric Fields
SQL requires single quotes around text values (most database systems will also allow double quotes).

However, numeric fields should not be enclosed in quotes:

Example

SELECT * FROM Customers
WHERE CustomerID = 1;
Enter fullscreen mode Exit fullscreen mode

References :
https://www.w3schools.com/sql/sql_where.asp
https://www.w3schools.com/java/java_examples.asp

Top comments (0)