- Declaration (Declarisation) ✓✓ Declaration is the process of introducing a variable in a program by specifying its data type and name. At this point, memory is reserved for the variable, but it does not yet have a value (unless given a default).
📌 Syntax:
datatype variableName;
📌 Example:
int age; // declaration
String name; // declaration
Here, age is declared as an integer, name as a string.
- Initialization ✓✓ Initialization means assigning an initial value to a declared variable. ✓✓ It can happen at the time of declaration or later in the code.
📌 Syntax:
datatype variableName = value;
📌 Example:
int age = 20; // declaration + initialization
String name = "Arun"; // initialized with value
Here, age is initialized with 20, name with "Arun".
Program Execution Life Cycle in Java
Write the Code
✓✓ You write the Java program in a .java file using an editor or IDE.
**Example: Hello.javaCompile the Code
✓✓ The Java compiler (javac) compiles the .java file into bytecode.
Output : A . class file is created.
**Example: Hello.class
Class Loader
✓✓ When you run the program, the Class Loader loads the .class file into JVM memory.
✓✓ It handles loading, linking, and initialization of classes.Bytecode Verification
✓✓ JVM’s Bytecode Verifier checks the .class file for security and correctness (e.g., no illegal code, stack overflow issuesJVM Execution
✓✓ The Interpreter reads bytecode instructions one by one and executes them.
✓✓The JIT Compiler (Just-In-Time) may also compile frequently used bytecode into native machine code for better performance.Execution in OS
✓✓ The translated code finally executes as native instructions on the operating system and hardware.Program Output
✓✓The program produces the result/output on the console.
What is methods and types of methods in java ?
✓ A method in Java is a block of code that performs a specific task, executes when it is called, and can return a value or be void.
👉 In simple words: A method is like a function in other languages, used for code reusability and modularity.
***Syntax of a Method
returnType methodName(parameters) {
// method body
// statements
return value; // if returnType is not void
}
Types of Methods in Java
- Built-in Methods (Predefined methods) ✓✓ Provided by Java libraries (inbuilt).
- User-defined Methods ✓✓ Created by the programmer to perform custom tasks.
Rules for identifiers in java
✓ In Java, an identifier is the name you give to classes, methods, variables, interfaces, etc.
✅ Rules for Identifiers in Java:
- Allowed characters Letters (A-Z, a-z) Digits (0-9) Underscore (_) Dollar sign ($) 👉 Example: myVar, student_name, $_count
Must not begin with a digit
Invalid - 1number
Valid - number1No special characters or spaces (except _ and $)
Invalid - my-name, first name
Valid - myName, first_nameCannot be a reserved keyword (like int, class, static, if)
Invalid: class
Valid: classNameCase-sensitive
Student and student are different identifiersNo length limit:
✓ You can make identifiers very long, but short and meaningful names are recommended.Convention rules (not enforced by compiler but recommended):
✓ Variables & methods → start with a lowercase letter (studentAge, calculateSum())
✓ Classes & interfaces → start with an uppercase letter (Student, CarDetails)
✓ Constants → written in UPPERCASE with underscores (MAX_VALUE, PI)
**Example Program
class StudentDetails {
int studentAge;
String studentName;
void displayInfo()
{
System.out.println(studentName + " is " + studentAge + " years old.");
}
}
- What is Datatypes in java ?
✓ A data type in Java is a classification that specifies which type of value a variable can hold and what kind of operations can be performed on it.
In simple words:
👉 Data type tells the compiler and JVM what kind of data (numbers, characters, text, true/false, etc.) is stored in a variable.
**Example Program
int age = 25; // int → stores integer values
double salary = 4500.50; // double → stores decimal values
char grade = 'A'; // char → stores a single character
boolean flag = true; // boolean → stores true/false
Types of datatypes
- Primitive Data Types
- Non primitive Data Types
Top comments (0)