View on GitHub

reading-notes

Reading notes taken while attending Code Fellows classes.

Java Basics

Index

Home
Variables
Operators
Expressions, Statments and Blocks
Control Flow Statments
What Does It Mean To Compile Code
Explain Like I’m Five
Questions

Variables

The Java programming language defines the following kinds of variables:

Operators

postfix expr++ expr–
unary ++expr –expr +expr -expr ~ !
multiplicative * / %
additive + -
shift « » »>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= «= »= »>=

Expressions, Statements, and Blocks

Expressions

An expression is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value.

Examples:

The data type of the value returned by an expression depends on the elements used in the expression.

Statements

Statements are roughly equivalent to sentences in natural languages. A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon (;).

// assignment statement
aValue = 8933.234;
// increment statement
aValue++;
// method invocation statement
System.out.println("Hello World!");
// object creation statement
Bicycle myBike = new Bicycle();

Blocks

A block is a group of zero or more statements between balanced braces and can be used anywhere a single statement is allowed.

class BlockDemo {
     public static void main(String[] args) {
          boolean condition = true;
          if (condition) { // begin block 1
               System.out.println("Condition is true.");
          } // end block one
          else { // begin block 2
               System.out.println("Condition is false.");
          } // end block 2
     }
}

Control Flow Statements

The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code. This section describes the decision-making statements (if-then, if-then-else, switch), the looping statements (for, while, do-while), and the branching statements (break, continue, return) supported by the Java programming language.

What Does It Mean To Compile Code

XKCD

Explain Like I’m Five

ELIFCompile

Questions

  1. What does “strong typed” mean?

    • Strong typed languages require data to be explicitly declared and will not allow implied but not declared data types.
  2. Explain to a non-technical friend the difference in how compilation works in Java and JavaScript.

    • Java is a compiled programming language. Meaning that written code is handled by another program that translates it to machine language (0’s and 1’s). Think of Java acting as a way to better read and write code for humans and the compiler translates that to a non english speaking entity (a computer processor). Compiled languages are typically faster than interpred languages.

    • JavaScript is an interpreted language. A program called an interpreter reads line by line and executes the code it reads immediately, never handing it down to the processor in machine language.

Back To Top