
Are you aware of the Java language basics or not? Java is a popular high-level object-oriented, platform independent programming language developed by Sun Microsystems in 1991. In 1995, the Sun Microsystem changed the name of Sun to Java. In 2009, further, the Oracle Corporation took over the Sun Microsystem.
Java developers are always in demand as a programming language as it enables programmers to write code that can run on multiple devices having Java Virtual Machine (JVM). There are many features of Java programming language such as strong typing, automatic garbage collection, standard libraries, and other features of Java that make it my favorite.
| public class ClassName { public static void main(String[] args) { // Code to be executed System.out.println("Hello, World!"); // Print statement } } |
There is always a class and main method with two parameters in the java language's basic structure. To print or display a message on the screen we use system.out.println().
| // This is a single-line comment |
| /* This is a multi-line comment. You can write multiple lines. */ |
| int number = 10; // Integer type double price = 19.99; // Floating-point type char letter = 'A'; // Character type boolean isJavaFun = true; // Boolean type String text = "Hello"; // String type |
| if (condition) { // Code if the condition is true } else if (anotherCondition) { // Code if another condition is true } else { // Code if all conditions are false } |
| switch (expression) { case value1: // Code for case 1 break; case value2: // Code for case 2 break; default: // Default code } |
| for (int i = 0; i < 10; i++) { System.out.println(i); } |
| int i = 0; while (i < 10) { System.out.println(i); i++; } |
| int i = 0; do { System.out.println(i); i++; } while (i < 10); |
| public class ArrayExample { public static void main(String[] args) { int[] numbers = {1, 2, 3, 4, 5}; // Declare and initialize an array System.out.println("First element: " + numbers[0]); // Access array element // Loop through the array System.out.println("All elements in the array:");for (int num : numbers) { System.out.println(num); } |

| // Define a method public static int addNumbers(int a, int b) { return a + b; } // Call a method int result = addNumbers(5, 3); System.out.println(result); // Outputs 8 |
| public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } |
| import java.util.Scanner; public class Addition { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter first number: "); int num1 = scanner.nextInt(); System.out.print("Enter second number: "); int num2 = scanner.nextInt(); int sum = num1 + num2; System.out.println("The sum is: " + sum); scanner.close(); } |

| public class EvenOdd { public static void main(String[] args) { int number = 10; if (number % 2 == 0) { System.out.println(number + " is even."); } else { System.out.println(number + " is odd."); } } } |
| public class ArrayExample { public static void main(String[] args) { String[] names = {"Alice", "Bob", "Charlie"}; for (String name : names) { System.out.println(name); } } } |
