Using the stock Sun 1.6 compiler and JRE/JIT, is it a good idea to use Duff's Device to unroll a loop? Or does it end up as code obfuscation with no performance benefit.
The toArray method in ArrayList , Bloch uses both System.arraycopy and Arrays.copyOf to copy an array .
public <T> T[] toArray(T[] a) {
if (a.length < size)
// Make a new array of a's runtime type, but my contents:
return (T[]) Arrays.copyOf(elementData, size, a.getClass());
System.arraycopy(elementData, 0, a, 0, size);
if (a.length > size)
a[size] = null;
return a;
}
How to compare these two copy method , when to use which ? Thanks.
Is there a way to set DPI in swing ? For the whole application ? And if there is how do I set it to the value of system DPI ?
I guess there must be a way to do it as I mentioned this feature must have benn added to NetBeans in some of latest versions...
Thank you for reading
I appreciate that anything that can be done done by a switch statment can be done by an if else statement.
But are there stylistic rules for when one should use the switch rather than if else statment.
In my application I use Jersey REST to serialize complex objects. This works quite fine. But there are a few method which simply return an int or boolean.
Jersey can't handle primitive types (to my knowledge), probably because they're no annotated and Jersey has no default annotation for them. I worked around that by creating complex types like a RestBoolean or RestInteger, which simply hold an int or boolean value and have the appropriate annotations.
Isn't there an easier way than writing these container objects?
Hi,
I'm using Apache XML-RPC 3.1.2 to talk to an online-service. They have something special, they need a hash over the whole XML with a secret key for some kind of security, like this:
String hash = md5(xmlRequest + secretKey);
String requestURL = "http://foo.bar/?authHash=" + hash;
So I need the XML-request like this:
<?xml version="1.0"?>
<methodCall>
<methodName>foo.bar</methodName>
<params>
<param>
<value><struct>
<member><name>bla</name>
<value><int>1</int></value>
</member>
<member><name>blubb</name>
<value><int>2</int></value>
</member>
</struct></value>
</param>
</params>
</methodCall>
But how do I get this String-representation of the XMLRPC-Request with the lib Apache XML-RPC?
GUI
i am trying to use JSpinner but as you can see from the attached image that it looks bad.
i am on windows 7. i was wondering if anyone knows how to make it look good?
just for clarity. bad means the edges dont line up and good means the spin control edges line up correctly.
thank you.
EDIT: maybe there is no cure for this? because i checked site and all their examples look like this!
Hi,
I came across PECS (short for Producer extends and Consumer super) while reading on Generics.
Can someone explain me how to use PECS to resolve confusion between extends and super?
Thanks in advance !
I'm using the .startsWith() filter in a JDOQL query but it's case sensitive.
So startsWith("ab") doesn't return "Abc" result and so on.
Will I need to use a SQL query to avoid this ?
I am go through a socket program. In that printStackTrace is caught by the catch block.
Actully what it is?
catch(IOException ioe)
{
ioe.printStackTrace();
}
I am unaware of it. For what they are used?
Hi there,
I'd like to have your expert explanations about an architectural question. Imagine a Spring MVC webapp, with validation API (JSR 303). So for a request, I have a controller that handles the request, then passes it to the service layer, which passes to the DAO one.
Here's my question. At which layer should the validation occur, and how ?
My though is that the controller has to handle basic validation (are mandatory fields empty ? Is the field length ok ? etc.). Then the service layer can do some tricker stuff, that involve other objets. The DAO does no validation at all.
BUT, if I want to implement some unit testing (i.e. test layers below service, not the controllers), I'll end up with unexpected behavior because some validations should have been done in the Controller layer. As we don't use it for unit testing, there is a problem.
What is the best way to deal with this ? I know there is no universal answer, but your personal experience is very welcomed.
Thanks a lot.
Regards.
I have following code running perfectly. It filter records based on single parameter.
public List<Orders> GetOrders(String email)
{
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Orders.class);
query.setFilter("Email == pEmail");
query.setOrdering("Id desc");
query.declareParameters("String pEmail");
query.setRange(0,50);
return (List<Orders>) query.execute(email);
}
Now i want to filter on multiple parameters. sdate and edate is Start Date and End Date.
In datastore it is saved as Date (not String).
public List<Orders> GetOrders(String email,String icode,String sdate, String edate)
{
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Orders.class);
query.setFilter("Email == pEmail");
query.setFilter("ItemCode == pItemCode");
query.declareParameters("String pEmail");
query.declareParameters("String pItemCode");
.....//Set filter and declare other 2 parameters
.....//
......
query.setRange(0,50);
query.setOrdering("Id desc");
return (List<Orders>) query.execute(email,icode,sdate,edate);
}
Any clue?
Consider the following code:
while(true) {
someFunction();
Thread.sleep(1000);
}
What I want is that, someFunction() be called once every 10 seconds. But this is not the case. It is being called every second. I tried Thread.wait(1000), but even that doesnt help. I removed of the while part, just kept the body, and at the end wrote :
Thread.start();
But it throwed an exception. Is there any other solution to this?
i have the following class:
public class NewGameContract {
public boolean HomeNewGame = false;
public boolean AwayNewGame = false;
public boolean GameContract(){
if (HomeNewGame && AwayNewGame){
return true;
} else {
return false;
}
}
}
when i try to use it like so:
if (networkConnection){
connect4GameModel.newGameContract.HomeNewGame = true;
boolean status = connect4GameModel.newGameContract.GameContract();
switch (status){
case true:
break;
case false:
break;
}
return;
}
i am getting the error: incompatible types found: boolean required: int on the following switch (status) code.
what am i doing wrong please?
I am trying to download a file from Sharepoint 2007 sp2 document library using GetItem method of the Copy webservice. I am facing the following issues :
In the local instance ( Windows Vista ) I can save only 10.5 Kb of any file. The webservice is returning only 10.5 Kb of data for any file.
On the production server, I am able to List the documents using some credentials but when I am trying to download a document using the same credentials I get a 401 : Unauthorized message. I can download the document using the Sharepoint website successfully.
Hi,
I am trying to do a conversion of a String to integer for which I get a NumberFormatException. The reason is pretty obvious. But I need a workaround here. Following is the sample code.
public class NumberFormatTest {
public static void main(String[] args) {
String num = "9.18E+09";
try{
long val = Long.valueOf(num);
}catch(NumberFormatException ne){
//Try to convert the value to 9180000000 here
}
}
}
I need the logic that goes in the comment section, a generic one would be nice. Thanks.
i am triying to write a web based proxy site on google app engine.Displaying the first page of entered url was fairly simple urlFetching api but i am unable to figure out how to proxify the links and requests origionating from this newly displayed page.
How should I go about implementing a method that gets a String composed of Latin characters to translate it into a String composed of a different set of characters, let's say Cyrillic.
Contrary to Code Contracts in C#, in JML Code Contracts are just text that's used in the form of comments in the header of a method. Wouldn't it be better to have them exposed as Annotations, then? That way even when compiling the information would persist on the .class's metadata, contrary to comments, that get erased.
Am I missing something?
Thanks
Hello,
I was wondering which libraries or API's would be useful in this. what im aiming for is to be able to type a command into a prompt and then specify which computer(out of all of them that are networked together) to execute that command on. the second part is i want to be able to see that command execute and the result on the computer that was specified.
for example if i enter "firefox www.google.com, desktop2" i want to be able to see the window open on the monitor of that computer. Do you understand what im trying to do? any help is appreciated.
Thanks, Morpheous
public abstract class Master
{
public void printForAllMethodsInSubClass()
{
System.out.println ("Printing before subclass method executes");
}
}
public class Owner extends Master {
public void printSomething () {
System.out.println ("This printed from Owner");
}
public int returnSomeCals ()
{
return 5+5;
}
}
Without messing with methods of subclass...is it possible to execute printForAllMethodsInSubClass() before the method of a subclass gets executed?
Thus the structure is something like this:
OasisReportMessagePayloadRTOReport_ItemReport_Data
Under report data it's broken into categories:
>>Zone
>>Type
>>Value
>>Interval
What I need to do is:
Get the value if the type is equal to 'myType' and the interval value is the LARGEST.
So an example of the xml might be (under report_data):
OasisReport
MessagePayload
RTO
REPORT_ITEM
REPORT_DATA
<zone>myZone1</zone> -- This should be the same in all reports since I only get them for 1 zone
<type>myType</type> --This can change from line to line
<value>12345</value>--This changes every interval
<Interval>122</Interval> -- This is essentially how many 5 minute intervals have taken place since the beginning of a day, finding the "max" lets me know it's the newest data.
Thereby I want to find stuff of "MyType" for the "max" interval and pull the Value (into a string, or a double, if not I can convert from string.
Can someone help me with this task?
Thanks!
Note: I've used Xpath to handle things like this in the past, but it seems outlandish for this... as it's SO complex (since not all the reports live in the same report_item, and not all the types are the same in each report)
Assign the following 25 scores to a one dimensional int array called "temp"
34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,66
Move the scores to a 2 dimensional int array called "scores" row wise
-- meaning the first 5 scores go into row 0 etc