|
Rajdeep.NET wrote:
B b=new B();
b.M1(50);
b.M2(100);
C c=new C();
c.Compare();
You create two instances. In the 'c' instance you do not set M1 or M2.
C c = new C();
c.M1(50);
c.M2(100);
c.Compare();
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Thanks Fly,
That was a silly mistake.
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
0. Don't you dare even think you are a java monkey, let alone a guru!
1. Read the documentation from Sun. It's ALL online and FREE, you have no excuse.
2. Though not reserved the Compare() method is part of the Comparable interface; read all about it here[^].
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Jack of all trades, master of none
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
??? Who ???
I are master of loadsatrades - plumber, painter, gardner, chef and occasional code-monk.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Nagy Vilmos wrote: ??? Who ???
'it'
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
i'm trying to read an xml file in java webservice,but the problem is even though the path is given it always searches the
"c:\programfiles\glassfish2\domains\domain1\config"
how can i give the path for the xml file in the project folder .
|
|
|
|
|
I want to know the restrictions imposed by a java applet on general programming with java. Basically I want to understand things we can do and things we cannot do...you know, where I might hit the silver lining?
PS: I am not so proficient in java technologies
|
|
|
|
|
This is the 'executive summary'
From memory and without bothering to search, a java applet cannot [should not?] go outside of the JVM except to 'phone home'. There is or should be no local IO.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
There is a java applet capable of reading the mac address. How do you think a browser application would be able to achieve this?
|
|
|
|
|
Getting your applet signed (such as by Verisign) can increase the things you are allowed to do by giving you a little more access to things outside of the 'sandbox'. Getting your applet signed does cost money...
|
|
|
|
|
Hello All,
I am using rxtxSerial library (import gnu.io.*; ) for my bridge application. Th example provided in the library's web site with nulltest.java employs only one serial port. It is powerful since it is threaded and detects incomming/outgoing streams.
However, I would like to bridge between servers so multiple ports will be employed. Do you heave any suggestion how to obtain it. The null test code is presented as follows.
import java.io.*;
import java.util.*;
import gnu.io.*;
public class nulltest implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static CommPortIdentifier saveportId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
static String messageString = "AT";
static OutputStream outputStream;
static boolean outputBufferEmptyFlag = false;
public static void main(String[] args) {
boolean portFound = false;
String defaultPort;
String osname = System.getProperty("os.name","").toLowerCase();
if ( osname.startsWith("windows") ) {
defaultPort = "COM5";
} else if (osname.startsWith("linux")) {
defaultPort = "/dev/ttyS0";
} else if ( osname.startsWith("mac") ) {
defaultPort = "????";
} else {
System.out.println("Sorry, your operating system is not supported");
return;
}
if (args.length > 0) {
defaultPort = args[0];
}
System.out.println("Set default port to "+defaultPort);
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(defaultPort)) {
System.out.println("Found port: "+defaultPort);
portFound = true;
nulltest reader = new nulltest();
}
}
}
if (!portFound) {
System.out.println("port " + defaultPort + " not found.");
}
}
public void initwritetoport() {
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.notifyOnOutputEmpty(true);
} catch (Exception e) {
System.out.println("Error setting event notification");
System.out.println(e.toString());
System.exit(-1);
}
}
public void writetoport() {
System.out.println("Writing \""+messageString+"\" to "+serialPort.getName());
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
}
public nulltest() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
}
public void run() {
initwritetoport();
try {
while (true) {
writetoport();
Thread.sleep(1000);
}
} catch (InterruptedException e) {}
}
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
int numBytes = 0;
try {
while (inputStream.available() > 0) {
numBytes = inputStream.read(readBuffer);
}
String result = new String(readBuffer);
System.out.println("Bytes read: "+numBytes+", Read contents: "+result);
} catch (IOException e) {}
break;
}
}
}
Kujtim
|
|
|
|
|
Sir, This is maheswara from A.P ...where can i get the code for band width analysis i.e it should record sent data and received data in a system with internet connection ....we have spent almost 10 days but no result plzzzzzzzz
|
|
|
|
|
Hey Maheshwara,
Nice to know that you are from A.P. But nobody (except indians) would know about that place. Well yes, and about your question, I think Google search does everything. Learn to use google to search for core programming resources sweetheart.
And how's Cheeranjivi? When is his next film gonna release?
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
Hello,
I heave an array of objects which each object has some common parameters, but also is to be characterized by adequate specific object. For each object I use 'objectType' parammeter to differentiate, then the rest, I tried as follows (using 'Object' type) but it is not working. Here is the complete simplified code:
class DiffObjectClasses{
public static void main(String [] args)
{
SerialObject so;
IPObject iob;
ObjectType ot[] = new ObjectType[3];
ot[0].objectID=1;
ot[0].objectType=1;
so=new SerialObject();
so.serialPortNo=21;
ot[0].objectContent=so;
ot[1].objectID=2;
ot[1].objectType=1;
so=new SerialObject();
so.serialPortNo=21;
ot[1].objectContent=so;
ot[2].objectID=3;
ot[2].objectType=2;
iob=new IPObject();
iob.host="localhost";
iob.port=2200;
ot[2].objectContent=iob;
System.out.println("----------------------------");
for(int indx=0; indx<ot.length;indx++)
{
System.out.println("ObjID:"+ot[indx].objectID);
System.out.println("ObjType:"+ot[indx].objectType);
switch(ot[indx].objectType)
{
case 1:
so=(SerialObject)ot[indx].objectContent;
System.out.println("Serial port no:"+so.serialPortNo);
break;
case 2:
iob=(IPObject)ot[indx].objectContent;
System.out.println("IP host:"+iob.host);
System.out.println("IP port:"+iob.port);
break;
}
}
}
}
class ObjectType{
int objectID;
int objectType;
Object objectContent;
}
class SerialObject{
int serialPortNo;
}
class IPObject{
String host="";
int port;
}
I've worked in C/C++, it was very simple by declaring 'void' member and then using implicit conversion as here but it sin't working in Java.
Kujtim
|
|
|
|
|
If you declare those last two classes like so:
class SerialObject extends ObjectType{
int serialPortNo;
}
class IPObject extends ObjectType{
String host="";
int port;
}
It may work.
You generally can't cast types to each other unless they somehow derive from each other in some way (unless it's a primitive type)
|
|
|
|
|
Hello,
I just tried your suggestion but it doesn't works. Even tried extends 'Object' since is more logical.
This is the error:
Exception in thread "main" java.lang.NullPointerException<br />
at DiffObjectClasses.main(DiffObjectClasses.java:9)
Thanks anyway,
Kujtim
modified on Friday, July 10, 2009 2:24 PM
|
|
|
|
|
Oh. I don't know then. But if I may ask, why are you doing it the C way?
If you're just going to store and print them, maybe I would do something like:
interface IPrintable
{
void Print();
}
class SerialObject implements IPrintable{
int serialPortNo;
public SerialObject(int portno)
{
serialPortNo = portno;
}
public void Print()
{
System.out.println("Serial port no:" + serialPortNo);
}
}
class IPObject implements IPrintable{
String host;
int port;
public IPObject(String host, int port)
{
this.host = host;
this.port = port;
}
public void Print()
{
System.out.println("IP host:" + host);
System.out.println("IP port:" + port);
}
}
And then make an array of IPrintable 's, of course.
|
|
|
|
|
Hello and thanks for responding,
there is a list of objects (class instances) which heave few common properties (at the moment two) but they belong to certain type regarding to access they provide. These specific properties seems more logical to be organized in a class, but the objects must be encapsulated together.
More simply, let these objects be servers, so the particular object Server[i], has the properties: id (Server[i].id), type and accessobject(which can be SerialObject or IPObject).
Good and similar example is ArrayList which enables storing objects, I then 'create' instances from these objects using implicit conversion. There also figures Object type as an argument, but here that is not working.
Kujtim
|
|
|
|
|
Ok I'm not disagreeing or something like that, but, well. Why do you use a custom "type" thing when Java already provides the means to see which class an object is an instance of?
|
|
|
|
|
Thanks again,
I am experienced C/C# programmer but will try that in Java.
Kujtim
|
|
|
|
|
The operator is in C# is called instanceof in Java (saves you some googling)
|
|
|
|
|
Hello,
I just solved the problem. It was because the instance was not created with ObjectType ot[] = new ObjectType[3]; so I had to add also the lines ot[0]=new ObjectType(); , ot[1]=new ObjectType(); and ot[2]=new ObjectType(); after that.
The working code looks as follows:
class DiffObjectClasses{
public static void main(String [] args)
{
SerialObject so;
IPObject iob;
ObjectType ot[] = new ObjectType[3];
ot[0]=new ObjectType();
ot[0].objectID=1;
ot[0].objectType=1;
so=new SerialObject();
so.serialPortNo=21;
ot[0].objectContent=so;
ot[1]=new ObjectType();
ot[1].objectID=2;
ot[1].objectType=1;
so=new SerialObject();
so.serialPortNo=21;
ot[1].objectContent=so;
ot[2]=new ObjectType();
ot[2].objectID=3;
ot[2].objectType=2;
iob=new IPObject();
iob.host="localhost";
iob.port=2200;
ot[2].objectContent=iob;
System.out.println("----------------------------");
for(int indx=0; indx<ot.length;indx++)
{
System.out.println("ObjID:"+ot[indx].objectID);
System.out.println("ObjType:"+ot[indx].objectType);
switch(ot[indx].objectType)
{
case 1:
so=(SerialObject)ot[indx].objectContent;
System.out.println("Serial port no:"+so.serialPortNo);
break;
case 2:
iob=(IPObject)ot[indx].objectContent;
System.out.println("IP host:"+iob.host);
System.out.println("IP port:"+iob.port);
break;
}
}
}
}
class ObjectType extends Object{
int objectID;
int objectType;
Object objectContent;
}
class SerialObject extends Object{
int serialPortNo;
}
class IPObject extends Object{
String host="";
int port;
}
Thanks for other suggestions!
|
|
|
|
|
|
ana_ochia wrote: we have this project at school
0. Look at the top message, we are adamantly against doing homework. In the long run it does not help you and it syre as hell does not help the profession.
1. Do not try and get your message to stand out with big text. When used for a whole message, it gives the hamsters at codeproject HQ a hernia.
2. Now, work out what you want to do. Write [on paper] how your program shall work and try out something. If you get stuck, come back and ask a programming question.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|