Bharat Singh (@Bharatastic) header
Bharat Singh (@Bharatastic) profile picture

Software Engineering

In The Matrix
Joined August 2021
Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)Photo by Bharat Singh (@Bharatastic)
Most Java developers use Java every day โ€” But very few truly understand it.
1
102
๐— ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ ๐—ผ๐˜ƒ๐—ฒ๐—ฟ๐—น๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐˜ƒ๐˜€ ๐—บ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ ๐—ผ๐˜ƒ๐—ฒ๐—ฟ๐—ฟ๐—ถ๐—ฑ๐—ถ๐—ป๐—ด - ๐——๐—ผ ๐˜†๐—ผ๐˜‚ ๐—ธ๐—ป๐—ผ๐˜„ ๐˜๐—ต๐—ฒ ๐—ฟ๐—ฒ๐—ฎ๐—น ๐—ฑ๐—ถ๐—ณ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ? Both are forms of polymorphism in Java - but they solve very different problems.
1
13
๐— ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ ๐—ผ๐˜ƒ๐—ฒ๐—ฟ๐—น๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด โ€ข Same method name, different parameters โ€ข Happens in the same class โ€ข Resolved at compile time ๐— ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ ๐—ผ๐˜ƒ๐—ฒ๐—ฟ๐—ฟ๐—ถ๐—ฑ๐—ถ๐—ป๐—ด โ€ข Same method signature in parent and child class โ€ข Enables runtime behavior changes โ€ข Resolved at runtime
1
11
๐—œ๐—ป ๐˜€๐—ถ๐—บ๐—ฝ๐—น๐—ฒ ๐˜๐—ฒ๐—ฟ๐—บ๐˜€: โ€ข Overloading โ†’ multiple ways to call a method โ€ข Overriding โ†’ changing behavior in subclasses Understanding this difference is essential ๐˜ฟ๐™ค ๐™”๐™ค๐™ช ๐™๐™š๐™–๐™ก๐™ก๐™ฎ ๐™†๐™ฃ๐™ค๐™ฌ ๐™…๐™–๐™ซ๐™–? โ€” ๐™‹๐™–๐™ง๐™ฉ 35 #Java #SoftwareEngineering
13
๐—œ๐—ป๐—ต๐—ฒ๐—ฟ๐—ถ๐˜๐—ฎ๐—ป๐—ฐ๐—ฒ - ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—ฎ๐—ป๐—ฑ ๐——๐—ฎ๐—ป๐—ด๐—ฒ๐—ฟ Inheritance lets a class derive ๐—ฎ๐˜๐˜๐—ฟ๐—ถ๐—ฏ๐˜‚๐˜๐—ฒ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ฏ๐—ฒ๐—ต๐—ฎ๐˜ƒ๐—ถ๐—ผ๐—ฟ๐˜€ from another class. It enables you to create new classes from existing ones, thereby improving code reuse and structure.
1
15
โ€ข A child class can directly use the parent classโ€™s variables and methods without duplicating code. โ€ข A child class can also introduce new features or override existing ones to enhance functionality. It provides: โ€ข Code reuse โ€ข Polymorphism โ€ข Clear โ€œis-aโ€ relationships
1
12
Inheritance enables reuse and polymorphism, Inheritance also introduces ๐˜๐—ถ๐—ด๐—ต๐˜ ๐—ฐ๐—ผ๐˜‚๐—ฝ๐—น๐—ถ๐—ป๐—ด. Use inheritance intentionally. Prefer composition when possible. ๐˜ฟ๐™ค ๐™”๐™ค๐™ช ๐™๐™š๐™–๐™ก๐™ก๐™ฎ ๐™†๐™ฃ๐™ค๐™ฌ ๐™…๐™–๐™ซ๐™–? โ€” ๐™‹๐™–๐™ง๐™ฉ 34 #Java #SoftwareEngineering
16
๐—–๐—ผ๐—ป๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐—ผ๐—ฟ ๐—ผ๐˜ƒ๐—ฒ๐—ฟ๐—น๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด - ๐—บ๐˜‚๐—น๐˜๐—ถ๐—ฝ๐—น๐—ฒ ๐˜„๐—ฎ๐˜†๐˜€ ๐˜๐—ผ ๐—ฐ๐—ฟ๐—ฒ๐—ฎ๐˜๐—ฒ ๐—ฎ๐—ป ๐—ผ๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜. Defining more than one constructor inside a class is ๐—–๐—ผ๐—ป๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐—ผ๐—ฟ ๐—ข๐˜ƒ๐—ฒ๐—ฟ๐—น๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด. The ๐˜€๐—ถ๐—ด๐—ป๐—ฎ๐˜๐˜‚๐—ฟ๐—ฒ of the constructor must be different.
1
12
We can change the signature of the constructor in the following ways: ย ย โ€ข By changing the ๐—ป๐˜‚๐—บ๐—ฏ๐—ฒ๐—ฟ ๐—ผ๐—ณ ๐—ฝ๐—ฎ๐—ฟ๐—ฎ๐—บ๐—ฒ๐˜๐—ฒ๐—ฟ๐˜€. ย ย โ€ข By changing the ๐—ฑ๐—ฎ๐˜๐—ฎ๐˜๐˜†๐—ฝ๐—ฒ๐˜€ ๐—ผ๐—ณ ๐—ฎ๐—ฟ๐—ด๐˜‚๐—บ๐—ฒ๐—ป๐˜๐˜€. ย ย โ€ข By changing the ๐˜€๐—ฒ๐—พ๐˜‚๐—ฒ๐—ป๐—ฐ๐—ฒ ๐—ผ๐—ณ ๐—ฎ๐—ฟ๐—ด๐˜‚๐—บ๐—ฒ๐—ป๐˜๐˜€.
1
12
Constructor Overloading adds flexibility, But too many constructors hurt readability. ๐˜ฟ๐™ค ๐™”๐™ค๐™ช ๐™๐™š๐™–๐™ก๐™ก๐™ฎ ๐™†๐™ฃ๐™ค๐™ฌ ๐™…๐™–๐™ซ๐™–? โ€” ๐™‹๐™–๐™ง๐™ฉ 33 #Java #SoftwareEngineering
10
๐—ง๐˜†๐—ฝ๐—ฒ๐˜€ ๐—ผ๐—ณ ๐—–๐—ผ๐—ป๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐—ผ๐—ฟ๐˜€ ๐—ถ๐—ป ๐—๐—ฎ๐˜ƒ๐—ฎ - ๐˜„๐—ต๐—ฎ๐˜ ๐—ฎ๐—ฟ๐—ฒ ๐˜๐—ต๐—ฒ๐˜† ๐—ฟ๐—ฒ๐—ฎ๐—น๐—น๐˜†? In Java, constructors arenโ€™t just about creating objects. They control how objects are born. There are several types of constructors:
1
14
๐—–๐—ผ๐—ฝ๐˜† ๐—–๐—ผ๐—ป๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐—ผ๐—ฟ โ€ข Creates a new object using another object โ€ข Java doesnโ€™t provide it by default - you define it โ€ข Useful for cloning state
1
12
Why this matters: Good constructors = clean objects. Bad constructors = bugs waiting to happen. They donโ€™t just create objects, They define object quality. ๐˜ฟ๐™ค ๐™”๐™ค๐™ช ๐™๐™š๐™–๐™ก๐™ก๐™ฎ ๐™†๐™ฃ๐™ค๐™ฌ ๐™…๐™–๐™ซ๐™–? โ€” ๐™‹๐™–๐™ง๐™ฉ 32.1 #Java #OOP #SoftwareEngineering
13
๐—–๐—ผ๐—ป๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐—ผ๐—ฟ๐˜€ - ๐˜„๐—ต๐˜† ๐˜๐—ต๐—ฒ๐˜† ๐—ฟ๐—ฒ๐—ฎ๐—น๐—น๐˜† ๐—บ๐—ฎ๐˜๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐—๐—ฎ๐˜ƒ๐—ฎ. A constructor looks like a method, but itโ€™s not. When you write: new MyClass() The constructor runs to bring an object to life. Without constructors, objects could start broken or incomplete.
1
14
What constructors do: โ€ข Allocate memory โ€ข Initialize instance variables โ€ข Ensure valid object state โ€ข No return type allowed โ€ข Same name as class + () โ€ข Creating the object = running the constructor They control how objects are born.
1
8
Constructors enforce: โ€ข Proper initialization โ€ข Required dependencies โ€ข Controlled object creation Theyโ€™re not just syntax - They define how objects come into existence. ๐˜ฟ๐™ค ๐™”๐™ค๐™ช ๐™๐™š๐™–๐™ก๐™ก๐™ฎ ๐™†๐™ฃ๐™ค๐™ฌ ๐™…๐™–๐™ซ๐™–? โ€” ๐™‹๐™–๐™ง๐™ฉ 32 #Java #SoftwareEngineering
9
๐—–๐—น๐—ฎ๐˜€๐˜€ ๐˜ƒ๐˜€ ๐—ข๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜ - ๐—ช๐—ต๐—ฎ๐˜ ๐—ฑ๐—ผ ๐˜๐—ต๐—ฒ๐˜† ๐—ฟ๐—ฒ๐—ฎ๐—น๐—น๐˜† ๐—บ๐—ฒ๐—ฎ๐—ป?
1
7
๐—ข๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜๐˜€: โ€ข A ๐—ฟ๐—ฒ๐—ฎ๐—น-๐˜„๐—ผ๐—ฟ๐—น๐—ฑ ๐—ฒ๐—ป๐˜๐—ถ๐˜๐˜†, live in memory. โ€ข Every object is an ๐—ถ๐—ป๐˜€๐˜๐—ฎ๐—ป๐—ฐ๐—ฒ ๐—ผ๐—ณ ๐—ฎ ๐—ฐ๐—น๐—ฎ๐˜€๐˜€. โ€ข Objects can not be created directly. โ€ข Objects have their own state and identity.
1
7
You write classes. You work with objects. Understanding this distinction is fundamental to object-oriented thinking. ๐˜ฟ๐™ค ๐™”๐™ค๐™ช ๐™๐™š๐™–๐™ก๐™ก๐™ฎ ๐™†๐™ฃ๐™ค๐™ฌ ๐™…๐™–๐™ซ๐™–? โ€” ๐™‹๐™–๐™ง๐™ฉ 31 #Java #SoftwareEngineering
7