java

Comparing if two Date instances refer to the same day

I have two Java instances of java.util.Date and I have to find out if they refer to the same day. I can do this the hard way, taking the dates apart and compare the days, making sure the years match too. Since this is such a common problem, I expect there to be an easier solution to this problem. Thanks! ...

Simulate touch command with Java

I want to change modification timestamp of a binary file. What is the best way for doing this? Would opening and closing the file be a good option? (I require a solution where the modification of the timestamp will be changed on every platform and JVM). ...

How can I use an inner class instance from another inner class method ?

public class Ex7 { private int fld; private void meth(int val) { fld = val; System.out.println(" meth() -> fld = " + fld); } public class Ex7Inner1 { void operateOnFld() { fld = 12; } void operateOnMeth() { meth(10); } public void bar() { ...

Input Required for Message Passing?

Is message passing taking place when calling a function with no input? i.e. with: object.toString(); Am I passing a message to 'object'? This might vary between languages, but I'm specifically referring to Java. ...

Why does ServletContext#getRealPath("/") return a relative path?

I have the following snippet of code: String path = servletContext.getRealPath("/"); Now I got a bugreport from a user saying that the returned path is not an absolute path. The returned path is 'usr/local/...' instead of '/usr/local/...' , so getRealPath seems to be returning a relative path. I can see this, because the returned pat...

Is Java guaranteed to inline string constants if they can be determined at compile time.

Consider this case: public Class1 { public static final String ONE = "ABC"; public static final String TWO = "DEF"; } public Class2 { public void someMethod() { System.out.println(Class1.ONE + Class1.TWO); } } Typically you would expect the compiler to inline the ONE and TWO constants. However, is this behavior guarant...

Java http call returning response code: 501

I am having an issue with this error: **Server returned HTTP response code: 501 for URL: http://dev1:8080/data/xml/01423_01.xml** See this code: private static Map sendRequest(String hostName, String serviceName) throws Exception { Map assets = null; HttpURLConnection connection = null; Authenticator.se...

Problem with WATIJ.

I have logged in to a website by using WATIJ jar file in java. Now I want to get the page source (HTML code) of the webpage that appeared after login. I have IE instance already. ...

JmenuItem mouse pressed work but mouse clicked event does not work? why?

I was trying to create a mouse clicked event of a JmenuItem but it did not work but mouse pressed event works. what is the difference between clicked and pressed and why only pressed works here? ...

Compressing with Java Decompressing with PHP

I have a situation where a servlet is providing compressed data to a PHP script. I compress the data on the Java side no problem, but PHP seems unable to decompress. Here is the relevent code snippets Java Side: OutputStream o=response.getOutputStream(); GZIPOutputStream gz=new GZIPOutputStream(o); gz.write(GridCoder.encode(rs,id...

Using log4j with inherited classes

I am instantiating a log4j object inside of a class which inherits most of the methods and attributes from a parent class. Right now I'm getting logging messages from the subclass only. How can I get logging messages to output in both the super class and subclass? EDIT: The way I am do the logging is that I have an instance variable i...

Where is the source code for <jdk>/jre/lib/deploy.jar?

Where is the source code for /jre/lib/deploy.jar? I have the source code for other jars like rt.jar (in /src.zip) but not deploy.jar. I need it to debug webstart. I'm using 1.6 on Windows if that makes a difference. ...

Is calling Java's Calendar.getTime() necessary to update the object?

I came across a comment in some java code that states that getTime() needs to be called to update the Calendar object. Is this true? I cannot find anything that says that this is necessary. Here's the code: Calendar cal = new GregorianCalendar(); cal.setFirstDayOfWeek(Calendar.SUNDAY); cal.set(2009, 9 - 1, 10, 2, 30); // Get Time needs...

How to interoperate between PC and camera from cell phone

Hi everyone!! My new project is to build an application to use the cell phone camera as the main camera from my PC. How can I do this kind of stuff? I thought of using bluetooth, but how my PC define the cell phone as the main camera? Best reguards. ...

How to Map unset property to value without getting NullPointerException in Dozer

Using Dozer to map two objects, I have: /** /* This first class uses the GXT (ExtJS) framework **/ Class1 extends BaseModelData { public int getId() { return (Integer)get("id"); } public void setId(int id) { set("id", id); } // more properties } Class2 { public int getId() { return i...

How to send parameters from a servlet

Hello, I am trying to use a RequestDispatcher to send parameters from a servlet. Here is my servlet code: protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String station = request.getParameter("station"); String insDate = request.getParameter("insDate"); ...

What does the org.apache.xmlbeans.XmlException with a message of "Unexpected element: CDATA" mean?

I'm trying to parse and load an XML document, however I'm getting this exception when I call the parse method on the class that extends XmlObject. Unfortunately, it gives me no ideas of what element is unexpected, which is my problem. I am not able to share the code for this, but I can try to provide more information if necessary. ...

Runtime configuration of a project without an IDE

Say i have a java project setup in eclipse. i have all the thirdparty jar's and reading the resources etc set in the eclipse IDE. ie all the classpath etc are set through the IDE Now if i want to launch my app from commandline. Can i get some hints/ links where i can undersand the configuration settings that can be done in Unix / windo...

Throttling method calls to M requests in N seconds

I need a component/class that throttles execution of some method to maximum M calls in N seconds (or ms or nanos, does not matter). In other words I need to make sure that my method is executed no more than M times in a sliding window of N seconds. If you don't know existing class feel free to post your solutions/ideas how you would im...

How to suspend current thread for 20 seconds in java?

How to suspend current thread for 20 seconds in java? ...