Core Java Tutorial for Beginners | English | Installation & Basics

🚀 Core Java with Installation & Basics

1. Install Java

a. Install JDK → Oracle JDK Downloads
b. Install IntelliJ → IntelliJ IDEA Downloads
c. Install Eclipse → Eclipse Downloads


2. Sample Code

a) Functions

A function is a block of code which takes some input, performs operations, and returns output.
Functions stored inside classes are called methods.
The most important one is main.

b) Class

A class is a group of objects with common properties.
It can contain variables (properties) and methods (functions).
Example:

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

c) Variables

A variable is a container used to hold data. Each variable must have a unique name (identifier).



d) Data Types

Data types define the type and size of data associated with variables. This determines the type and size of data associated with variables which is essential to know since different data types occupy different sizes of memory. There are 2 types of Data Types :

  • Primitive Data Types – fixed size (byte, short, int, long, float, double, char, boolean). 

    Data TypeMeaningSizeRange
    byte2’s complement int1-128 to 127
    short2’s complement int2-32K to 32K
    intInteger numbers4-2B to 2B
    longLarge integer8±9 quintillion
    floatFloating-point4~7 decimal digits
    doubleDouble floating-point8~16 decimal digits
    charCharacter2a–z, A–Z, symbols
    booleanTrue/False1true, false
  • Non-Primitive Data Types – variable size (String, Arrays, Objects, etc). 



3. String Class

Strings are immutable non-primitive data types in Java. Once a string is created it’s value cannot be changed i.e. if we wish to alter its value then a new string with a new value has to be created. This class in java has various important methods that can be used for Java objects. 

Strings are immutable objects in Java.
Common methods:

  • concat() 


  • charAt()


  • length()


  • replace()


  • substring()



4. Arrays

Arrays in Java are like a list of elements of the same type i.e. a list of integers, a list of booleans etc.

Arrays are used to store multiple values of the same type.

int[] numbers = new int[5]; // method 1


int[] nums = {1, 2, 3, 4, 5}; // method 2



5. Casting

Casting in java is the assigning values of one type to another. The types being considered here are compatible i.e. we can only assign values of a number type to another type storing numbers (vice-versa is not allowed i.e. floating values cannot be assigned to boolean data types). Casting in Java is of 2 types:

Casting assigns values of one type to another.

  • Implicit Casting: smaller → larger type (automatic). This casting is done by java implicitly i.e. on its own. It is assigning smaller values to larger data types.


  • Explicit Casting: larger → smaller type (manual). This casting is done by the programmer. It is assigning larger values to smaller data types.


    int x = 10;     double y = x; // implicit     double d = 9.8;     int i = (int) d; // explicit



6. Constants

A constant is a variable with a fixed value that cannot be reassigned.
Use the keyword final in Java.

final double PI = 3.14159;




7. Operators

Types of operators in Java:

  • Arithmetic: +, -, *, /, %

  • Assignment: =, +=, -=, *=, /=

  • Comparison: ==, !=, >, <, >=, <=

  • Logical: &&, ||, !

  • Unary: ++a, a++, --a, a--


    Operator Operation Shown below:

    1. == Gives true if two operands are equal A==B is not true

    2. != Gives true if two operands are not equal A!=B is true

    3. > Gives true if left operand is more than right operand A>B is not true

    4. < Gives true if left operand is less than right operand A<B is true

    5. >= Gives true if left operand is more than right operand or equal to it A>=B is not true

    6. <= Gives true if left operand is more than right operand or equal to it A<=B is true

     

    d. Logical Operators: Logical operators are used to connect multiple expressions or conditions together.

    We have 3 basic logical operators.

    Suppose : A=0 and B=1

    Operator Operation Example given below:

     

    1. && AND operator. Gives true if both operands are non zero 

        (A && B) is false

     

    2. || OR operator. Gives true if at least one of the two operands are non-zero.

        (A || B) is true

     

    3. ! NOT operator. Reverse the logical state of operand 

        !A is true


8. Math Class

Java provides Math class with useful functions.

import java.lang.Math; public class MathExample { public static void main(String[] args) { System.out.println(Math.max(5, 10)); System.out.println(Math.min(5, 10)); System.out.println(Math.random()); } }




9. Taking Input

We use Scanner class for input.

import java.util.Scanner; Scanner sc = new Scanner(System.in); int num = sc.nextInt();




10. Conditional Statements

If-Else: The if block is used to specify the code to be executed if the condition specified in if is true, the else block is executed otherwise.

int age = 20; if(age >= 18) { System.out.println("You are adult."); } else { System.out.println("You are minor."); }




