Declarations, Invocations and Executions

Java 8 min min read Updated: Mar 31, 2026 Beginner
Declarations, Invocations and Executions
Beginner Topic 14 of 25

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.

Key Concept: Declaration means introducing a program element, invocation means calling or using it, and execution means the actual running of code by the JVM.

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.

java int age; String name; double salary;

In the above examples:

  • int, String, and double are data types
  • age, name, and salary are 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.

java int add(int a, int b) { return a + b; }

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.

java class Student { Student() { System.out.println("Constructor declared"); } }

Here, Student() is a constructor declaration.

Class Declaration

A class declaration defines the blueprint of objects.

java class Car { String color; void start() { System.out.println("Car started"); } }

In this example:

  • Car is the class declaration
  • color is an instance variable declaration
  • start() is a method declaration

Object Declaration

In Java, object declaration means creating a reference variable that can point to an object.

java Student s;

Here:

  • Student is the class type
  • s is 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

java int age;

Initialization

java age = 25;

Declaration + Initialization Together

java int age = 25;

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

java class Demo { void show() { System.out.println("Method invoked"); } } public class Main { public static void main(String[] args) { Demo d = new Demo(); d.show(); } }

Here:

  • show() is declared inside class Demo
  • d.show() is method invocation

Constructor Invocation

Constructor invocation happens when an object is created using the new keyword.

java Student s = new Student();

In this line:

  • Student s is reference declaration
  • new Student() creates the object
  • Student() constructor is invoked

Static Method Invocation

Static methods are invoked using the class name.

java class Demo { static void show() { System.out.println("Static method invoked"); } } public class Main { public static void main(String[] args) { Demo.show(); } }

Invocation with Parameters

A method can be invoked with arguments.

java class Calculator { int add(int a, int b) { return a + b; } } public class Main { public static void main(String[] args) { Calculator c = new Calculator(); int result = c.add(10, 20); System.out.println(result); } }

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:

java public static void main(String[] args)

This is the entry point of a Java application.

Program Execution Flow

Let us understand the complete flow using a simple example.

java class Demo { void show() { System.out.println("Inside show method"); } } public class Main { public static void main(String[] args) { System.out.println("Program starts"); Demo d = new Demo(); d.show(); System.out.println("Program ends"); } }

Execution Flow

  1. JVM starts execution from main()
  2. "Program starts" is printed
  3. Object d is created
  4. Method show() is invoked
  5. "Inside show method" is printed
  6. Control returns to main()
  7. "Program ends" is printed

Declaration, Invocation, and Execution Together

Let us connect all three ideas in one example.

java class Student { String name; // declaration Student(String name) { // constructor declaration this.name = name; } void display() { // method declaration System.out.println("Name: " + name); } } public class Main { public static void main(String[] args) { Student s = new Student("Amit"); // object declaration + constructor invocation s.display(); // method invocation } }

Understanding This Example

  • String name; → variable declaration
  • Student(String name) → constructor declaration
  • void display() → method declaration
  • Student s → object reference declaration
  • new Student("Amit") → constructor invocation
  • s.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.

java class Demo { static { System.out.println("Static block executed"); } static void show() { System.out.println("Static method executed"); } } public class Main { public static void main(String[] args) { Demo.show(); } }

Execution Flow

  • Class Demo loads 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.

java class Demo { int x = 10; void show() { System.out.println("x = " + x); } } public class Main { public static void main(String[] args) { Demo d = new Demo(); d.show(); } }

Here, object creation is necessary before method execution.

Nested Method Invocation

One method can invoke another method. This creates a chain of execution.

java class Demo { void first() { System.out.println("Inside first"); second(); } void second() { System.out.println("Inside second"); } } public class Main { public static void main(String[] args) { Demo d = new Demo(); d.first(); } }

Execution Flow

  1. main() starts
  2. first() is invoked
  3. "Inside first" is printed
  4. second() is invoked from inside first()
  5. "Inside second" is printed
  6. Control returns back

Recursive Invocation

A method can also invoke itself. This is called recursion.

java class Demo { void countDown(int n) { if (n == 0) return; System.out.println(n); countDown(n - 1); } }

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 new keyword
  • 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.

Quick Summary: Declaration introduces a Java element, invocation calls it, and execution is the actual running of the code by the JVM.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators