java notes
java notes
{
public static void main(String args[])
{
System.out.println("Hello Java");
}
}
-- here Hello Java will be printed/ result as a output of the program execution in
the function.
/*
**Java Programming: A Symphony of Syntax**
---
"Once upon a runtime, in the kingdom of JVM, there thrived a young method named
`main`. Borne of the `public` family, it bore the sacred keyword `static`, ensuring
its omnipresence without the invocation of an object. The `void` inheritance
rendered it selfless, returning nothing but executing everything.
Within the walls of curly braces `{}`, `main` had a singular mission: to guide the
bytecode to its destiny. Its first commandment was a humble declaration:
```java
System.out.println("Hello, World!");
```
---
In Java, every object is a citizen of a vast universe, created and governed by the
benevolent class structures. A class is not merely a blueprint; it is a story
waiting to unfold. Consider the character `Hero`, a valiant protagonist who roams
the realms of variables and methods:
```java
class Hero {
String name;
int strength;
void displayHero() {
System.out.println("Behold, " + name + " with strength " + strength + "!");
}
}
```
Here, `String name` and `int strength` are the attributes defining Hero’s essence,
while `void displayHero()` is the bard, narrating tales of the hero’s might.
---
The plot thickens with the introduction of control structures, the guiding forces
shaping the storyline of any Java program. The `if` statements are the forks in the
road, the `while` loops the endless mazes, and the `for` loops the rhythmic marches
of repetition. Let us eavesdrop on their dialogue:
```java
if (strength > 10) {
System.out.println(name + " is a mighty warrior!");
} else {
System.out.println(name + " must train harder.");
}
```
This snippet is not mere logic; it is a philosophical musing. "To be strong or not
to be strong," ponders our hero. And as the loops weave their patterns, they
reflect life’s endless cycles:
```java
for (int i = 0; i < 3; i++) {
System.out.println(name + " gains experience.");
}
```
---
Yet, Java's true magic lies in its ability to forge connections through `methods`,
`interfaces`, and `inheritance`. These constructs create a network where objects
converse, collaborate, and evolve. It's a society where classes inherit wisdom
(`extends`), form alliances (`implements`), and adhere to protocols (`interfaces`).
*/