Date: 28 Sept 2025
Welcome back to my Java learning journey!
I am not counting days for blogging as it was creating a unnecessary pressure on me to blog daily. I know it's good but with job it's hard to do coding and most of my time was going into blogging which I could have diverted into coding. Blogging is not waste of time, I learn a lot when I have to explain the topic in my own words. I am just limiting it to once in a week or so.
πΉ Variables in Java
A variable is a name given to a memory location that stores data.
- Stored in RAM during execution.
- We must define its data type to indicate what kind of value it will hold.
- First, we declare a variable, then we may initialise it.
int a; // declaration
a = 10; // initialisation
int b = 20; // declaration + initialisation
β A variable can only be declared once, but its value can be changed anytime.
πΉ Data Types in Java
Java has two categories of data types:
- Primitive (8 types)
- Non-Primitive (String, Arrays, Classes, etc.)
π’ 1. Primitive Data Types
These are the most basic types in Java, predefined by the language.
A. Whole Numbers
byte
short
int
long
B. Real Numbers (Decimals)
float
double
C. Single Character
char
D. Logical Values
boolean
β οΈ Each primitive data type has a predefined range. For example:
byte b = 127; // max value
byte c = -128; // min value
π’ 2. Non-Primitive Data Types
These are built using primitive types. Examples:
String
Array
Class
π Note:
-
""
β String literal -
''
β Char literal (cannot be empty)
πΉ Literals
A literal is simply a fixed value that appears exactly as written.
- Example:
10
,"Hello"
,'A'
,true
.
π String is a data type, and it just means text.
πΉ Statement vs Expression
- Expression β Anything that produces a value.
-
Statement β A complete command that can be executed (usually ends with
;
).
Examples:
3 + 4 // Expression β produces 7
int x = 3+4; // Statement β assigns 7 to variable x
"Hello" // String literal β an expression
πΉ Keywords
Keywords are reserved words in Java with predefined meaning.
Examples: class
, public
, static
, void
, int
, if
, else
.
β You cannot use keywords as variable names.
πΉ Output in Java
Using System.out.println()
-
println("Hello")
β prints text and moves to the next line. -
println()
β prints a blank line.
Example:
System.out.println("Java is fun!");
System.out.println(); // blank line
System.out.println("Let's learn more...");
πΉ Playing with JShell
JShell is an interactive tool for running Java code without creating a full class.
Some useful commands:
-
/list
β shows commands entered so far -
/var
β lists variables created -
ctrl + c
β cancels a process -
/exit
β exits JShell
π In JShell, each line is treated as a statement, so ;
is optional.
π Wrap-up
Today I learned:
β What variables are and how to declare/initialize them
β Primitive vs Non-primitive data types
β Statements vs Expressions
β What literals and keywords mean
β How to use System.out.println()
for output
β Some handy JShell commands
Self Notes
Coding is a serious thing, in last two days I wasted much of my time in other activities. I have realised my mistake and now I will code daily. I am already short of time and wasting time isn't good. I won't be scrolling social media now on.
Top comments (0)