Java Methods: Organized Code with Public Void Greet

Java Learning Journey – Day 9 Today I learned an important concept in Java — Methods. A method is a block of code that performs a specific task. It helps make code organized, reusable, and easier to maintain. 🔹 Basic Structure of a Method public void greet() { System.out.println("Hello!"); } Here: • public → Access modifier • void → Return type • greet() → Method name • {} → Method body 🔹 Example of a Method with Parameters public int add(int a, int b) { return a + b; } 🔹 Calling a Method greet(); int sum = add(5, 10); 💡 Key Learning: Methods allow developers to break programs into smaller reusable pieces, making programs cleaner and easier to manage. Continuing my journey to become a better Java developer step by step. If you're also learning Java or working in development, let’s connect and grow together. 🤝 #Java #JavaDeveloper #Programming #CodingJourney #SoftwareDevelopment #LearnJava #Hariom #HariomKumar

  • “Java Learning Journey – Day 9: Understanding Java Methods.” The image uses bold colors and a clean structured layout to explain the concept of methods in Java.

The top section defines a method as a block of code that performs a specific task and helps organize and reuse code. It shows the basic method structure with elements like access modifier (public), return type (void), method name, parentheses (), and parameters. A simple example method is displayed:
public void methodName() { System.out.println("Hello!"); }.

Another section explains defining methods, including components such as visibility, return type, and parameters, with an example method:
public int add(int a, int b) { return a + b; }.

The infographic also demonstrates calling methods with examples like greet();, int sum = add(5, 10);, and String msg = getMessage();.

Visual elements such as robot icons, a calculator, notebook, and stationery create a study environment, highlighting that methods help make Java code.

To view or add a comment, sign in

Explore content categories