It's Been a Long Time: A Fresh Update


Why Stopped
Due to Emergency now life back on track and here i am :) .
What Studied in Previous days.
That’s Right never stopped learning. Learned many new things in Java.
What i Learned :
functions : (what is it and how its helps to code).
So, function (also known as methods) are the Instructions that are grouped together. simple. It is a container for logic, allowing you to group related operations into one place.
A method can:
Take inputs (called parameters).
Perform some actions.
Return a value (or not, if it's a void method).
Why Are Methods Important in Java?
There are many reasons to use This:
Resuability.
Modularity.
Maintainability.
DRY (Do Not Repeat Yourself) Very Important. (you don’t need to write same code again and again)
Types of Methods in Java.
Predefined Methods.
User defined Methods.
How to Write it.
This is the Syntax of it.
returnType methodName(parameters) {
// method body
}
Explanation:
returnType :
Here returnType means which type of data you want from the function when it Ends.
methodName :
method name meand the name that you want to give the method.
parameters :
It means Function takes a input that it function on. means it also need some Data that upon it process function. parameter is that thing.
Working method (function):
public class Main {
public static void greet() {
System.out.println("Hello, World!");
}
public static void main(String[] args) {
greet();
}
}
Calling :
you also have to call the function to run it.
Here greet(); is the calling of the function and it your function takes the parameter in that you call it something like this greet(“parameter“);
What’s Next ?
Arrays.
Introduction
At first, I had no idea what they were, but after a bit of practice, they started to make sense. In this blog post, I’ll explain arrays the way I understand them, with simple examples. If you’re also just starting out, I hope this helps!
What is an Array?
Nothing Just a Collection of similar Data types. It helps you store multiple values in a single place.
How to create a new Array:
int[] array = new int[5]; //this is creating the new array which is size 5 and empty
// in simple we just reserve the space in memory of a size 5 array.
int[] array \=> this creates at compile time of program.
new int[5] \=> this Happen on the Runtime dynamically. Create object in Heap memory.
Imagine you want to store the names of fruits. Without an array, you'd have to do this:
String fruit1 = "Apple";
String fruit2 = "Banana";
String fruit3 = "Cherry";
But with an array, you can store all of them together:
String[] fruits = {"Apple", "Banana", "Cherry"};
Accessing Array Elements:
System.out.println(fruits[0]); // Output: Apple
System.out.println(fruits[1]); // Output: Banana
System.out.println(fruits[2]); // Output: Cherry
Changing and Adding Values:
fruits[1] = "Orange";
System.out.println(fruits[1]); // Output: Orange
That’s all for the new start will try to upload as regular as possible.
Peace✌️.
Subscribe to my newsletter
Read articles from Bhavesh Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Bhavesh Sharma
Bhavesh Sharma
i am currently starts to learning new things as you can check my progress in blogs.