Terminating a Java Program

Calling System.exit(0) (or any other value for that matter) causes the Java virtual machine to exit, terminating the current process. The parameter you pass will be the return value that the java process will return to the operating system. You can make this call from anywhere in your program – and the result will always … Read more

Why it is mandatory to use “throws IOException”

It may not be mandatory to add the throws IOException to your main function, but its mandatory to do something about the exception. When you’re doing file io, or network io, or other (?) io, something could go wrong. The file might not exist, it could be on a bad sector of the disk, the … Read more

Make a simple timer in Java

This is not difficult. However, I would caution you that I have seen some very confused answers on stack overflow, in some cases shockingly poor coding habits, so be very careful. First let me answer the question. If seem that the biggest mistake that programmers make in implementing a timer, is thinking that they need … Read more

What is the use of a private static variable in Java?

Of course it can be accessed as ClassName.var_name, but only from inside the class in which it is defined – that’s because it is defined as private. public static or private static variables are often used for constants. For example, many people don’t like to “hard-code” constants in their code; they like to make a public static or private static variable with a meaningful … Read more

“The public type <> must be defined in its own file” error in Eclipse [duplicate]

If .java file contains top level (not nested) public class, it has to have the same name as that public class. So if you have class like public class A{…} it needs to be placed in A.java file. Because of that we can’t have two public classes in one .java file. If having two public classes would be allowed then, and lets say aside from public A class … Read more

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