Skip to content

Tag: java

How to get last month/year in java?

How do I find out the last month and its year in Java? e.g. If today is Oct. 10 2012, the result should be Month = 9 and Year = 2012. If today is Jan. 10 2013, the result should be Month = 12 and Year = 2012. Answer Your solution is here but instead of addition you need to

amazon s3 upload file time out

I have a JPG file with 800KB. I try to upload to S3 and keep getting timeout error. Can you please figure what is wrong? 800KB is rather small for upload. Error Message: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed. HTTP Status…

Java storing two ints in a long

I want to store two ints in a long (instead of having to create a new Point object every time). Currently, I tried this. It’s not working, but I don’t know what is wrong with it: And I’m getting the int values like so: Answer y is getting sign-extended in the first snippet, which would overw…

Cannot construct instance of – Jackson

I am using Jackson and I’m having problems, when I try to deserialize an Object I get the following error: I am having problems in the attribute: Could anyone help me? Answer You cannot instantiate an abstract class, Jackson neither. You should give Jackson information on how to instantiate MyAbstractCl…

RequestFocus in TextField doesn’t work

I use JavaFX 2.1 and I created GUI using FXML, in the controller of this GUI I added myTextField.requestFocus();. But I always get the focus in the other control. Answer At the time of initialize() controls are not yet ready to handle focus. You can try next trick: For tricky complex applications (like Pavel_…

jax ws getting client ip

I’m trying to retrieve the client IP with JAX-WS, I used: I get a NullPointerException in req, mc is not null. My question is which JAR to use for HttpServletRequest because I’m using a Java stand-alone application? Thanks Answer How to get the webservice client address for a jax-ws service depend…

Write and Read Cookies in different Applications

I have two applications running in Jboss, can I write a cookie in a application and read in another? For example, if I have two Servlets: – WriterCookieServlet on localhost:8080/Application1 – ReaderCookieServlet on localhost:8080/Application2 WriterCookieServlet: Then on ReaderCookieServlet I wan…

Is PriorityQueue a FIFO Queue?

PriorityQueue implements Queue, but is PriorityQueue a FIFO data structure like Queue? Answer From the Queue interface: Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner. Among the exceptions are priority queues, which order elements according to a supplied compara…