• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Start selling Create your account
Document preview thumbnail
Preview 2 out of 12 pages
Summary

Summary Basic OOP Java Part 1: Syntax, Methods, Variables & Memory Allocation

Document preview thumbnail
Preview 2 out of 12 pages

Clear, high-yield study notes for Object-Oriented Programming with Java. Includes detailed diagrams, stack/heap memory visualizations, code breakdowns, and execution flow walkthroughs. Key Topics Covered in this Document: ● Structure of a Java Class & Main Method Execution ● Single-Threaded Program Flow & Method Calling Mechanics ● Java Memory Allocation: Stack Memory vs. Heap Memory ● The 4 Variable Types: Local, Block, Static, and Instance (Non-static) ● Variables Variable Scoping, Lifetime, and Redeclaration Rules ● Static Members vs. Instance Members (Static Area Mechanics)

Content preview

Structure of a Class

class class_name {
output input

modifiers return_type method_name (parameter_list) {


...
class
method
{...} block

data_type name = value; variable

}

}

Main Method
When the JVM starts running, it looks for the class you give it at the command line. Then it starts looking
for a specially-written method(main method) that looks exactly like:

public static void main (String[] args) { (shortcut: psvm → tab)
// your code goes here
}

Next, the JVM runs everything between the curly braces { } of your main method.
★ Every Java application has to have at least one class, and at least one main method (not one main per
class; just one main per application).


Method Calling
class A {
public static void main (String[] args) {
System.out.println("Hello! main method"); (shortcut: sout→ tab)
// A.method1(); (using the class flag)

method1();
} method calling

public static void method1 () {
System.out.println("Hello! method 1");
}
}

Only static methods can be called without creating an object, and this can be done in two ways:
• Directly within the same class: If the method is static and belongs to the same class where it's
being called, you can simply use the method name (e.g. method1();).

• Using the class name (class flag): If you are calling a static method from outside the class or for
explicit clarity, you can use the class flag followed by the method name (e.g. A.method1();).




nabiii_11 Page 1

, Single-threaded Execution Flow OUTPUT:
1. Hello! main method
class A { Hello! method 1
2. Hello! main method
public static void main (String[] args) {

System.out.println("1. Hello! main method");

A.method1();

System.out.println("2. Hello! main method");

}


public static void method1 () {

System.out.println("Hello! method 1");

}

}

One Thread, One Path
The program starts in the main method, proceeds through its statements, calls method1, executes method1,
and then returns to finish main. This is a linear, uninterrupted flow within a single thread.

method1 does not run in parallel with main; it runs within the same thread, temporarily interrupting the
execution of main.

Each line of code is executed strictly in order. System.out.println("1. Hello! main method"); must
finish before A.method1(); is called, and A.method1(); must complete before
System.out.println("2. Hello! main method"); can execute.





nabiii_11 Page 2

Document information

Study
Unknown
Uploaded on
September 29, 2026
Number of pages
12
Written in
2024/2025
Type
Summary
£8.57

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
1
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions