Java supports eight different primitive data types.
Java provides four ways to deal with numbers for different applications.
Real Numbers with decimals: The `float` and the `double` data types.
Real whole numbers: The int data type
Any ASCII value that can be represented in the machine is called a character (i.e., a char) . The char data type holds a single character and it must be enclosed inside the single quotes ' ' and represents a numeric value. For example:
> char c = 'a'
> c
'a'
> (int)c
97
The value 97 is obtained by typecasting to an integer the character c. Type casting means to force Java to transform a data type into another data type by specifying the data type inside the parenthesis, as shown (int). You can find the decimal value for the character 'a' and all the characters on your keyboard in the following table.
Java supports an additional data type called `String`. The String is a collection of characters that represent words or phrases.
This is called concatenation. Concatenation is the process of gluing Strings with any other data type, including objects, such as Strings. The process to concatenate must be done through the '+' operand.
> String x = "hello" // defining a String x
> String y = "world" // defining a String y
Let us create another variable, z that will concatenate the value of x and y by using the `+` operator.
> String z = x + y
> z
"helloworld"
But also, you can incorporate more Strings or variables in between,
> z = x+" "+y
"hello world"
AP CS A
[Scope, Comments, and Programming Style]
MOD-2.C Describe the functionality and use of program code through comments.
MOD-2.C.1 Comments are ignored by the compiler and are not executed when the program is run.
MOD-2.C.2 Three types of comments in Java include /* */, which generates a block of comments, //, which generates a comment on one line, and /** */, which are Javadoc comments and are used to create API documentation.
CS1
[Scope, Comments, and Programming Style]
130.421.c.2.d Write programs with proper programming style to enhance the readability and functionality of the code by using meaningful descriptive identifiers, internal comments, white space, spacing, indentation, and a standardized program style;
130.421.c.6.s Demonstrate an understanding of the concept of scope;
Design, write, test, and debug a program that effectively uses the different structured data types provided in the language like strings, arrays/lists, dictionaries, sets
Trace the flow of control during the execution of a program (both correct and incorrect).
Use appropriate terminology to identity elements of a program (e.g., identifier, operator, operand)
[Scope, Comments, and Programming Style]
SDF-18. Apply consistent documentation and program style standards.
Rubric