Sitemap

Java Basics for core programming

4 min readSep 20, 2025

--

Hello, I am Pralesh Rayamajhi. This is for those who is willing to get started with programming with Java core. I would try to put simple as much as possible so that you can get full picture.

There are basics rules that governs the programming in java.

  1. Fundamentals of java
  2. Basic Structure of Java program
  3. Data Types and variables
  4. Operators
  5. Control Statements
  6. Switch Cases
  7. Loops
  8. Arrays
  9. Methods
  10. Object Oriented Programming (OOP) — principle of OOP
  11. Exception Handling

Lets dive into it,

  1. Fundamentals of Java

What is Java ?

It is a programming language that is high level, object oriented and is know for its WORA (Write Once, Run anywhere) capabilities allowing the creator or developer to create and run code on any platform with Java Virtual Machine called JVM. We need to install JVM, its a software that helps build java application including mobile apps, enterprise system, web application, games, and many more. It is similar to C++ but has its more robust features and is supported by libraries and frameworks.

It is strongly typed language meaning we cannot change rules according to our own way as we do in Python or scripting language.

2. Basic Structure of Java program

Create package e.g Test1 in this case and write class and main method. Main is the entry of java program.

Press enter or click to view image in full size
  • class → Blueprint for objects.
  • main() → Entry point.
  • System.out.println() → Prints to console.

3. Data Types & Variables

Primitive types: byte, short, int, long, float, double, char, boolean
Non-primitive: String, Arrays, Classes.

Example

int age = 25;
double salary = 55000.50;
boolean isStudent = false;
String name = “Pralesh”;

4. Operators

Arithmetic: + — * / %
Relational: == != > < >= <=
Logical: && || !
Assignment: = += -= *= /=
Increment/Decrement: ++ —

Get PRALESH RAYAMAJHJI’s stories in your inbox

Join Medium for free to get updates from this writer.

5. Control Statements

5.1 Conditional if else

Press enter or click to view image in full size

Based on age, if age ≥18, then it prints ‘Adult’ to the console else, ‘Minor’ to console.

5.2 Switch Case

Press enter or click to view image in full size

when day equals to 1 it prints “Monday” , when day equals 2 it prints “Tuesday” and when input is random number or invalid number it prints “Other day”. Default is basically if no cases is matched , then it prints default case.

5.3 For Loops and While Loops

Press enter or click to view image in full size

This both loop function same operation. It prints 5 numbers from 0 to 4. Just look at how those two loops perform same operation despite having different way of working along with keywords for and while. These for and while keywords are reserved keywords meaning it cannot be used as variable declaration or as literal.

5.4 Do while Loop

Press enter or click to view image in full size

This loop executes at least once irrespective of any condition. If you really see here, j=1 has been initialized and it goes to block without any condition check and block has print statement so it prints 1 without any check condition so no error for first statement then it can have error if condition is not met. Here our j≤5 satisfies the condition, so it again goes back to loop block and continues untill condition fails. Please look carefully the way syntax has been written for do while loop. while will be at the end of block with semicolon.

8. Arrays

Press enter or click to view image in full size

Way to create an array, we initialize with datatype [ ] variable_name and assigned values to variable. Then we print the numbers[0] that is first element 10. Note, array always starts with index 0,1,…n-1. Here last index or element would be n-1.

9. Methods

Press enter or click to view image in full size

In this class, we are implementing method named add and returning sum of two numbers. Here we are passing a=5 and b=10 to a method. For that we are here creating object and calling from object using dot (.), we created object because we cannot call object unless we define method as static.

E.g static int add(int a, int b) in method declaration.

10. Object Oriented Programming Language (OOPs)

10.1 Class and Object

Press enter or click to view image in full size

Principle of OOPs:

  • Encapsulation — Wrapping data & methods (private, getters/setters)
  • Inheritance — uses extends keyword
  • Polymorphism — Method overloading & overriding
  • Abstraction — Abstract classes & Interfaces

11. Exception Handling

Press enter or click to view image in full size

Some of the types of Exception Handling :

Press enter or click to view image in full size
Types of Exception Handling.

--

--

PRALESH RAYAMAJHJI
PRALESH RAYAMAJHJI

Written by PRALESH RAYAMAJHJI

Graduate Computer Science at South Dakota State University