Home » Online Computer Education » Learn Fundamentals of Java Programming “Primitive Data Types in Java Programming ” Lesson 4

Learn Fundamentals of Java Programming “Primitive Data Types in Java Programming ” Lesson 4

Primitive Data Types

Besides the two Java data types (int, double) that you have seen in the percentage calculator program, we can use six more data types. In all, Java supports eight primitive data types as in Table 1.

Java fundamentals Primitive data type 1

Java fundamentals  Primitive data type 2

STYLE TIP – Variable Names

1. Variable names can begin with either an alphabetic character, an underscore (_), or a dollar sign ($). However, convention is to begin a variable name with a letter. They can consist of only alphabets, digits, and underscore.

2. Variable names must be one word. Spaces are not allowed in variable names. Underscores are allowed. “total_marks” is fine but
“total marks” is not.

3. There are some reserved words in Java that cannot be used as variable names, for example – int.

4. Java is a case-sensitive language. Variable names written in capital letters differ from variable names with the same spelling but written in small letters. For example, the variable name “percentage” differs from the variable name “PERCENTAGE” or “Percentage”.

5. It is good practice to make variable names meaningful. The name should indicate the use of that variable.

6. You can define multiple variables of the same type in one statement by separating each with a comma. For example, you can define three integer variables as below:
int num1, num2, num3;

About

The main objective of this website is to provide quality study material to all students (from 1st to 12th class of any board) irrespective of their background as our motto is “Education for Everyone”. It is also a very good platform for teachers who want to share their valuable knowledge.

Leave a Reply

Your email address will not be published.