Java Basics for Beginners

Share

Java Basics for Beginners

 
1. What is Java?

Java, a high-level programming language, was conceived by Sun Microsystems (now a part of Oracle Corporation) in 1995. Its platform-independence makes it unique – write your Java code on one platform, and it can run anywhere that has Java Runtime Environment (JRE).

2. The structure of a Java Program:

Here’s an elementary Java program:

java
public class Greeting {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

In this code, Greeting is a class. The main component of a Java application is its class. The main() method, present inside the class, serves as the program’s entry point.

3. Data Types and Variables:

Java comprises several data types:

  • int for whole numbers (e.g., 7, 42, 0)
  • double for numbers with decimals (e.g., 3.14, -0.99)
  • char for individual characters (e.g., ‘b’, ‘Z’)
  • boolean for binary values (true/false)
  • String for a chain of characters (e.g., “Good Morning!”)

You can use variables to hold values:

java
int myAge = 21;
String myName = "John Doe";

4. Operators in Java:

Java includes various types of operators: arithmetic (+, -, *, /, %), comparison (<, >, <=, >=, ==, !=), and logical (&&, ||, !).

5. Control Flow Statements:

Java provides several control flow structures like if conditions, for and while loops. For example:

java

if (myAge > 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}

for (int i = 1; i <= 5; i++) {
System.out.println(i);
}

 

while (myAge < 25) {
System.out.println(myAge);
myAge++;
}

6. Arrays in Java:

An array lets you store multiple values in a single variable. Here’s the way to declare an array:

java
double[] myGrades = new double[5]; // A double array of size 5

7. Methods:

Methods (or functions) in Java are blocks of code designed to perform specific tasks.

java
public double calculateAverage(double num1, double num2) {
return (num1 + num2) / 2;
}

8. Object-Oriented Programming (OOP):

Java leverages object-oriented programming principles, enabling it to depict concepts as “objects” that pair data fields (attributes) with procedures known as methods.

You use classes to create objects in OOP. A class is like a template for creating objects. Here’s a simple class definition:

java

public class Cat {
// Attributes or fields
String breed;
String color;

 

// Behavior or method
void meow() {
System.out.println("Meow Meow");
}
}

The foundational OOP concepts in Java are:

  • Inheritance: A class can adopt properties (fields and methods) from another class.
  • Encapsulation: Binds together code and the data it manipulates into a single unit, such as a class.
  • Polymorphism: Allows methods to perform varied tasks based on the object they interact with.
  • Abstraction: Reveals only necessary information to the user, hiding internal complexity.

Demo Day 1 Video:

 
You can find more information about Java in this Java Docs Link

 

Conclusion:

Unogeeks is the No.1 Training Institute for Java Training. Anyone Disagree? Please drop in a comment

You can check out our other latest blogs on Java Training here – Java Blogs

You can check out our Best in Class Java Training details here – Java Training

💬 Follow & Connect with us:

———————————-

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Mail us at: info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook: https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks


Share

Leave a Reply

Your email address will not be published. Required fields are marked *