Unit 4 - Java language construcs Flashcards

Goals: – what primitive data types Java has and what value range they cover. – how variables can be temporarily stored with values. – what important operators exist in Java and how they are used. – what control structures are available and how statements can be repeated for control purposes. – how the visibility of classes and their elements can be defined in targeted ways using packages.

1
Q

What are the 4 primitive data types?

A
  • logical value (boolean) - True/False
  • integer (byte, short, int, long) - whole numbers
  • floating point number (float, double) - any number
  • Character (char) - letters & symbols
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a string?

A

It has properties of a primitive data type but it is a java class.
It is used to save strings of any length. The class String offers many existing methods for processing strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a variable?

A

It stores values in the application memory. They are similar to attributes, but the can only be used in the method body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are arithmetic operators?

A

they can execute mathematical functions

  • ++ (increment, increases a variable by the value 1)
    • (arithmetic addition)
    • (arithmetic subtraction)
  • · (arithmetic multiplication)
  • / (arithmetic division)
  • % (Remainder/modulus, calculates the remainder of the arithmetic division)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are logical operators?

A

These are operators used to run logical functions, they return a value of true or false and can only result in a boolean.

  • ! (logical complement/NOT, changes the truth value of the operand)
  • && (logical AND, returns true when both operators are true)
  • || (logical OR, returns true if one of the two operands is true)
  • ^ (exclusive OR, returns true if one operand is true and one operand is false)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are relational operators?

A

They compare expressions against each other and return boolean as the result type.

  • == (equal, returns true if the values of the operands are equal)
  • != (non-equal, returns true if the values of the operands are not equal)
  • < (Less than, returns true if the value of the operand one the left is less than the value on the right)
  • <= (Less than or equal to, returns true if the the value on the left is less than or equal to the value on the right)
  • > (Greater than, returns true if the value of the operand on the left is greater than the value of the operand on the right.)
  • > = (Greater than or equal to, returns true if the value of the operand on the left is greater than or equal to the value of the operand on the right.)
  • instanceof (type comparison, returns true if the data types of both operands match)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a concatenation of strings (operator)?

A

It is a function of the data type String that creates a new string from two existing strings through simply stringing them together.

    • (joining strings, joining multiple strings to form a new string)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are control structures?

A

They are elements of a programming language for conditional or nested execution of statements.

It enables controlled repeat execution of statements. The most important control structures in Java are:

  • conditional branches (if-else)
  • loops (for, while, do-while)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain conditional branches in more detail.

A
  • if-else statement (checks a condition and tests where the program continues, either the if or the else code block is executed)
  • expanded if-else statement (not just one condition is tested before the else block is processed, but multiple, mutually exclusive conditions)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain loops in more detail.

A

Loops allow sequential execution of the statements, the number of iterations of the loop is determined by the satisfaction of a loop condition.

  • while loop (if loop condition is true, executes the statements in the loop, the condition is tested again etc.)
  • do-while loop (statements in the loop are always executed at least once, after that the condition is tested)
  • for loop (initialization, test the condition, evaluates condition, if true executes all statements, then executes the statement in the loop increment)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a package?

A

It is an element used for structuring the java classes of a development project. Java classes are assigned to packages. Packages can themselves also contain packages.
The first line of the source text in a Java class always contains the package in which the class is located. The class names must be unique within a package.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain the visibility modifier.

A
  • element is visible to all classes in the program
    ~~~
    public class Order {}
    public voic calculateSum () {}
    ~~~
  • element is only visibile in the same package
    ~~~
    class Order {}
    voic calculate Sum() {}
    ~~~
  • element is only visible in the same package or derived classes
    ~~~
    protected void calculateSum() {}
    protected int quantityProduct;
    ~~~
  • element is only visible for elements of the same class
    ~~~
    private void calculateSum() {}
    private int quantityProduct;
    ~~~
How well did you know this?
1
Not at all
2
3
4
5
Perfectly