Skip to content

Tag: java

Mock a constructor with parameter

I have a class as below: The logic in the constructor A(String test) and check() are the things I am trying to mock. I want any calls like: new A($$$any string$$$).check() returns a dummy string “test”. I tried: But it doesn’t seem to be working. new A($$$any string$$$).check() is still goin…

File To Store Data in J2ME

I’m writing a J2ME dictionary app and I’m stuck on which is the best way to store the content in the app. I don’t want the app to be too big. I want to store the descriptions of the words in a dictionary. Please help me. I know about RMS but I don’t want to use RMS because all the

How to query for a List in JdbcTemplate?

I’m using Spring’s JdbcTemplate and running a query like this: There are no named parameters being passed, however, column name, COLNAME, will be passed by the user. Questions Is there a way to have placeholders, like ? for column names? For example SELECT ? FROM TABLEA GROUP BY ? If I want to sim…

How to read write this in utf-8?

I was getting an error io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence The solution is to read and write file in UTF-8. My code is: I’m reading a url and writing it to a file DirectionResponse.xml. Then reading DirectionResponse.xml and writing the same as *ppre_DirecionRespon…

Feemarker writing images to html

is there anyway to write image in freemarker instead of giving link as <img src=”${pathToPortalImage} Note : cant we use otputstream or something in freemarker ? Answer You can embed the image as base64 directly inside the html img tag. To convert an image to base 64 you can use Apache Commons (codec…

Is there a simpler solution for Codingbat fix45?

I am trying to solve this CodingBat problem: (This is a slightly harder version of the fix34 problem.) Return an array that contains exactly the same numbers as the given array, but rearranged so that every 4 is immediately followed by a 5. Do not move the 4’s, but every other number may move. The array…

How to convert UTC time into local time in Java?

I have time coming from gpslocation service in 1352437114052 format. Can some one tell me how to convert this into local time either in Java or Matlab or Excel. Answer Create a new Date from your milliseconds since epoch. Then use a DateFormat to format it in your desired timezone.