Week 3 - Lecture 5 and 6 Java Programming Basics Part 2
Week 3 - Lecture 5 and 6 Java Programming Basics Part 2
❑ Variables
❑ Scope and Lifetime of variable
❑ Constants
❑ Arithmetic Expression
❑ Java Classes
❑ Control Structure
Variables
Variable is a named location where data can be stored. It is a location
in computer’s memory with a specific address, where a value can be
stored and retrieved when required.
A variable is assigned with a data type.
You can use this variable only within that method and the other
methods in the class aren't even aware that the variable exists.
Example:
final int var = 100;
final double pi= 3.14159;
private static final double pi= 3.14159;
Arithmetic Expression Evaluation
To evaluate an arithmetic expression two concepts needs to be
understood
◦Operator Precedence
◦ Operator precedence controls the order in which operations are performed
◦Operator Associativity
◦ The associativity of an operator specifies the order in which operations of
the same precedence are performed
Operator Precedence and Associativity
Operators Precedence and Associativity for Java is following
float f=65/10+38/10;
System.out.println(f);
Task
List down Java Compile –time and Run-time errors.