Skip to content

Memory Leak or wastage concept #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="/DesignPatternsJava9/src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Compiled class file
.idea/*
*.class

# Log file
*.log

*.iws
# BlueJ files
*.ctxt

15 changes: 15 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DesignPatternsJava9</name>
<comment/>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
6 changes: 6 additions & 0 deletions DesignPatternsJava9.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<component inheritJdk="true">
<output-test url="file://$MODULE_DIR$/bin/test/DesignPatternsJava9"/>
<exclude-output/>
<contentEntry url="file://$MODULE_DIR$"/>
</component>
13 changes: 13 additions & 0 deletions DesignPatternsJava9.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/bin/production/DesignPatternsJava9" />
<output-test url="file://$MODULE_DIR$/bin/test/DesignPatternsJava9" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# DesignPatternsJava9
This repo consists Gang of Four Design patterns code on Java 9. Each branch in the repository has code of 1 design pattern. Switch repository to try out different design patterns.
# What is memory issue / memory wastage
Memory is one of the most critical resource of a software program and it should be used wisely.
A memory leak reduces the performance of the computer by reducing the amount of available memory. Eventually, in the worst case, too much of the available memory may become allocated and part of the system or device stops working correctly, the application fails, or the system slows down

Each design pattern is focused to solve certain problem and it might have few side effects as well. A design that worked on a small software might not work on big enterprise software.

Hence, First thing is to find the primary target of the design and then pick and choose the design pattern based on issue in hand.

### Learn Design Patterns with Java by Aseem Jain
This repository contains working project code used in video Course by Packt Publication with title "Learn Design Patterns with Java " authored by "Aseem Jain".

### Course link:
https://www.packtpub.com/application-development/learn-design-patterns-java-9-video

### ![ http://in.linkedin.com/in/premaseem](https://github.com/premaseem/DesignPatternsJava9/blob/master/linkedin.png "http://in.linkedin.com/in/premaseem") Profile: http://in.linkedin.com/in/premaseem

### Authors blog on design patterns:
https://premaseem.wordpress.com/category/computers/design-patterns/

### Software Design pattern community face book page:
https://www.facebook.com/DesignPatternGuru/
27 changes: 27 additions & 0 deletions src/com/premaseem/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.premaseem;

/*
@author: Aseem Jain
@title: Design Patterns with Java 9
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
*/
public class Calculator {
static int num = 0;
private static Calculator instance = null;

public static Calculator getInstance(){
if (instance == null){
instance = new Calculator();
}
return instance;
}

private Calculator () {
num++;
System.out.println(num + " wasting memory with new object");
}

public Integer add (Integer sum, Integer number) {
return sum + number;
}
}
24 changes: 24 additions & 0 deletions src/com/premaseem/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.premaseem;

/*
@author: Aseem Jain
@title: Design Patterns with Java 9
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
@copyright: 2018 Packt Publication
*/
public class Client {
public static void main (String[] args) {
System.out.println("program to add number");
Integer sum = calculateSum();
System.out.println("total of all numbers is "+ sum);
}

private static Integer calculateSum () {
Integer sum = 0;
for (int i =0; i< 1000; i++){
Calculator calc = Calculator.getInstance();
sum = calc.add(sum,i);
}
return sum;
}
}