Use Strings carefully β οΈ
If two Strings are concatenated using β+β operator in a βforβ loop, then it creates a new String Object, every time.
This causes wastage of Memory and increases Performance time.
Also, while instantiating a String Object, constructors should be avoided and instantiation should happen directly. For example:
#memory #java #string
@ProgrammingTip
If two Strings are concatenated using β+β operator in a βforβ loop, then it creates a new String Object, every time.
This causes wastage of Memory and increases Performance time.
Also, while instantiating a String Object, constructors should be avoided and instantiation should happen directly. For example:
//Slower Instantiation β
String bad = new String("string object");
//Faster Instantiation β
String good = "string object";
#memory #java #string
@ProgrammingTip
Avoiding Memory Leaks By Simple Tricks β
Memory Leaks often cause performance degradation of software. Since, Java manages memory automatically, the developers do not have much control.
But there are still some standard practices which can be used to protect from memory leakages. ππ»ββοΈ
1οΈβ£ - Always release database connections when querying is complete.
2οΈβ£ - Try to use Finally block as often possible.
3οΈβ£ - Release instances stored in Static Tables.
#java #memory #performance
@programmingTip
Memory Leaks often cause performance degradation of software. Since, Java manages memory automatically, the developers do not have much control.
But there are still some standard practices which can be used to protect from memory leakages. ππ»ββοΈ
1οΈβ£ - Always release database connections when querying is complete.
2οΈβ£ - Try to use Finally block as often possible.
3οΈβ£ - Release instances stored in Static Tables.
#java #memory #performance
@programmingTip
Measuring Time π°
Many applications require a very precise time measurement. For this purpose, Java provides static methods in System class. π
1οΈβ£ - currentTimeMillis(): Returns current time in MilliSeconds since Epoch Time, in Long.
view sourceprint?
2οΈβ£ - nanoTime(): Returns the current value of the most precise available system timer, in NanoSeconds, in long.
nanoTime() is meant for measuring relative time interval instead of providing absolute timing.
#java #time
@ProgrammingTip
Many applications require a very precise time measurement. For this purpose, Java provides static methods in System class. π
1οΈβ£ - currentTimeMillis(): Returns current time in MilliSeconds since Epoch Time, in Long.
view sourceprint?
long startTime = System.currentTimeMillis();
long estimatedTime = System.currentTimeMillis() - startTime;
2οΈβ£ - nanoTime(): Returns the current value of the most precise available system timer, in NanoSeconds, in long.
nanoTime() is meant for measuring relative time interval instead of providing absolute timing.
long startTime = System.nanoTime();
long estimatedTime = System.nanoTime() - startTime;
#java #time
@ProgrammingTip
πΌ Rescale Image In Java πΌ
An image can rescaled using AffineTransform. First of all, Image Buffer of input image is created and then scaled image is rendered. βοΈ
#java #image
@ProgrammingTip
An image can rescaled using AffineTransform. First of all, Image Buffer of input image is created and then scaled image is rendered. βοΈ
BufferedImage imgSource =
ImageIO.read(new File("myImage.jpg"));
BufferedImage imgDest =
new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgDest.createGraphics();
AffineTransform affinetransformation =
AffineTransform.getScaleInstance(2, 2);
g2d.drawRenderedImage(imgSource,
affinetransformation);
ImageIO.write(imgDest, "JPG",
new File("outImage.jpg"));
#java #image
@ProgrammingTip