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…
Tag: java
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…
Invalid packaging for parent pom.xml, must be “pom” but is “ear”
Could anybody suggest me an solution with the following exception. I am going to create a multi-module project. Parent Project name is LOGICBACKEND child project name is DBAccess I need to have ear file of LOGICBACKEND which should contain DBAccess prjoects jar file. I am getting following exception when i ru…
Implementing Cursor in Java with some Transparency
I have a 35×40 px. png image I want to use as a custom cursor in a Swing application. The image has a glow so contains alpha transparency values. Problem is when I attempt to use the conventional method of using the Toolkit to generate the custom cursor I get black pixels where alpha transparency values …
How to create Currency instance with non ISO 3166 country like en_UK?
In my app, I get the user’s default locale using Locale.getDefault() and then pass that to Currency.getInstance(Locale). It mostly works, but I have started getting reports from users which show the following IllegalArgumentException in the stack trace: Caused by: java.lang.IllegalArgumentException: Uns…
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.