I´ve been searching for it and I found Encog and Neuroph but I don´t know if any about them... I've to do a final project and I need a litle feedback from humans, sometimes google is not enough XD
I have about 4 threads. One thread keeps checking some data that the other thread is updating. The others are doing some processing in the background. All have been started at this point.
My question is when the checking thread sees that the data has not been updated yet I currently sleep for a little bit but is there any way for me to tell the system to back to executing the thread that does the updating?
That or is there any way I can put something like a listener on the data(a String) and once its updated an event will fire that will do what it needs to do?
I tried using yield() and it seemed to just keep returning to the thread I called yield() from.
Thanks
I'm writing a library that uses reflection to find and call methods dynamically. Given just an object, a method name, and a parameter list, I need to call the given method as though the method call were explicitly written in the code.
I've been using the following approach, which works in most cases:
static void callMethod(Object receiver, String methodName, Object[] params) {
Class<?>[] paramTypes = new Class<?>[params.length];
for (int i = 0; i < param.length; i++) {
paramTypes[i] = params[i].getClass();
}
receiver.getClass().getMethod(methodName, paramTypes).invoke(receiver, params);
}
However, when one of the parameters is a subclass of one of the supported types for the method, the reflection API throws a NoSuchMethodException. For example, if the receiver's class has testMethod(Foo) defined, the following fails:
receiver.getClass().getMethod("testMethod", FooSubclass.class).invoke(receiver, new FooSubclass());
even though this works:
receiver.testMethod(new FooSubclass());
How do I resolve this? If the method call is hard-coded there's no issue - the compiler just uses the overloading algorithm to pick the best applicable method to use. It doesn't work with reflection, though, which is what I need.
Thanks in advance!
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?
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 one Map that contains some names and numbers
Map<String,Integer> abc = new TreeMap<String,Integer>();
It works fine. I can put some values in it but when I call it in different class it gives me wrong order. For example:
I putted
abc.put("a",1);
abc.put("b",5);
abc.put("c",3);
some time it returns the order (b,a,c) and some time (a,c,b).
What is wrong with it? Is there any step that I am missing when I call this map?
i want to list files starting with a name like "Report" from a folder.
i found this in google to list all files but i don't how to list file starting with a name.
Thank you
File directory = new File("C:\\Users\\kiki\\Downloads");
File[] files = directory.listFiles();
for (int index = 0; index < files.length; index++)
{
//Print out the name of files in the directory
System.out.println(files[index].toString());
}
If we only need to graphically authorize a user,
view a few tables representation (from database),
ability to change data in the database visually
what tools to use to write such a web application that will run on Tomcat?
What framework allows to do that in the most straightforward, easy-to-manage and elegant way?
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
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 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?
I am trying to write a recursive method to print n number of asteriks in a line and create a new line at the end.
So, TriangleOps.line(5);
would print
*****
This is the code I wrote:
public static void line (int n){
if(n>0){
System.out.println("*");
line(n-1);
}}
instead it prints
*
*
*
*
*
with a lot of space at the end. Can anyone tell me how to remove the line breaks?
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 need to do a search in a map of maps and return the keys this element belong.
I think this implementation is very slow, can you help me to optimize it?.
I need to use TreeSet and I can't use contains because they use compareTo, and equals/compareTo pair are implemented in an incompatible way and I can't change that.
(sorry my bad english)
Map m = new TreeSet();
public String getKeys(Element element) {
for(Entry e : m.entrySet()) {
mapSubKey = e.getValue();
for(Entry e2 : mapSubKey.entrySet()) {
setElements = e2.getValue();
for(Element elem : setElements)
if(elem.equals(element)) return "Key: " + e.getKey() + " SubKey: " + e2.getKey();
}
}
}
Hi, I have some classes and I'm trying to fill the objects of this class. Here is what i've tried. (Question is at the below)
public class Team
{
private String clubName;
private String preName;
private ArrayList<String> branches;
public Team(String clubName, String preName)
{
this.clubName = clubName;
this.preName = preName;
branches = new ArrayList<String>();
}
public Team() {
// TODO Auto-generated constructor stub
}
public String getClubName() { return clubName; }
public String getPreName() { return preName; }
public ArrayList<String> getBranches() { return branches; }
public void setClubName(String clubName) { this.clubName = clubName; }
public void setPreName(String preName) { this.preName = preName; }
public void setBranches(ArrayList<String> branches) { this.branches = branches; }
}
public class Branch
{
private ArrayList<Player> players = new ArrayList<Player>();
String brName;
public Branch() {}
public void setBr(String brName){this.brName = brName;}
public String getBr(){return brName;}
public ArrayList<Player> getPlayers() { return players; }
public void setPlayers(ArrayList<Player> players) { this.players = players; }
}
//TEST CLASS
public class test {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String a,b,c;
String q = "q";
int brCount = 0, tCount = 0;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
Team[] teams = new Team[30];
Branch[] myBranch = new Branch[30];
for(int z = 0 ; z <30 ;z++)
{
teams[z] = new Team();
myBranch[z] = new Branch();
}
ArrayList<String> tmp = new ArrayList<String>();
int k = 0;
int secim = Integer.parseInt(input.readLine());
while(secim != 0)
{
if(k!=0)
secim = Integer.parseInt(input.readLine());
k++;
switch(secim)
{
case 1 :
brCount = 0;
a = input.readLine();
teams[tCount].setClubName(a);
b= input.readLine();
teams[tCount].setPreName(b);
c = input.readLine();
while(c.equals(q) == false)
{
if(brCount != 0)
{c = input.readLine();}
if(c.equals(q)== false){
myBranch[brCount].brName = c;
tmp.add(myBranch[brCount].brName);
brCount++;
}
System.out.println(brCount);
}
teams[tCount].setBranches(tmp);
for(int i=0;i<=tCount;i++ ){
System.out.print("a :" + teams[i].getClubName()+ " " + teams[i].getPreName()+ " ");
System.out.println(teams[i].getBranches());}
tCount++;
break;
case 2:
String src = input.readLine();//LATERRRRRRRr
}
}
}
}
The problem is one of my class elements. I have an arraylist as an element of a class.
When i enter:
AAA as preName
BBB as clubName
c
d
e as Branches
Then as a second element
www as preName
GGG as clubName
a
b as branches
The result is coming like:
AAA BBB c,d,e,a,b
GGG www c,d,e,a,b
Which means ArrayList part of the class is putting it on and on. I tried to use clear() method but caused problems. Any ideas.
Hi Experts,
I want to write "Arabic" in the message resource bundle (properties) file but when I try to save it I get this error:
"Save couldn't be completed
Some characters cannot be mapped using "ISO-85591-1" character encoding. Either change encoding or remove the character ..."
Can anyone guide please?
I want to write:
global.username = ??? ????????
How should I write the Arabic of "username" in properties file? So, that internationalization works..
BR
SC
Good Morning - it is school assignment, I am not asking for any source code (if you can provide any pesudo code it would be awesome).
Here is the problem :(
I have to create a term frequency table. It is not pure TF, I just need to count the words and write down.
I know basic steps to do it
1 - extract all terms (I can do it with file reader)
2 - remove repeating terms (I can do it with TreeMap)
The output of 2nd step would be
Niga, ponga, dinga, bitlo, etc.
3 - Now I have to see if there is any word in current file from above terms or not, if yes then I will count.
Now this is my problem, I stucked on step 3 :(
I have some idea how to count words with TreeMap (treemap.containskey etc.) but it would be global count not local count for each file :(
Any pseudo code?
Writing generated PDF (ByteArrayOutputStream) in a Servlet to PrintWriter.
I am desperately looking for a way to write a generated PDF file to the response PrintWriter.
Since a Filter up the hierarchy chain has already called response.getWriter() I can't get response.getOutputStream().
I do have a ByteArrayOutputStream where I generated the PDF into. Now all I need is a way to output the content of this ByteArrayOutputStream to the PrintWriter. If anyone could give me a helping hand would be very much appreciated!
I use setLayout (null) and I'm trying to place the buttons and textfield places I know by x, y
The problem when I run the program no matter what software (Eclipse, bluej)
I need to run on the panel with the mouse until I stand on the position of the button and I can see it.
When I find the textfield, it is small and only when I start writing it became the size I set it
Does anyone know how to solve it?
J2EE has ServletRequest.getParameterValues().
On non-EE platforms, URL.getQuery() simply returns a string.
What's the normal way to properly parse the query string in a URL when not on J2EE?
public static MySingleton getInstance() {
if (_instance==null) {
synchronized (MySingleton.class) {
_instance = new MySingleton();
}
}
return _instance;
}
1.is there a flaw with the above implementation of the getInstance method?
2.What is the difference between the two implementations.?
public static synchronized MySingleton getInstance() {
if (_instance==null) {
_instance = new MySingleton();
}
return _instance;
}
I have seen a lot of answers on the singleton pattern in stackoverflow but the question I have posted is to know mainly difference of 'synchronize' at method and block level in this particular case.