Tag: java
Convert byte to KB MB GB
[code language=”java”]
static readonly string[] SizeSuffixes =
{ "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
static string SizeSuffix(Int64 value)
{
if (value < 0) { return "-" + SizeSuffix(-value); }
if (value == 0) { return "0.0 bytes"; }
int mag = (int)Math.Log(value, 1024);
decimal adjustedSize = (decimal)value / (1L << (mag * 10));
return string.Format("{0:n1} {1}", adjustedSize, SizeSuffixes[mag]);
}
[/code]
IDEA community edition, jetty, war, debug, maven
Let’s create a simple java web app by IntelliJ IDEA community edition, Jetty. There is opportunity to debug the app even by IDEA CE.
Continue reading IDEA community edition, jetty, war, debug, maven
Java feature/bug
1.
[code language=”java”]
public static void main(String[] args) {
System.out.println(Byte.valueOf((byte) 48) == Byte.valueOf((byte) 48));
System.out.println(Byte.valueOf((byte) 248) == Byte.valueOf((byte) 248));
System.out.println(Integer.valueOf(48) == Integer.valueOf(48));
System.out.println(Integer.valueOf(248) == Integer.valueOf(248));
}
[/code]
Answer
[code language=”java”]
true
true
true
false
[/code]