I’m unable to create a new servlet because I cannot assign it a project. Also the browse buttons do not work, at all, as in they silently fail Am I missing something basic? I’ve been able to create,…
Tag: java
codility absolute distinct count from an array
so i took the codility interview test yesterday and was informed today that i failed, unfortunately i wasnt given any other information by either codility nor the employer as to where i screwed up so i would appreciate some help in knowing where i went wrong. i know codility pays alot of emphasis on how fast …
Java: set timeout on a certain block of code?
Is it possible to force Java to throw an Exception after some block of code runs longer than acceptable? Answer Yes, but its generally a very bad idea to force another thread to interrupt on a random line of code. You would only do this if you intend to shutdown the process. What you can do is to use Thread.i…
How do I pass JavaScript values to Scriptlet in JSP?
Can anyone tell me how to pass JavaScript values to Scriptlet in JSP? Answer Your javascript values are client-side, your scriptlet is running server-side. So if you want to use your javascript variables in a scriptlet, you will need to submit them. To achieve this, either store them in input fields and submi…
Maven: best way of linking custom external JAR to my project?
It’s my first couple of days learning Maven and I’m still struggling with the basics. I have an external .jar file (not available in the public repos) that I need to reference in my project and I’m trying to figure out what my best option is. It’s a small scale project without a centra…
How do I determine the term frequency of the terms in each document?
I’m building an inverted index, but I can’t seem to get the correct frequencies when I check the database. I read everywhere that you should use a HashMap, but I’m not quite sure if this is the correct method of doing so. Any ideas? Answer You should get the value for the token first, increm…
Java: Filling a BufferedImage with transparent pixels
I have an off-screen BufferedImage, constructed with the type BufferedImage.TYPE_INT_ARGB. It can contain anything, and I’m looking for a way to (fairly efficiently) completely overwrite the image with transparent pixels, resulting in an ‘invisible’ image. Using something like this: Has no e…
What is the difference between Servlet response methods addHeader and setHeader?
Can I use setHeader to set an new header? Or Do I need to addHeader first, then use setHeader method? Answer The documentation says that you can add multiple values to a particular header using the addHeader method, whereas an initial value would be overwritten if you use the setHeader method. In both cases a…
Decode base64Url in Java
https://web.archive.org/web/20110422225659/https://en.wikipedia.org/wiki/Base64#URL_applications talks about base64Url – Decode a modified Base64 for URL variant exists, where no padding ‘=’ will be used, and the ‘+’ and ‘/’ characters of standard Base64 are respectiv…
Simple Java name based locks?
MySQL has a handy function: SELECT GET_LOCK(“SomeName”) This can be used to create simple, but very specific, name-based locks for an application. However, it requires a database connection. I have …