Introduction
In today’s session, we continued our journey with Java programming and started working with Eclipse IDE to organize and write our code. This was my first experience in creating a proper project structure in Eclipse, and it helped me understand how Java programs are built step by step.
What We Learned
Classes:
A class in Java acts as a blueprint for creating objects. It defines the structure of a program by containing both variables and methods. Every Java program begins with at least one class.Variables and Their Types:
Variables are named storage containers used to hold data. We learned about several types:
int – for whole numbers
double – for decimal numbers
char – for single characters
boolean – for values that are either true or false
String – for text
There are also two important categories of variables in Java:
Instance Variable: Declared inside a class but outside any method. Its value is unique for each object.
Local Variable: Declared inside a method and can only be used within that method.
Example:
public class Student {
// Instance variable
String name = "John";
public void studentdetails() {
// Local variable
int age = 18;
}
}
Methods and Their Types:
Method is a block of code which executes a specific task.
Types of methods:
- Methods with return type: Return a specific value.
- Methods without return type: Declared with void keyword and return nothing.
- Methods with arguments: Accept inputs.
- Methods without arguments: Do not take any inputs.
Practical Work in Eclipse
During the practical session, we created a new project in Eclipse. Inside the src folder, we added a new package to organize our work. Then, within the package, we created a new class that contained the method. This allowed us to test simple programs and get familiar with Eclipse’s project structure.
Thoughts
This session gave me a clear understanding of how classes, variables, and methods come together to form the foundation of Java programming. I am looking forward to exploring more features of Java and building more complex programs in the future.
Top comments (0)