|
i want to save a message structure and it's score to a data structure. but some of data structures are repetitious.i want to use two dimensional collection with duplicate key which collection can help me?
thanks,
|
|
|
|
|
It's difficult to know which one is best for you, but the Collections tutorial[^] has some good information.
Veni, vidi, abiit domum
|
|
|
|
|
To solve this you can map to every message ID as key to a list of values.
Like : Map<string, list<string="">>
|
|
|
|
|
Have a Map with Elements <Key,List<MessageStructure,Score>>.
|
|
|
|
|
Hi,
i want to send message for other node's neighbors in peersim and i write protocol for node to do that for this job i send and receive messages using protocol's send and receive methods. an agent to send a message to her neighbor call put method of neighbor to do that .is it correct or no?
thanks,
it's my code for send and receivemessage.
public void clearinbix()
{
inbox.clear();
}
public void clearoutbox(){
outbox.clear();
}
protected ArrayList<Message> getIncomingMessage()
{
ArrayList<Message> inmsg=(ArrayList<Message>)inbox.clone();
tempMessages.addAll(inmsg);
clearinbix();
return inmsg;
}
public void putMessage(Message msg)
{
inbox.add(msg);
}
protected void sendOutGoingMessage(Message msg,Node node)
{
msg.setSource(node);
outbox.add(msg);
}
public ArrayList<Message> getMessages()
{
ArrayList<Message> outmsg=(ArrayList<Message>)outbox.clone();
clearoutbox();
return outmsg;
}
modified 20-Sep-13 0:18am.
|
|
|
|
|
|
yes i study documentation but there is no example that show this way of message passing is correct or not correct. i want to know my code do message passing though the simulation or i pass message directly between nodes.
thanks,
|
|
|
|
|
Then you need to test your code; we cannot tell you whether it is correct or not.
Veni, vidi, abiit domum
|
|
|
|
|
How can I select the check box and press the submit bottom and only search for the selected check box option.?
|
|
|
|
|
No idea whatsoever, provide a proper explanation of your problem. Also, your title is "Php", so what does this have to do with Java?
Anf finally, please do not put your question in bold, this is considered rude.
Veni, vidi, abiit domum
|
|
|
|
|
Is your question related to java or php?
|
|
|
|
|
package exam804;
class Base
{
public static void foo(Base bObj)
{
System.out.println("In Base.foo()");
bObj.bar();
}
public void bar()
{
System.out.println("In Base.bar()");
}
}
class Derived extends Base
{
public static void foo(Base bObj)
{
System.out.println("In Derived.foo()");
bObj.bar();
}
public void bar()
{
System.out.println("In Derived.bar()");
}
}
class OverrideTest
{
public static void main(String[] args)
{
Base bObj = new Derived();
bObj.foo(bObj);
}
}
why the output is
"In Base.foo() In Derived.bar()" and not
"In Derived.foo() In Derived.bar()" ?
|
|
|
|
|
Why is foo declared as static ?
Veni, vidi, abiit domum
|
|
|
|
|
i don't know .i take this question from exam
|
|
|
|
|
Asaf Shay wrote:
i don't know .i take this question from
exam
However that is the clue as to the answer to the question.
|
|
|
|
|
You do not need to create the instance into base class. If you have base class, leave it, every class, which extends the base class as father class makes instances to it automatically. All you need is to put "super" modifier, if u need to call any function from your base class.
I suggest you to do like this in this case:
public class OverrideTest{
public static void main(String[] args){
Derived dObj = new Derived();
dObj.foo();
}
}
public class Derived extends Base{
public void foo(){
System.out.println("In Derived.foo()");
super.foo();
}
}
public class Base{
public void foo(){
System.out.println("In Base.foo()");
}
}
Now your output will be:
"In Derived.foo()"
"In Base.foo()"
You do not need to use this:
Base bObj = new Derived();
If You want to call the foo() method of Base class directly from yor Main class, remove the foo() method from your Derived class. In this case, the foo() method will be called from Base class automatically.
modified 19-Sep-13 9:53am.
|
|
|
|
|
this question is from exam .so i don't want to make the code better or different . i only want to know what i ask .
|
|
|
|
|
שלום אסף --
אלה התיקונים שצריך להכניס כדי שהתוצאה תראה כפי שרצית
1] Derived bObj = new Derived() ;
2] class Derived extends Base
public static void foo(Derived bObj)
אני חושב שהתוצאה הלא נכונה נגרמת בגלל "דריסה" לא נכונה של המחלקה היורשת
|
|
|
|
|
foo() in Base class is declared as Static. Therefore it is not belonged to specific object but common for all objects.
bObj is an object of Base class, therefore it will call foo() in Base class, because foo() is Static.
|
|
|
|
|
To explain that, take a look at what is executed and why.
First of all, you create a new Derived-Instance as an instance of Base.
Take a look at how you call the static method foo():
You dont access it in a static way (to use exact the phrase the compiler will warn you with) - which would be Base.foo() or Derived.foo() - but you call it on an instance.
As mentioned, bObj is an instance of Base (because you declared it as that) and thus the static Method Base.foo() is called, which prints the "In Base.foo()"-Part of your output.
If you declared it as an instance of Derived, the static method Derived.foo() would have been called there.
To explain the part "In Derived.bar()" take a look at what is called next:
In Base.bar() you call bObj.bar();
bObj was instantiated with new Derived(), so the method bar() on that object is overriden with the implementation in Derived, which prints then "In Derived.bar()".
I hope that explains inheritance a bit better.
ab
|
|
|
|
|
|
i'm still new to java, but i want to create a java application for mobile phones, which will perform the following functions for sending sms online
get Username and password of the user
Message Sender ID,
Recipient numbers or select from contact list
the message
then the send button which will make use of sms API
|
|
|
|
|
Please use Google to do some research first. It is not possible to provide all this information in a technical forum.
Veni, vidi, abiit domum
|
|
|
|
|
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class server extends Frame implements ActionListener, Runnable
{
Image Icon = Toolkit.getDefaultToolkit().getImage("hi.gif");
ServerSocket ss;
Socket s;
BufferedReader br;
BufferedWriter bw;
TextField text;
Button sendBut, exitBut;
List list;
public server(String m) // class constructor
{
super(m);
setSize(300, 130);
setLocation(0,0);
setIconImage(Icon);
setResizable(false);
setBackground(new Color(192, 192, 192));
this.setLayout(new GridLayout(2, 1));
Panel panels[] = new Panel[2];
panels[0] = new Panel();
panels[1] = new Panel();
panels[0].setLayout(new BorderLayout());
panels[1].setLayout(new FlowLayout(FlowLayout.LEFT));
sendBut = new Button("Send");
exitBut = new Button("Exit");
sendBut.addActionListener(this);
exitBut.addActionListener(this);
list = new List();
list.addItem("Server up & Listening on port plz wait...");
text = new TextField(25);
panels[0].add(list);
panels[1].add(text);
panels[1].add(sendBut);
panels[1].add(exitBut);
add(panels[0]);
add(panels[1]);
setVisible(true);
try
{
ss = new ServerSocket(1053);//some port number, better be above 1000
s = ss.accept();
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
bw.write("Hi! ASL plz??");
bw.newLine();
bw.flush();
Thread th;
th = new Thread(this);
th.start();
}catch(Exception e){}
}
public void run()
{
while (true)
{
try
{
list.addItem(br.readLine());
}catch (Exception e){}
}
}
public static void main(String arg[])
{
// create an object instance
// by sending the title as a parameter
new server("Server Applicaton");
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource().equals(exitBut))
System.exit(0);
else
{
try
{
bw.write(text.getText());
bw.newLine();bw.flush();
text.setText("");
}catch(Exception x){}
}
}
}
|
|
|
|
|
How would I get the JSpinner value into database?,
the value is in alphanumeric
Like
1month
2month
String[] monthStrings = {"1Month","3Month","6Month","1Year"};
SpinnerListModel monthModel = new SpinnerListModel(monthStrings);
JSpinner spinner = new JSpinner(monthModel);
|
|
|
|