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 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?
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
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.
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?
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.
Having read this question In what order are the different parts of a class initialized when a class is loaded in the JVM? and the related JLS. I would like to know in more detail why for example having class Animal (superclass) and class Dog (subclass) as following:
class Animal
{
static{
System.out.println("This is Animal's static block speaking"):
}
{
System.out.println("This is Animal's instance block speaking");
}
class Dog{
static{
System.out.println("This is Dog's static block speaking");
}
{
System.out.println("This is Dog's instance block speaking");
}
public static void main (String [] args)
{
Dog dog = new Dog();
}
}
Ok before instantiating a class its direct superclass needs to be initialized (therefore all the statics variables and block need to be executed).
So basically the question is: Why after initializing the static variables and static blocks of the super class, control goes down to the subclass for static variables initialization rather then finishing off the initialization of also the instance member?
The control goes like:
superclass (Animal): static variables and static blocks
subclass (Dog): static variables and static blocks
superclass (Animal): instance variables and instance blocks
sublcass (Dog):instance variables and instance blocks
What is the reason why it is in this way rather than :
superclass -> static members
superclass -> instance members
subclass -> static members
sublcass-> instance members
When I create complex type hierarchies (several levels, several types per level), I like to use the final keyword on methods implementing some interface declaration. An example:
interface Garble {
int zork();
}
interface Gnarf extends Garble {
/**
* This is the same as calling {@link #zblah(0)}
*/
int zblah();
int zblah(int defaultZblah);
}
And then
abstract class AbstractGarble implements Garble {
@Override
public final int zork() { ... }
}
abstract class AbstractGnarf extends AbstractGarble implements Gnarf {
// Here I absolutely want to fix the default behaviour of zblah
// No Gnarf shouldn't be allowed to set 1 as the default, for instance
@Override
public final int zblah() {
return zblah(0);
}
// This method is not implemented here, but in a subclass
@Override
public abstract int zblah(int defaultZblah);
}
I do this for several reasons:
It helps me develop the type hierarchy. When I add a class to the hierarchy, it is very clear, what methods I have to implement, and what methods I may not override (in case I forgot the details about the hierarchy)
I think overriding concrete stuff is bad according to design principles and patterns, such as the template method pattern. I don't want other developers or my users do it.
So the final keyword works perfectly for me. My question is:
Why is it used so rarely in the wild? Can you show me some examples / reasons where final (in a similar case to mine) would be very bad?
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
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 !
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 aware that you can initialize an array during instantiation as follows:
String[] names = new String[] {"Ryan", "Julie", "Bob"};
Is there a way to do the same thing with an ArrayList? Or must I add the contents individually with array.add()?
Thanks,
Jonathan
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!
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?
I'm curious why the String.indexOf is returning a 0 (instead of -1) when asking for the index of an empty string within a string.
The Javadocs only say this method returns the index in this String of the specified string, -1 if the string isn't found.
System.out.println("FOO".indexOf("")); // outputs 0 wtf!!!
System.out.println("FOO".indexOf("bar")); // outputs -1 as expected
System.out.println("FOO".indexOf("F")); // outputs 0 as expected
System.out.println("".indexOf("")); // outputs 0 as expected, I think
Rather new to REST and Jersey, and I'm trying out some basic examples. I've got one particular question though, which I haven't really found an answer for yet (don't really know how to look for this): how would you go about storing/defining common services so that they are stateful and accessible to all/some resources?
For instance, a logger instance (Log4J or whatever). Do I have to manually initialize this and store it in the HttpSession? Is there a "best practice" way of doing this so that my logger is accessible to all/some resources?
Thanks a lot.
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
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?
Hello, recently I went through the inheritance concept.
As we all know, in inheritance, superclass objects are created/initialized prior to subclass objects. So if we create an object of subclass, it will contain all the superclass information.
But I got stuck at one point.
Do the superclass and the subclass methods are present on separate call-stack?
If it is so, is there any specific reason for same?
If it is not so, why they don't appear on same call-stack?
E.g.
// Superclass
class A {
void play1( ) {
// ....
}
}
// Subclass
class B extends A {
void play2( ) {
//.....
}
}
Then does the above 2 methods i.e play1( ) and play2( ) appear on separate call stack?
Thanks.
Greetings Stack Overflowers,
A while back, I was working on a program that hashed values into a hashtable (I don't remember the specifics, and the specifics themselves are irrelevant to the question at hand). Anyway, I had the following code as part of a "recordInput" method.
tempElement = new hashElement(someInt);
while(in.hasNext() == true)
{
int firstVal = in.nextInt();
if (firstVal == -911)
{
break;
}
tempElement.setKeyValue(firstVal, 0);
for(int i = 1; i<numKeyValues;i++)
{
tempElement.setKeyValue(in.nextInt(), i);
}
elementArray[placeValue] = tempElement;
placeValue++;
} // close while loop
} // close method
This part of the code was giving me a very nasty bug -- no matter how I finagled it, no matter what input I gave the program, it would always produce an array full of only a single value -- the last one.
The problem, as I later determined it, was that because I had not created the tempElement variable within the loop, and because values were not being assigned to elementArray[] until after the loop had ended -- every term was defined rather as "tempElement" -- when the loop terminated, every slot in the array was filled with the last value tempElement had taken.
I was able to fix this bug by moving the declaration of tempElement within the while loop. My question to you, Stackoverflow, is whether there is another (read: better) way to avoid this bug while keeping the variable declaration of tempElement outside the while loop.
(suggestions for better title and tags also appreciated)
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?
Suppose I have a big program that consists of hundreds of methods in it. And according to the nature of input the program flow is getting changed.
Think I want to make a change to the original flow. And it is big hassle to find call hierarchy/ references and understand the flow.
Do I have any solution for this within Eclipse? Or a plugin? As an example, I just need a Log of method names that is in order of time. Then I don't need to worry about the methods that are not relevant with my "given input"
Update : Using debug mode in eclipse or adding print messages are not feasible. The program is sooooo big. :)
I want to create a JSON object. I have tried the following
myString=new JSONObject().put("JSON", sampleClass).toString();
but mystring gives me {"SampleClass@170f98"}.
I also tried the following
XStream xsStream=new XStream(new JsonHierarchicalStreamDriver());
SampleClass sampleClass=new SampleClass(userset.getId(),userset.getUsername());
myString=xsStream.toXML(sampleClass);
It works but when i use getJSON in javascript to get myString it does not work.
Hello
I have some code that has generic references in it and my IBM RAD IDE will not compile the code, instead treating it as an error. I have checked the version of the JRE its pointing to across all the Enterprise Project's and it is 1.5 which I am told does support generics. Also I checked that all the libraries for WAS were pointing to the correct version and that the Compiler Compliance Level was set correctly (which it was at 5.0 and i changed it to 6.0 with no luck either)
Does anyone have any suggestions as to anything else I can try? I have issues like this with RAD all the time and I dont know about anyone else but they took eclipse and made it complicated and dysfunctional.