Declarations, Invocations and Executions
In Java, writing code is not only about knowing syntax. A programmer must also understand how different elements are declared, how they are invoked, and how they finally execute at runtime. These three ideas—declaration, invocation, and execution—form the foundation of program flow.
A Java program contains classes, variables, methods, constructors, and objects. First, these are declared in the program. Then, some of them are invoked or called. Finally, the Java Virtual Machine executes them according to Java rules and control flow.
What is Declaration in Java?
Declaration means defining or introducing a programming element so that Java knows about its existence. A declaration gives a name, type, and sometimes structure to a class, variable, method, or constructor.
Common things that can be declared in Java are:
- variables
- methods
- constructors
- classes
- objects
Variable Declaration
Variable declaration means specifying the type and name of a variable.
In the above examples:
int,String, anddoubleare data typesage,name, andsalaryare variable names
At this stage, the variables are declared, but they may not yet have usable values.
Method Declaration
Method declaration means defining a method with its return type, name, and parameters.
This method declaration tells Java:
- the method returns an
int - its name is
add - it accepts two integer parameters
Constructor Declaration
Constructor declaration means defining a constructor that will initialize an object.
Here, Student() is a constructor declaration.
Class Declaration
A class declaration defines the blueprint of objects.
In this example:
Caris the class declarationcoloris an instance variable declarationstart()is a method declaration
Object Declaration
In Java, object declaration means creating a reference variable that can point to an object.
Here:
Studentis the class typesis the reference variable
At this point, the object is only declared, not yet created.
Difference Between Declaration and Initialization
Beginners often confuse declaration with initialization. These are different steps.
Only Declaration
Initialization
Declaration + Initialization Together
What is Invocation in Java?
Invocation means calling or using something that has already been declared. In Java, invocation commonly happens with:
- methods
- constructors
- objects through method calls
In simple words, declaration defines it, invocation uses it.
Method Invocation
Method invocation means calling a method so that its code runs.
Example
Here:
show()is declared inside classDemod.show()is method invocation
Constructor Invocation
Constructor invocation happens when an object is created using the new keyword.
In this line:
Student sis reference declarationnew Student()creates the objectStudent()constructor is invoked
Static Method Invocation
Static methods are invoked using the class name.
Invocation with Parameters
A method can be invoked with arguments.
Here, the method add() is invoked with 10 and 20.
What is Execution in Java?
Execution means the actual running of instructions by the JVM. Once a method or constructor is invoked, Java executes its statements line by line according to program flow.
Execution begins from:
This is the entry point of a Java application.
Program Execution Flow
Let us understand the complete flow using a simple example.
Execution Flow
- JVM starts execution from
main() "Program starts"is printed- Object
dis created - Method
show()is invoked "Inside show method"is printed- Control returns to
main() "Program ends"is printed
Declaration, Invocation, and Execution Together
Let us connect all three ideas in one example.
Understanding This Example
String name;→ variable declarationStudent(String name)→ constructor declarationvoid display()→ method declarationStudent s→ object reference declarationnew Student("Amit")→ constructor invocations.display()→ method invocation- Printing output → execution result
Method Declaration vs Method Invocation
| Point | Method Declaration | Method Invocation |
|---|---|---|
| Meaning | Defining the method | Calling the method |
| Contains body | Yes | No |
| Example | void show() { ... } |
show(); |
| When used | During class design | During execution flow |
Constructor Declaration vs Constructor Invocation
| Point | Constructor Declaration | Constructor Invocation |
|---|---|---|
| Meaning | Defining the constructor | Calling it during object creation |
| Example | Student() { } |
new Student() |
| Execution | Not executed by itself | Runs during object creation |
Execution of Static Members
Static members have a different execution behavior because they belong to the class, not the object.
Execution Flow
- Class
Demoloads when referenced - Static block executes first
- Then static method
show()executes
Execution of Instance Members
Instance members require object creation before they can be invoked.
Here, object creation is necessary before method execution.
Nested Method Invocation
One method can invoke another method. This creates a chain of execution.
Execution Flow
main()startsfirst()is invoked"Inside first"is printedsecond()is invoked from insidefirst()"Inside second"is printed- Control returns back
Recursive Invocation
A method can also invoke itself. This is called recursion.
Here, the method declaration is only once, but invocation happens repeatedly.
Common Beginner Mistakes
- Confusing declaration with initialization
- Thinking declaring a method means it automatically runs
- Thinking constructor declaration creates an object by itself
- Forgetting that execution starts from
main() - Confusing static method invocation with instance method invocation
Best Practices
- Use clear and meaningful method and variable names in declarations
- Understand that declared members do nothing until invoked or accessed
- Keep execution flow simple and readable
- Use proper indentation to understand nested invocation clearly
- Differentiate object creation from reference declaration
Interview-Oriented Points
- Declaration means defining a class, variable, method, or constructor
- Invocation means calling a method or constructor
- Execution means actual running of statements by JVM
- Program execution starts from
main() - Constructor invocation happens through the
newkeyword - Static members can be invoked using class name
- Instance members require object creation
Conclusion
Declarations, invocations, and executions are three closely connected ideas in Java. A declaration defines a program element, invocation uses it, and execution runs it through the JVM.
Once this flow is understood clearly, Java programs become easier to read, debug, and design. This concept also forms the base for understanding method calls, constructor flow, object creation, recursion, and execution control.

