how are static method calls handled by the JVM? does it still allocate memory when a call is made? if yes, how does garbage collection treat this allocation after the method call?
I have a web service implemented as EJB. One of it's methods returns Map<String,String>. On client side I use php :
$client = new SoapClient($wsdl,array("cache_wsdl"=>WSDL_CACHE_NONE));
$result = $client->foo($params);
Everything works fine, but I would like $result-return to be an associative array. Now it looks like
array(10) { [0]=> object(stdClass)#46 (2) { ["key"]=> string(4) "key1"
["value"]=> string(4) "val1" } ....
I want
array(10) {"key1"=>"value1", "key2"=>"value2", .... }
The obvious solution is to iterate through this array and create a new array
$arr = array();
foreach ($result->return as $val)
$arr[$val->key] = $val->value;
But I wonder if there is a better way to get an assosicative array ?
Thanks in advance.
I can understand why network apps would use multiplexing (to not create too many threads), and why programs would use async calls for pipelining (more efficient). But I don't understand the purpose of AsynchronousFileChannel.
Any ideas?
Hello, I know the following code could extract whole texts of the docx document, however, I need to extract paragraph instead. Is there are possible way??
public static String extractText(InputStream in) throws Exception {
JOptionPane.showMessageDialog(null, "Start extracting docx");
XWPFDocument doc = new XWPFDocument(in);
XWPFWordExtractor ex = new XWPFWordExtractor(doc);
String text = ex.getText();
return text;
}
Any helps would much appreciated. I need this so urgently.
I am trying to move a JComponent say a label over a table.I am tracking this event using MouseMotionListener's mouseDragged method.This method perfectly helps me in tracking the item.Is there a way to track the mouse release after dragging is complete(.ie the dropping event).
tktLabel1.addMouseMotionListener(new MouseMotionListener()
{
public void mouseDragged(MouseEvent arg0)
{
tktLabel1.setBounds(tktLabel1.getX() + arg0.getX(),
tktLabel1.getY() + arg0.getY(), width, height);
}
public void mouseMoved(MouseEvent arg0)
{
}
});
Dear All:
Was wondering, which is correct:
Option One
class A {
public void methodOne() {
synchronized(this) {
modifyvalue
notifyAll()
}
}
public void methodTwo() {
while (valuenotmodified) {
synchronized(this) {
wait()
}
}
}
Option Two
class A {
public void methodOne() {
modifyvalue
synchronized(this) {
notifyAll()
}
}
public void methodTwo() {
while (valuenotmodified) {
synchronized(this) {
wait()
}
}
}
and why?
Thank you
Misha
In a JVM the memory is split into Method Area ,Stack ,Heap , Temp and Registry . what is String Local Memory ? Does this exists ? If so when does it gets allocated or assigned ?
Appropriate Usage of this ?
Thanks
I am writing a simple multithreaded socketserver and I am wondering how best to handle incoming connections:
create a new thread for each new connection. The number of concurrent threads would be limited and waiting connections limited by specifying a backlog
add all incoming connections into a queue and have a pool of worker threads that process the queue
I am inclined to go for option 2 because I really don't want to refuse any connections, even under high loads, but I am wondering if there are any considerations I should be aware of with accepting effectively unlimited connections?
Here's what I am looking to accomplish, I have a class that has an enum of some values and I want to subclass that and add more values to the enum. This is a bad example, but:
public class Digits
{
public enum Digit
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
}
}
public class HexDigits extends Digits
{
public enum Digit
{
A, B, C, D, E, F
}
}
so that HexDigits.Digit contains all Hex Digits. Is that possible?
I am a building a console Sudoku Solver where the main objective is raw speed.
I now have a ManagerThread that starts WorkerThreads to compute the neibhbors of each cell. So one WorkerThread is started for each cell right now. How can I re-use an existing thread that has completed its work?
The Thread Pool Pattern seems to be the solution, but I don't understand what to do to prevent the thread from dying once its job has been completed.
ps : I do not expect to gain much performance for this particular task, just want to experiment how multi-threading works before applying it to the more complex parts of the code.
Thanks
I need to split a text using the separator ". ". For example I want this string :
Washington is the U.S Capital. Barack is living there.
To be cut into two parts:
Washington is the U.S Capital.
Barack is living there.
Here is my code :
// Initialize the tokenizer
StringTokenizer tokenizer = new StringTokenizer("Washington is the U.S Capital. Barack is living there.", ". ");
while (tokenizer.hasMoreTokens()) {
System.out.println(tokenizer.nextToken());
}
And the output is unfortunately :
Washington
is
the
U
S
Capital
Barack
is
living
there
Can someone explain what's going on?
hi,
need to convert a pdf file to a doc file. I found different type of example to generate pdf file but not got pdf to doc.
please help me in this regard with good example or source code or guideline.
when looping, for instance:
for ( int j = 0; j < 1000; j++) {}; and I need to instantiate 1000 objects, how does it differ when I declare the object inside the loop from declaring it outside the loop ??
for ( int j = 0; j < 1000; j++) {Object obj; obj =}
vs
Object obj;
for ( int j = 0; j < 1000; j++) {obj =}
It's obvious that the object is accessible either only from the loop scope or from the scope that is surrounding it. But I don't understand the performance question, garbage collection etc.
What is the best practice ? Thank you
Suppose I have a string that contains '¿'. How would I find all those unicode characters? Should I test for their code? How would I do that?
I want to detect it to avoid sax parser exception which I am getting it while parsing the xml
saved as a clob in oracle 10g database.
Exception
javax.servlet.ServletException: org.xml.sax.SAXParseException: Invalid byte 1 of 1-byte UTF-8 sequence.
What complexity are the methods multiply, divide and pow in BigInteger currently? There is no mention of the computational complexity in the documentation (nor anywhere else).
I have the following code in struts.xml:
<interceptor-ref name="checkTabsStack">
<param name="tabName">availability</param>
</interceptor-ref>
and I want to access the parameter tabName in the interceptor routine, how do i do that? i tried
Map params = ActionContext.getContext().getParameters();
but params comes empty...
Thanks!
Hi,
I have an arraylist set up. I have input instuctions set up too, so that the user can enter one string, then one integer, then one string (the first name, the age, and the last name).
I need to sort the arraylist by the last name. The code I have entered so far is all under the main method:-
public static void main(String[] args) {
Name Name[] = new Name[50];
int count = 0;
for (int i=0; i<50; i++)
NewName[i] = new Name();
//ADD NEW TO ARRAYLIST NAME
String FName = JOptionPane.showInputDialog("first name");
int age = Integer.parseInt(JOptionPane.showInputDialog("age"));
String LName = JOptionPane.showInputDialog("last name");
NewName[count] = new Name(FName, age, LName);
count = count++;
}
//ITEMS SORT BY LAST NAME
//CODE FOR SORT GOES HERE
Right, this is from an older exam which i'm using to prepare my own exam in january. We are given the following method:
public static void Oorspronkelijk()
{
String bs = "Dit is een boodschap aan de wereld";
int max = -1;
char let = '*';
for (int i=0;i<bs.length();i++) {
int tel = 1;
for (int j=i+1;j<bs.length();j++) {
if (bs.charAt(j) == bs.charAt(i)) tel++;
}
if (tel > max) {
max = tel;
let = bs.charAt(i);
}
}
System.out.println(max + " keer " + let);
}
The questions are:
what is the output? - Since the code is just an algorithm to determine the most occuring character, the output is "6 keer " (6 times space)
What is the time complexity of this code?
Fairly sure it's O(n²), unless someone thinks otherwise?
Can you reduce the time complexity, and if so, how?
Well, you can. I've received some help already and managed to get the following code:
public static void Nieuw()
{
String bs = "Dit is een boodschap aan de wereld";
HashMap<Character, Integer> letters = new HashMap<Character, Integer>();
char max = bs.charAt(0);
for (int i=0;i<bs.length();i++) {
char let = bs.charAt(i);
if(!letters.containsKey(let)) {
letters.put(let,0);
}
int tel = letters.get(let)+1;
letters.put(let,tel);
if(letters.get(max)<tel) {
max = let;
}
}
System.out.println(letters.get(max) + " keer " + max);
}
However, I'm uncertain of the time complexity of this new code: Is it O(n) because you only use one for-loop, or does the fact we require the use of the HashMap's get methods make it O(n log n) ?
And if someone knows an even better way of reducing the time complexity, please do tell! :)
I am trying to create a database of users with connection between users (friends list).
There are 2 main tables: UserEntity (main field id) and FriendEntity with fields:
- initiatorId - id of user who initiated the friendship
- friendId - id of user who has been invited.
Now I am trying to fetch all friends of one particular user and encountered some problems with using subqueries in JDO here.
Logically the query should be something like this:
SQL: SELECT * FROM UserEntity WHERE EXISTS (SELECT * FORM FriendEntity WHERE (initiatorId == UserEntity.id && friendId == userId) || (friendId == UserEntity.id && initiatorId == userId))
or SELECT * FROM UserEntity WHERE userId IN (SELECT * FROM FriendEntity WHERE initiatorId == UserEntity.id) OR userId IN (SELECT * FROM FriendEntity WHERE friendId == UserEntity.id)
So to replicate the last query in JDOQL, I tried to do the following:
Query friendQuery = pm.newQuery(FriendEntity.class);
friendQuery.setFilter("initiatorId == uidParam");
friendQuery.setResult("friendId");
Query initiatorQuery = pm.newQuery(FriendEntity.class);
initiatorQuery.setFilter("friendId == uidParam");
initiatorQuery.setResult("initiatorId");
Query query = pm.newQuery(UserEntity.class);
query.setFilter("initiatorQuery.contains(id) || friendQuery.contains(id)");
query.addSubquery(initiatorQuery, "List initiatorQuery", null, "String uidParam");
query.addSubquery(friendQuery, "List friendQuery", null, "String uidParam");
query.declareParameters("String uidParam");
List<UserEntity> friends = (List<UserEntity>) query.execute(userId);
In result I get the following error:
Unsupported method while parsing expression.
Could anyone help with this query please?
I would like to know what is the best, fastest and easiest way to compare between 2-dimension arrays of integer.
the length of arrays is the same. (one of the array's is temporary array)
thanks.
I am relatively new to multi-threading and want to execute a background task using a Swingworker thread - the method that is called does not actually return anything but I would like to be notified when it has completed.
The code I have so far doesn't appear to be working:
private void crawl(ActionEvent evt)
{
try
{
SwingWorker<Void, Void> crawler = new SwingWorker<Void, Void>()
{
@Override
protected Void doInBackground() throws Exception
{
Discoverer discover = new Discoverer();
discover.crawl();
return null;
}
@Override
protected void done()
{
JOptionPane.showMessageDialog(jfThis, "Finished Crawling", "Success", JOptionPane.INFORMATION_MESSAGE);
}
};
crawler.execute();
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
}
}
Any feedback/advice would be greatly appreciated as multi-threading is a big area of programming that I am weak in.
Hello,
Im using Collections.sort() to sort a LinkedList whose elements implements Comparable interface, so they are sorted in a natural order. In the javadoc documentation its said this method uses mergesort algorithm wich has n*log(n) performance.
My question is if there is a more efficient algorithm to sort my LinkedList?
The size of that list could be very high and sort will be also very frequent.
Thanks!