Switch: Switch case statements are a substitute for long if statements that compare a variable to multiple values. After a match is found, it executes the corresponding code of that value case.

int day = 3; switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; default: System.out.println("Invalid"); }




11. Break & Continue

Jumps in loops are used to control the flow of loops. There are two statements used to implement jump in loops - Continue and Break. These statements are used when we need to change the flow of the loop when some specified condition is met.

Continue statement is used to skip to the next iteration of that loop. This means that it stops one iteration of the loop. All the statements present after the continue statement in that loop are not executed.

  • Continue → skips current iteration.                                                                                         In this for loop, whenever i as a number divisible by 4, it will not be printed as the loop will skip to the next iteration due to the continue statement. Hence, all the numbers except those which are divisible by 4 will be printed.

  • Break statement is used to terminate the current loop. As soon as the break statement is encountered in a loop, all further iterations of the loop are stopped, and control is shifted to the first statement after the end of loop.

  • Break → exits loop immediately. 

                                                                      In this loop, when i becomes equal to 4, the for loop terminates due to break statement, Hence, the program will print numbers from 1 to 3 only.



12. Loops

A loop is used for executing a block of statements repeatedly until a particular condition is satisfied. A loop consists of an initialisation statement, a test condition and an increment statement.

For Loop: The syntax of the for loop is:

 for (initialization; condition; update) {

/ / body of-loop

}

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




While Loop: The syntax for while loop is:

 while(condition) {

/ / body of the loop

}

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



Do-While Loop: The syntax for the do-while loop is:

 do {

/ / body of loop;

}

while (condition);



int j=1; do { System.out.println(j); j++; } while(j<=5);

13. Exception Handling: Exception Handling in Java is a mechanism to handle the runtime errors so that normal flow of the application can be maintained. It is done using 2 keywords - 'try' and 'catch'. Additional keywords like finally, throw and throws can also be used and we discuss when we dive deep into this concept.

try { int result = 10 / 0; } catch(ArithmeticException e) { System.out.println("Error: " + e.getMessage()); }




14. Methods / Functions: A function is a block of code that performs a specific task. Why are functions used? syntax: 

return-type function_name (parameter 1, parameterϮ ……

parameter n) {

//function

_

body

}

example:

int add(int a, int b) { return a + b; }

return-type: The return type of a function is the data type of the variable that

function returns. For eg- If we write a function that adds 2 integers and returns

their sum then the return type of this function will be ‘int’ as we will return a sum

that is an integer value. When a function does not return any value, in that case the

return type of the function is 'void'. 

function_name: It is the unique name of that function.

Parameters: It is always recommended to declare a function before it is used.

A function can take some parameters as inputs. These parameters are specified along with their data types. For eg- if we are writing a function to add 2 integers, the parameters would be passed like –

int add (int num1, int num2)

main function: The main function is a special

function as the computer starts running the code from the beginning of the main function. Main function serves as the entry point for the program.



15. Mini Project – Number Guessing Game as "DummyProject"Let’s create a project where we are trying to ask the user to guess a randomly generated number. The number is in the range of 1 to 10. If the user guesses a number that is greater, we print "SORRY !! your number is large". If the user guesses a number that is smaller, we print "SORRY !! your number is small". If the user is able to correctly guess the number, then we print "GREAT ..  YOU ARE RIGHT, YOU GUSSED A CORRECT NUMBER!!". At the end we will print the number that was generated by our Math library using Math.random() method. LETS WRITE THE CODE...
import java.util.Scanner; class DummyProject { public static void main(String[] args) { int number = 1 + (int)(10 * Math.random()); Scanner sc = new Scanner(System.in); System.out.print("Guess a number between 1 and 10: "); int guess = sc.nextInt(); if(guess > number) { System.out.println("SORRY !! your number is large"); } else if(guess < number) { System.out.println("SORRY !! your number is small"); } else { System.out.println("GREAT .. YOU ARE RIGHT!"); } System.out.println("The number was: " + number); } }



👉Watch Core Java in Action better:

Here's a quick video to help you understand Core Java Tutorial for Beginners in Action better: Coming soon


✅ Conclusion

You have now learned the fundamentals of Core Java — installation, variables, data types, strings, arrays, operators, loops, exception handling, methods, and even a small project.


💼 Professional Support Available

If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.

Technologies covered include Java, Spring Boot, PL/SQL, Azure, and workflow automation (jBPM, Camunda BPM, RHPAM).




Comments

Popular posts from this blog

jBPM Installation Guide: Step by Step Setup

Scopes of Signal in jBPM

OOPs Concepts in Java | English | Object Oriented Programming Explained