In Java, the body of a do-while loop and the loop condition do not belong to the same scope. So the following code won’t compile: But this code does make sense to me. Also, I cannot find any pitfalls if the body and the condition are in the same scope; since the body will always get executed, and Java d…
Tag: java
How to add Tomcat Server in eclipse
I just installed Java EE plugin in plain eclipse and I am trying to add tomcat server. I opened add new server which showing “Choose the type of server to create” but there is no server list. How can I add tomcat server? Eclipse: Indigo. Answer Do as this: Windows -> Show View -> Servers The…
How to make Eclipse align the ?: ternary operator?
I need the exact same effect as in this question but in Eclipse. It should only do the alignment if I explcitly insert a new line before the “:” or if the second operand (the “true” expression) is too long. Example: Answer This original answer was for Galileo which is well over a decad…
No Such Element Exception?
So here is my code: For some reason I get a No Such Element Exception I’m not sure why though. Basically my program is searching through two text files – armor.txt and TreasureClassEx.txt. getTreasureClass receives a treasure class from a monster and searches through the txt until it reaches a bas…
How do I start creating a small compiler for a school project in java or c#
for my final exam (to graduate from university) I’ve been asked to create a tiny compiler, with the following requirements: The student must develop a basic compiler with all the design parts that conforms it (lexical analysis, syntaxis analysis, parsing, etc). This compiler will have an interface that shows …
How to hide the soft keyboard inside a fragment?
I have a FragmentActivity using a ViewPager to serve several fragments. Each is a ListFragment with the following layout: When starting the activity, the soft keyboard shows. To remedy this, I did the following inside the fragment: I save the incoming ViewGroup container parameter from onCreateView as a way t…
In Java, how can I combine two JSON arrays of objects?
I have several string each containing a JSON representation of an array of objects. Here’s an example in code to illustrate, though this is not my actual code (the JSON strings are passed in): I need to combine those two JSON arrays into one large JSON array. I could treat this as a String manipulation …
How to safely save a file to disk in android?
I have written an android app that saves (potentially) large files to the SD Card. Occasionally I get an IOException during the write operation which causes the file to be left in a corrupt state. Based on the answer to this question: Question: How to safely write to a file? the strategy I should use is to cr…
How to break out or exit a method in Java?
The keyword break in Java can be used for breaking out of a loop or switch statement. Is there anything which can be used to break from a method? Answer Use the return keyword to exit from a method. From the Java Tutorial that I linked to above: Any method declared void doesn’t return a value. It does n…
Getting old data with JPA
I’m getting old data with JPA, even if I disable the cache. I guess is because the resource is configured to be RESOURCE_LOCAL, but I’m not sure. My code that is getting old info about the user: My entity: Anybody has some idea of what is going on? UPDATE 1 The begin, flush and commit methods were…