This is in the context of a local Processing program. I would like to run an external program to get some data. Is there a popen() or equivalent function I can use?
In an interview the interviewer asked me the following question: is it possible to serialize a singleton object? I said yes, but in which scenario should we serialize a singleton?
And is it possible to design a class whose object can not be serialized?
What do I write instead of "TheClass" to make this work? Or is there an alternative way to do it (possibly without making WithName and WithAge generic)?
class Item {
NeigborList<TheClass> neighbors;
}
class WithName extends Item { // here I want neighbors to be a NeighborList<WithName>
String name;
void someMethod() {
System.out.println(neighbors.nearestTo(this).name);
}
}
class WithAge extends Item { // here I want neighbors to be a NeighborList<WithAge>
int age;
void someOtherMethod() {
System.out.println(neighbors.nearestTo(this).age);
}
}
Should there be any specific order in which I should write the following :
public static void main() ?
In other words, can I re-shuffle public,static,void in any order ?
Why or Why not ?
How would i call this function in my main?
private JFrame getMainpageframe1() {
if (mainpageframe1 == null) {
mainpageframe1 = new JFrame();
mainpageframe1.setSize(new Dimension(315, 306));
mainpageframe1.setContentPane(getMainpage());
mainpageframe1.setTitle("Shopping For Less: Main Page");
mainpageframe1.setVisible(true);
mainpageframe1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
return mainpageframe1;
}
public static void main(String[] args) {
//call that function to output the JFrame?
}
thanks
How do you handle clean up when the program receives a kill signal?
For instance, there is an application I connect to that wants any third party app (my app) to send a finish command. What is the best say to send that finish command when my app has been destroyed with a kill -9?
I got this thing i'm trying to solve:
I got a ListView created using Wicket ( 1.5 ) with a lot of elements and a scroll. When new items are available, the user is asked if he would like to refresh the list via a message backed by an AjaxLink:
public void onClick(AjaxRequestTarget ajaxTarget) {
/* do something ... */
ajaxTarget.addComponent(_list);
}
So on click the list gets reloaded and the scroll position is reset to zero. Is there any way i can call JavaScript before the list reloads the save the scroll position?
(I know how to get/save the scroll position ( .scrollTop() ) , i just don't know how to call a function right before AJAX ).
This has been asked several times for several languages but I can't get it to work.
I have a string like this
String str = "This is a string.\nThis is a long string.";
And I'm trying to replace the \n with <br /> using
str = str.replaceAll("(\r\n|\n)", "<br />");
but the \n is not getting replaced.
I tried to use this RegEx Tool to verify and I see the same result. The input string does not have a match for "(\r\n|\n)". What am i doing wrong ?
Hello,
I have a datetime field in mysql table and i am using JPA for persisting data but only date goes in database. Time always shows 00:00:00. What should i do?
I am not doing any manipulation with Date. All i do is to assign new Date() to a variable and store it in database.
What am i doing wrong?
public class Test {
public static void main(String[] args){
if (5.0 5) // (5.0<5) for both case it is going to else
System.out.println("5.0 is greater than 5");
else
System.out.println("else part always comes here");
/another sample/
if (5.0 == 5)
System.out.println("equals");
else
System.out.println("not equal");
}
}
can any one explain the first "if statement" why it always come to else part
Is a variable inside the main, a public variable?
public static void main(String[] args) {
.........
for(int i=0;i<threads.length;i++)
try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
long time=0;
....
}
i and time are they both public variables?
Of course if my reasoning is correct, also any variable belonging to a public method should be considered public.. am i right?
Thanks
Imagine you have a NB Platform application and you would like to use that application via some other app that you've created.
In essence, how can you learn how to start an application if you don't want to use the NB Platform or IDE. You'd somehow need to figure out the stuff that NB Platform does for you when it loads up a module.
hi,
this might be trivial (please forgive me for that)
but my eventual goal is to have a string like
def newline= 'C:\\www\web-app\StudyReports\\test.bat'
but my old line only have one '\',
i tried different ways of using the following
def newline=oldline.replaceAll(/\\/,'//')
but did not work at ...
could someone help me out.
Problem/Task:
Write an interface with one method and two classes that implement this interface.
Now write a main method with an array that holds an instance of each class. Using a for-each loop, invoke the method upon each item.
Is this an interview question? (I'm not sure if the author meant to post this as a question or was looking for an answer to the above.)
I'm working on a small sketch in processing where I am making a "clock" using the time functions and drawing ellipses across the canvas based on milliseconds, seconds and minutes. I'm using a for loop to draw all of the ellipses and each for loop is inside its own method. I'm calling each of these methods in the draw function. However for some reason only the first method that is called is being drawn, when ideally I would like to have them all being visibly rendered.
//setup program
void setup() {
size(800, 600);
frameRate(30);
background(#eeeeee);
smooth();
}
void draw(){
milliParticles();
secParticles();
minParticles();
}
//time based particles
void milliParticles(){
for(int i = int(millis()); i >= 0; i++) {
ellipse(random(800), random(600), 5, 5 );
fill(255);
}
}
void secParticles() {
for(int i = int(second()); i >= 0; i++) {
fill(0);
ellipse(random(800), random(600), 10, 10 );
background(#eeeeee);
}
}
void minParticles(){
for(int i = int(minute()); i >= 0; i++) {
fill(50);
ellipse(random(800), random(600), 20, 20 );
}
}
I have a few string problems that I need to put together for a complete homework assignment. They all work correctly by themselves, but when I put them together in the main function, the last one that finds the smallest word in a string gives an error. Anyone know why?
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
//Length of Word
String word1 = sc.next();
System.out.println(word1.length());
//Evens in one string odds in the other
String word2 = sc.next();
StringBuilder even = new StringBuilder();
StringBuilder odd = new StringBuilder();
for(int i = 0; i < word2.length(); i++){
if(i % 2 == 0){
even.append(word2.charAt(i));
}
else{
odd.append(word2.charAt(i));
}
}
System.out.println(even + " " + odd);
//Diminishing Suffix
String word3 = sc.next();
for(int j = 0; j < word3.length(); j++){
System.out.print(word3.substring(j, word3.length()) + " ");
}
System.out.printf("\n");
//Letter Replacement
String word4 = sc.next();
String word5 = sc.next();
String word6 = sc.next();
String word7 = word4.replace(word5, word6);
System.out.println(word7);
//How many times x appears in xstring
String word8 = sc.next();
String word9 = sc.next();
int index = word8.indexOf(word9);
int count = 0;
while (index != -1) {
count++;
word8 = word8.substring(index + 1);
index = word8.indexOf(word9);
}
System.out.println(count);
System.out.println();
//Lexicographically smallest word
String Sentence = sc.nextLine();
String[] myWords = Sentence.split(" ");
int shortestLengths, shortestLocation;
shortestLengths=(myWords[1]).length();
shortestLocation=1;
for (int i = 1; i <myWords.length; i++) {
if ((myWords[i]).length() < shortestLengths) {
shortestLengths=(myWords[i]).length();
shortestLocation=i;
}
}
System.out.println(myWords[shortestLocation]);
}
}
Talking about the lexicographically smallest one
There's a class I'm working with that has a display() function that prints some information to the screen. I am not allowed to change it. Is there a way to "catch" the string it prints to the screen externally?
Hi All.
I'm implementing a web based document management system and I'd like to implement ACLs in my system.
My formal requirements are hierarchal permissions (documents inherit permissions from their folders) user groups (users can dynamically create groups and associate users with groups). Such groups can have permissions on objects in the system.
My code will query permission on objects in two cases:
1. Manipulating a single document
2. Listing all documents where a manipulation is possible
The latter requirement seems the achilles heel for Spring Security ACLs (their method seems likely to incur multiple DB hits for each document I manage)
Anyone know of another ACL implementation?
Thanks!
Hello there,
I am try to find out how to enforce uniqueness in fields other than the unique id.
Example:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User implements IsSerializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String name;
@Persistent
private String email; // <= I want this to be unique as well
}
In the example above, how can I enforce uniqueness of the email value across the database?
Daniel
Hello,
I have an object of CalendarEntry
I know that http://www.google.com/calendar/feeds/[email protected]/allcalendars/full is the feed url of all calendars
but how I can get this feed url from CalendarEntry instance?
Because I wanna post a new entry in a specified calendar and I need this url.
Thanks!
I am testing the performance of a data streaming system that supports continuous queries.
This is how it works:
- There is a polling service which sends data to my system.
- As data passes into the system, each query evaluates based on a window of the stream at the current time.
- The window slides as data passes in.
My problem is this, when I add more queries to the system, I should expect the throughput to decrease because it can't cope the data rate.
However, I actually observe an increase in throughput.
I can't understand why this is the case and I am guessing that it's something to do with the way the JVM allocates CPU, memory etc.
Can anyone shed any light to my problem?
I have a cookie that is formatted like partA:partB. The colon is not escaped in any fashion. I need to read this cookie in a JSP script, and request.getCookies() is only returning partA. I can't change the cookie because it is used in multiple applications, and fixing the cookie would break production code. Any ideas how I can read the full value of this cookie?
I need to setup LookAndFeel Files in JDK 1.6.
I have two files:
napkinlaf-swingset2.jar
napkinlaf.jar
How can I set this up and use it?
I would like a GTK look and feel OR Qt look and feel, Are they available?
Process p;
String line;
String path;
String[] params = new String [3];
params[0] = "D:\\prog.exe";
params[1] = picA+".jpg";
params[2] = picB+".jpg";
try {
p = Runtime.getRuntime().exec(params);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null)
System.out.println(line);
input.close();
} catch (IOException e) {System.out.println(" procccess not read"+e);}
i don't get any error, just nothing
in cmd.exe prog.exe is working fine
What to improve in order to make this code working?