Expressions, Statements, Blocks, and Branches Flashcards
Expression
Is a combination of one or more explicit values, constants, variables, operators, and functions that the programming language interprets and computes to produce another value.
Statements
Is a syntactic unit of an imperative programming language that expresses some action to be carried out. Statements in Java are terminated by a semi-colon ( ; ) and may contain expressions.
Blocks
Block is a group of statements that needs to be executed as a single unit.
In Java, blocks are identified by curly-braces { }.
Methods
Create a reusable block of code.
Methods are defined by a Method Signature.
Method Signature
Consists of an accessor + return_data_type + name + ( parameters )
Accessor
A keyword, like public, private or protected, that identifies who can use the method
Return type
A Data Type, (int, double, String), that identifies the output - what type of data the method will return.
Name
A descriptive name that can be used to call the method, causing the code in it’s code block to execute
Parameters
A list of variables, contained in ( ) that must be populated when calling the method.
Parts of a Method
Method Signature - Code Block - Return statement
Code Block
Code to execute when the method is used. Defined by { } following the method signature.
Return statement
Statement of code that tells the method what value to return. This value must be the same data type as a methods return type.
Boolean Expression
An expression that evaluates to a single boolean value (true or false). Commonly used to conditionally decide what code to execute.
Comparison Operators
Used to compare two values. Can only be used with int, long, short, byte, boolean, double, and float data types. Cannot be used with String.
Logical Operators
Combines two or more boolean expressions, such that they evaluate to a single value. In natural language these are represented by AND, OR and NOT.