Java Virtual Machine (JVM)
Published by: Anil K. Panta
Java Virtual Machine (JVM)
Converts compiled byte code into machine code.
Allows Java programs to run on any platform (Write once, run anywhere).
Byte code is OS-independent.
Parts of a Java Program:
Documentation Section:
Comments about the program, author, date, purpose, etc.
Package Declaration:
Organizes classes and avoids name conflicts.
Example: package com.example.app;
Import Statements:
Imports external classes.
Example: import java.util.Scanner;
Class Definition:
Contains class name, variables, and methods.
Example: public class Rectangle { ... }
Variables:
Class/Static Variables – shared by all objects.
Instance/Object Variables – unique to each object.
Local Variables – declared inside methods.
Main Method:
Entry point of every Java program.
Syntax: public static void main(String[] args) { ... }
Methods/Behaviors:
Define actions the object can perform.
Syntax: public int calculateArea(int width, int height) { ... }
Naming Conventions in Java
Class Names: PascalCase → MyClass, StudentRecord
Interfaces: PascalCase, often ends with Interface
Methods: camelCase, verbs → getName(), calculateTotal()
Variables: camelCase, nouns → userName, price
Constants: UPPERCASE_WITH_UNDERSCORES → PI, MAX_SIZE