- JAVA OVERVIEW
- History of Java
- Tools you will need for java
- Java Environment Setup
- Popular Java Editors
- Java Basic Syntax/First-Program
- Java Identifiers
- Java Modifiers
- Java Arrays
- Java Enums
- Java Keywords
- Comments in Java
- Java - Objects and Classes
- Objects in Java
- Classes in Java
- Constructors
- Creating an Object
- Accessing Instance Variables and Methods
- Source file declaration rules
- Java Package
- Simple Case Study
- Basic Data Types
- Primitive Data Types
- Reference Data Types
- Java Literals
- Variable Types
- Local variables
- Instance variables
- Class or static variables
- Java Access Modifiers
- What is OOPS
- Inheritance concept
- Encapsulation
- What is Polymorphism
- Method Overloading
- Method Overriding
- Abstraction in Java
- Abstract class
- Interface in Java
- Method overloading in Java:
- What is Annonymous object?
- Java 8
What is the local variables?
Local variables are declared in methods, constructors, or blocks.
Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor or block.
Access modifiers cannot be used for local variables.
Local variables are visible only within the declared method, constructor or block.
Local variables are implemented at stack level internally.
There is no default value for local variables so local variables should be declared and an initial value should be assigned before the first use.
Example:Here, age is a local variable. This is defined inside pupAge() method and its scope is limited to this method only.:-
public class Test
{
public void pupAge()
{
int age = 0;
age = age + 7;
System.out.println("Puppy age is : " + age);
}
public static void main(String args[])
{
Test test = new Test();
test.pupAge();
}
}
This would produce following result: Puppy age is: 7
Example:Following example uses age without initializing it, so it would give an error at the time of compilation.:-
public class Test
{
public void pupAge()
{
int age;
age = age + 7;
System.out.println("Puppy age is : " + age);
}
public static void main(String args[])
{
Test test = new Test();
test.pupAge();
}
}
This would produce following error while compiling it:
Test.java:4:variable number might not have been initialized age = age + 7;
^1 error