Computer Programming - Week 3
Computer Programming - Week 3
Data Types
Character Data Types are used for characters, marks and symbols; it uses the keyword char (short for
character), and then the literal that represents the variable, usually enclosed in single quotes (‘’) .
The Boolean Data Type is a 1-bit data type used for conditional statements, or statements that return a value of
either True or False; it uses the keyword boolean and has a default value of False.
SESSION 2
Variables
Also called Fields in Java.
Items of data used to store the state of objects.
Components of Variables
The data type indicates the type of value that the variable will hold.
The identifier serves as the label for the variable; it can be called for use on the program’s classes on methods .
Types of Variables
Primitive Variables are composed of primitive data types stored in its actual memory location; primitive
variables are usually located within methods, and cannot be used across other methods.
Reference Variables are variables that store an address in its actual memory location instead of the data itself;
the address points the program to the data located in another location. Reference variables are usually used for
classes so that a class and its corresponding methods and values can be used.
SESSION 3
Constants
Used to represent values that never change (such as the number of days of the week, number of days in a year,
the value of pi, etc.).
Especially important if the value that is being represented is constantly being used across the program’s different
classes and methods.
Uses the final keyword for the variable’s declaration.
Sample #1:
Output:
Sample #2:
Output:
References
Deitel, H., & Deitel, P. (2004). Java: How to program (early objects). Prentice Hall.
Lambert, K., Osborne, M. (2011). Fundamentals of Java. Cengage Learning Asia Pte Ltd.