2) ctrl + space bar
3) ctrl + f6
4) ctrl + f7
5) ctrl + shift + R
6) ctrl + shift + T
7) Alt + up arrow
8) Alt + down arrow
9) Alt + left arrow
10) Alt + right arrow
List< String> list = ["item"];
String item = list[0];
Set< String > set = {"item"};
Map< String,Integer > map = {"key" : 1};
int value = map["key"];
Automatic Resource MgtBufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
But you love this below one!!!!try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
Improved Type Inference for Generic Instance Creation (diamond)Map<String,String> hello = new Map<>();Underscores in numeric literals
String availability = "available";
switch(availability) {
case "available":
//code
break;
case "unavailable":
//code
break;
case "merged":
//code
default:
//code
break;
}
Note : Check for the Null in the String before you passing the String into Switch case.try {
Here comes your code....
}
catch(IOException | NullPointerException | ..........) {
}
/**
* @author anand
*/
public class ImageTest {
/**
* @param args
*/
public static void main(String[] args) {
String path = "/home/devaraj/Image/portraits.jpg";
File file = new File(path);// Specify the input image source file location.
try {
FileInputStream fis = new FileInputStream(file);
InputStream bis = new BufferedInputStream(fis);
FileOutputStream fos = null;
Image image = (Image) ImageIO.read(bis);
int thumbWidth = 100;// Specify image width in px
int thumbHeight = 100;// Specify image height in px
int imageWidth = image.getWidth(null);// get image Width
int imageHeight = image.getHeight(null);// get image Height
double thumbRatio = (double) thumbWidth / (double) thumbHeight;
double imageRatio = (double) imageWidth / (double) imageHeight;
// This calculation is used to convert the image size according to the pixels mentioned above
if (thumbRatio < imageRatio) {
thumbHeight = (int) (thumbWidth / imageRatio);
} else {
thumbWidth = (int) (thumbHeight * imageRatio);
}
BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = thumbImage.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
System.out.println("Encoder" + encoder);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
int quality = 300;
quality = Math.max(0, Math.min(quality, 500));
param.setQuality(0.75f, false);
// output image type.
String format = "jpg";
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
ImageIO.write(thumbImage, format, new File("/home/devaraj/Image/outputimage/portraits_aspect.jpg"));
} catch (IOException ioExcep) {
ioExcep.printStackTrace();
} catch (Exception excep) {
excep.printStackTrace();
}
}
}