Datatypes

Goals For This Lesson

After completing this lesson students should be able to:

  • understand the common uses of certain datatypes.
  • identify and classify data using datatypes
  • describe objects in the real world using datatypes

Why Do We Use Datatypes?

Datatypes help us as programmers represent different forms of information in the programs we write.  The main datatypes that you will come across in Java are the String, int, char, double and boolean datatypes; these datatypes are also found in most other higher-level programming languages.  These datatypes are used with a programming construct called a variable which stores data based on which datatype it is associated with, i.e. a String variable can only hold Strings, while a boolean variable can only hold booleans.

ints and doubles

This concept allows us as programmers to write code that works with numbers; both whole numbers, in the case of the int datatype, and decimal numbers, in the case of double datatype, (when precision is important). 

Strings and chars

Strings are used in cases where we want to store names, street addresses or complex encrypted information.  When a single character needs to be stored (this could be a single letter, a single symbol or even a single-digit number) chars are used by programmers in these cases. 

booleans

The boolean datatype assists us when we want to store information which we use in the decision making parts of the program (control flow).

 

Comparison Operators

Operators are the tools programmers use to compare or combine elements in the program.  We will focus here on the ones used for comparison.  The main operators for making comparisons are the ==, !=, >=, <=, > and < operators. 

Understanding These Tools

These operators are best understood as statements that can be answered with a response of either "True." or "False.".  Now, let's see the translation of these operators into statements:

  • a == b, “a is equal to b.”
  • a != b, “a is not equal to b.”
  • a > b, “a is greater than b.”
  • a < b, “a is less than b.”
  • a >= b, “a is greater than or equal to b.”
  • a <= b, “a is less than or equal to b.”

As programmers, we use the responses to these statements, which turn out to be booleans (true or false), to make decisions in our programs.

Object-Oriented Programming

Object-oriented programming is a programming paradigm which focuses its attention on how to best describe concepts which exist in the real world, programmatically.   Objects are the constructs which we use as software engineers to describe the aforementioned real-world concepts.   We use variables as our means to describe the intrinsic characteristics of real-world concepts.  While methods are used to describe the behavior of these concepts.

Camera Class

The Camera class defines the key features and functions of a camera.  It is a clear example of how classes are created in the Java programming langauge.

camera_Screen_Capture.png

UML For the Camera Class

This UML diagram allows us to see, at a glance, the data fields and methods that compose the Camera class.

Java_Camera_Class.png