Programming Structures in Java - I (B)
Programming Structures in Java - I (B)
with Java
Programming
Structures in
Java
Rita Nagar
Assistant Professor, CSE Department MPGI
Outlines
1. Comments
2. Data types
3. Variables
4. Operators
5. Control Flow
6. Arrays & String
• For example
• Literals
• Keywords
• Variables
• Symbolic Constants
Literals
• Null literal: Used to represent a reference that does not refer to any object,
represented by the keyword null.
Keywords
else, while, for, switch, case, break, continue, return, and static,
among others.
Variables
• A variable is a container which holds the value while the Java
program is executed. A variable is assigned with a data type.
• Variable is a name of memory location.
Three types of variables in java
Local variable
Instance variable
Static variable
1) Local Variables
Local Variables are a variable that are declared inside the body of
a method.
2) Instance Variables
Instance variables are defined without the STATIC keyword .They
are defined Outside a method declaration. They are Object
specific and are known as instance variables.
3) Static Variables
Static variables are initialized only once, at the start of the
program execution. These variables should be initialized first,
before the initialization of any instance variables.
symbolic constant
Scope
Method
Block Scope
scope
Method Scope
class Test
{
public static void main(String args[])
{
for (int x = 0; x < 4; x++)
{
System.out.println(x);
}
Type conversion
Widening Narrowing
Conversion
(Automatic) Explicit Conversion
Widening Conversion (Automatic)
The numeric data types are compatible with each other but no
automatic conversion is supported from numeric type to char or
Boolean. Also, char and Boolean are not compatible with each
other.
Explicit Conversion