How to check type of variable in Java?

Java is a statically typed language, so the compiler does most of this checking for you. Once you declare a variable to be a certain type, the compiler will ensure that it is only ever assigned values of that type (or values that are sub-types of that type). The examples you gave (int, array, double) these … Read more

Session TimeOut in web.xml

To set a session-timeout that never expires is not desirable because you would be reliable on the user to push the logout-button every time he’s finished to prevent your server of too much load (depending on the amount of users and the hardware). Additionaly there are some security issues you might run into you would … Read more

Java integer-double division confusion

In your first example: sum is an int, and 4 is also an int. Java is dividing one integer by another and getting an integer result. This all happens before it assigns the value to double avg, and by then you’ve already lost all information to the right of the decimal point. Try some casting. OR

What does ‘0’ do in Java?

Ascii characters are actually numbers. And 0 .. 9 digits are numbers starting from decimal 48 (0x30 hexadecimal). So to get the value of any character digit, you can just remove the ‘0’, ie 48. If you don’t remove ‘0’ (48) the total sum will be over by 48 * numberOfDigits. See an ascii table to locate digits in it. … Read more

How to connect to FTP over TLS/SSL (FTPS) server in Java

The SimpleFTP class/library does not support TLS/SSL at all. Use the FTPSClient class from the Apache Commons Net library instead. See the official example for the FTPClient class and just substitute the FTPClient with the FTPSClient. The FTPSClient class defaults to an explicit TLS/SSL (recommended). In a rare case you need an implicit TLS/SSL, use new FTPSClient(true).

JVM Crash – “EXCEPTION_ACCESS_VIOLATION”

The crash happens inside DirectX library: d3d9.dll. Try the following options: Update / reinstall graphics driver. Switch off graphics card utilities (I’ve noticed RivaTuner in the list of loaded libraries). Run Java with -Dsun.java2d.d3d=false JVM option or set J2D_D3D=false environment variable. This would definitely help, though Java will not make use of Direct3D acceleration.

:: (double colon) operator in Java 8

Usually, one would call the reduce method using Math.max(int, int) as follows: That requires a lot of syntax for just calling Math.max. That’s where lambda expressions come into play. Since Java 8 it is allowed to do the same thing in a much shorter way: How does this work? The java compiler “detects”, that you want to implement a method … Read more

How do I apply the for-each loop to every character in a String?

The easiest way to for-each every char in a String is to use toCharArray(): This gives you the conciseness of for-each construct, but unfortunately String (which is immutable) must perform a defensive copy to generate the char[] (which is mutable), so there is some cost penalty. From the documentation: [toCharArray() returns] a newly allocated character array whose length is the length of this string and whose contents are … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)