Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
assignments_new
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Suresh Kumar
assignments_new
Commits
0b8ed9c0
Commit
0b8ed9c0
authored
Jun 28, 2022
by
Suresh Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Singleton
parent
6c965654
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
0 deletions
+87
-0
Student.java
eager Loading/src/singleton/com/Student.java
+12
-0
Test.java
eager Loading/src/singleton/com/Test.java
+8
-0
Eager.java
lazyloading/src/fetching/com/Eager.java
+18
-0
Lazy.java
lazyloading/src/fetching/com/Lazy.java
+25
-0
Hashcode.java
lazyloading/src/hashcode/com/Hashcode.java
+24
-0
No files found.
eager Loading/src/singleton/com/Student.java
0 → 100644
View file @
0b8ed9c0
package
singleton
.
com
;
public
class
Student
{
static
Student
st
=
new
Student
();
private
Student
(){
System
.
out
.
println
(
"Simple Singleton Created "
);
}
static
Student
getInstance
(){
return
st
;
}
}
eager Loading/src/singleton/com/Test.java
0 → 100644
View file @
0b8ed9c0
package
singleton
.
com
;
public
class
Test
{
public
static
void
main
(
String
[]
args
){
Student
s1
=
Student
.
getInstance
();
Student
s2
=
s1
;
System
.
out
.
println
(
s1
==
s2
);
}
}
lazyloading/src/fetching/com/Eager.java
0 → 100644
View file @
0b8ed9c0
package
fetching
.
com
;
class
Eager
{
private
static
Eager
obj
=
new
Eager
();
//Early, instance will be created at load time
private
Eager
(){
System
.
out
.
println
(
"Eager Singleton Instantiation"
);
}
public
static
Eager
getEager
(){
return
obj
;
}
public
static
void
main
(
String
[]
args
){
Eager
e1
=
Eager
.
getEager
();
}
}
lazyloading/src/fetching/com/Lazy.java
0 → 100644
View file @
0b8ed9c0
package
fetching
.
com
;
public
class
Lazy
{
private
static
Lazy
l
=
null
;
private
Lazy
()
{
System
.
out
.
println
(
"Lazy Singleton being initialized"
);
}
public
static
Lazy
getInstance
()
{
if
(
l
==
null
)
l
=
new
Lazy
();
return
l
;
}
public
static
void
main
(
String
[]
args
){
Lazy
l1
=
Lazy
.
getInstance
();
}
}
\ No newline at end of file
lazyloading/src/hashcode/com/Hashcode.java
0 → 100644
View file @
0b8ed9c0
package
hashcode
.
com
;
public
class
Hashcode
{
public
static
void
main
(
String
[]
args
){
String
a
=
"suresh"
;
String
b
=
"suresh"
;
if
(
a
.
equals
(
b
)){
System
.
out
.
println
(
"a and b both variable are equals and their respective values are : "
+
" "
+
a
.
hashCode
()
+
" And "
+
b
.
hashCode
()
);
}
String
c
=
"suresh"
;
String
d
=
"kumar"
;
if
(!
c
.
equals
(
d
)){
System
.
out
.
println
(
"c and d both variable are un_equals and their respective values are : "
+
" "
+
c
.
hashCode
()
+
" And "
+
d
.
hashCode
()
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment