I’m a beginner in Java. I have a method as below: public void time_filter(Long t1, Long t2){ NavigableMap time_map = new TreeMap(); …
Tag: java
How can I apply aop on a whole package except one subpackage
Assuming my current package structure in a spring projects as : com.stackoverflow |- service |- entities |- controllers |- package1 |- package2 |-util How can I apply an aspect to all the …
zip function for Java
Is there some standard API or established third party library (I am thinking commons or Guava) that provides in Java the equivalent of zip or map vector function in languages like Ruby or Clojure? So the signature (for two collections) would be: where Pair would also be presumably defined in that library. I k…
Nested if-else behaviour without braces
Consider the following unformatted nested if-else Java code My question is: according to the Java language specifications, to what if does the else branch apply? By hand-reformatting and adding braces, which of these two is correct? Block 1: Block 2: Answer From the Java Language Specification: The Java progr…
Big O – O(log(n)) code example
Like the Big O notation “O(1)” can describe following code: What code can O(log(n)) describe? Another question: What solutions are there for “Big O problems” (what to do, when getting a lot of data as an input)? Answer Classic example: This will be: 2k = x → Applying log to both sides …
Junit Testing JNDI InitialContext outside the application server
Please help me to mock the above code. Hi Tom Anderson I tried the below code But its giving error as: Please help me to test the code i just want connection from JNDI datasource Answer The orthodox thing to do here would be to change you code so that the Context is injected into it (by a dependency injection
Identifying each field in Multiple File upload
When trying to upload multiple files with Struts 2 using ArrayList, how to identify each field? For example, if I have two file fields, File1 and File2 and on the client side, I choose to upload only File2, Struts 2 only creates one element in the list and I am not able to correctly map File1 as empty and Fil…
Storing integer as attribute in jsp
I want to pass an Integer value as an attribute in JSP. But when i try an error is returned. Could you tell me a method to store Integer numbers as attributes in JSP? I am getting a casting error saying parseInt() is not suited for handling objects. Answer request.getAttribute returns an Object. you need to c…
EXE4j Jar to exe error
I’m recently Java 7 update 21 JDK and i created java application with netbeans For distributing my jar i use Exe4j 4.5.2 Jar to exe. Now when i used Exe4j it creates exe but when i execute it it shows me error message. “The JVM could not be started. The maximum heap size (-Xmx) might be too large …
What’s the difference between Spring Data’s MongoTemplate and MongoRepository?
I need to write an application with which I can do complex queries using spring-data and mongodb. I have been starting by using the MongoRepository but struggled with complex queries to find examples or to actually understand the Syntax. I’m talking about queries like this: or the use of JSON based quer…