There are two types of iterators in Java: fail-safe and fail-fast. What does this mean, and is the difference between them? Answer What is the difference between them … “Fail-safe” (in engineering) means that something fails in a way that causes no or minimal damage. Strictly speaking, there…
Tag: java
In Intellij, how do I toggle between camel case and underscore spaced?
At my company we have two different style guides for java vs sql. In java I have a field named historyOfPresentIllness and when i write the sql, I want to name it history_of_present_illness. Is there a keyboard shortcut to switch from one to the other when I have the phrase highlighted? Or perhaps a plugin th…
Printing pyramid in Java on the console
How can I print a pyramid in Java like this My current code looks like this: If I try this removing declared i & j then it shows an array out of bounds exception However ‘i’ & ‘j’ are creating the problem. What should my code look like. Answer initially val is equal to 1 . Insi…
Java: why Thread.sleep() and yield() are static?
Why sleep() and yield() methods are defined as static methods in java.lang.Thread class? Answer The code would only execute when someXThread was executing, in which case telling someYThread to yield would be pointless. So since the only thread worth calling yield on is the current thread, they make the method…
Can’t remove jar from Web App Library
How can I remove the jars in my Web App Library? I manually added a couple jars to the web app library. My program is now pitching a fit so I clearly need to remove them. However, when I go to the Build Path, the “Remove” is greyed out. Answer A project’s Web App Library is composed automati…
Java “NoClassDefError” while running the program on Linux
I have a Java program that imports some of the Weka packages. I basically compiled it using the “javac -classpath CLASSPATH:weka.jar program_name.java” command, and everything was fine. When …
Android: How to get the area size of a drawn path?
My problem is to measure the surface area of a path. I generate a random Path and draw it on a canvas. After touching on this closen path, i want to get the area size of this drawn path. How can i get the real area size of this path? The pathes (shapes) looks like this here: link to the
How to know if now time is between two hours?
I have a now time: And I have some hour constants, for example, 23 and 8 (it’s 11pm or 23:00, 8am or 08:00). How I can know is now time between it’s two hour constants? It need to run some code of program or not to run if now time is between in two hours, for example, do not run
Get last week date range for a date in Java
Suppose I have a Date 20 June 2013 How can I get the Date range for the last week, ie in this case 9 June to 15 June. Also if the date was 2nd June 2013 the range should be 26 may to 1 june Answer this is Java Calendar based solution output it’s localized, in my Locale week starts
Is it possible to declare a variable in Gradle usable in Java?
Is it possible to declare a variable in Gradle usable in Java ? Basically I would like to declare some vars in the build.gradle and then getting it (obviously) at build time. Just like a pre-processor macros in C/C++… An example of declaration would be something like that … : Is there a way to do …