5 Minutes of Java (1. Variable and Data Type)

Variable and Data Type

You have learnt about the following data type in Python.

  • int – Used for whole numbers (e.g. 1, 10, 100)
  • float – Used for decimal numbers (e.g 1.4, 2.5, 3.0)
  • str – Used for any textual data (e.g. ‘John, “Peter”, “Male”)
    You can use both single quote (‘john’) or double quote (“john”)

In Java, there is similar concept of data type as well.

  • int – Used for whole numbers as well
  • float, double – Used for decimal numbers
    In this course, for simplicity, we will always use double to store decimal numbers.
  • String – Used for textual data. Take note that only double quote is allowed (“john”)

2 thoughts on “5 Minutes of Java (1. Variable and Data Type)

    1. No. You should use char if you are sure that your variable is only going to store one character. You are right, single quote for char.

      This can be considered as a new data type compared to what you have learnt in python.

Leave a Reply