|
Success or failure in what sense? Looking at the example code you have posted there is very little that can go wrong.
The convention in Java is that success of an operation like this is assumed and you can expect a byte array to be returned: if anything goes wrong and the operation cannot be completed successfully, an exception is thrown. This may be a checked or an unchecked exception. There is a lot of debate over which of these is better, and I have no desire to open that debate up here (we'll be here forever while people argue backwards and forwards). Lets just say that if the operation fails, an exception is thrown and the type of exception tells you what went wrong. The calling method then catches the exception and responds accordingly.
In other words, your method returns an intialised byte array. If the initialisation of the byte array fails, throw an exception indicating why it failed. I can't tell you what exception would be best because I don't know what you expect to go wrong from the example code you posted.
You certainly could make it work by returning a class containing the byte array and a success/failure flag but this is not the preferred way of doing it in Java.
|
|
|
|
|
This very very simplified part of the large project I am developing. It will manage (register, unregister, list, ...) clients to listen/write at serial(COM) and TCP/IP. So the byte array is actually stream that commes(input arg) and goes(returned by function) by the so called "bridge" I am developing. Bytes of the stream contain the info from / to the requester.
Hope this is more clear.
Kujtim
|
|
|
|
|
In that case, I would definitely use an exception to indicate failure. Personally I would use a checked exception in this case (puts on tin hat and runs for cover from the "I hate checked exceptions" brigade) but YMMV.
Returning a success indicator is a very C way of doing things. Using a class as an equivalent of a struct to hold the byte array and a yes/no success flag is the result of trying to force C coding practices onto Java, which is why it feels clumsy and inelegant.
|
|
|
|
|
The remote user issues registration request from the GUI. For that request we build a stream which contains all the details. It is executed on the host module, if succeeds it receives the answer upon success, if not it receives failure message stream. We defined dedicated PROTOCOL for this.
Any failure is catched and handled by try/catch internally. But the remote objects needs to communicate between, thus the protocol between them.
Kujtim
modified on Monday, July 27, 2009 9:42 AM
|
|
|
|
|
Well, I thought I understood your problem, but now I'm confused. It sounds as if you are passing data cross-process using a custom protocol. If it's a dedicated protocol that you have designed yourself, you are free to pass data in whatever format you want. I'm not sure what that has to do with returning data from Java method calls and I'm not sure what answer you're expecting to get from this forum so I will bow out at this point.
|
|
|
|
|
Am I right that what you require is that any change to the stored data is propogated back up the line to anyone interested? If so, then this sounds more like a subscribe/publish pattern.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
DOes this form includes question regarding javascripts??:S
|
|
|
|
|
|
Beat me to it.
Howeever javascript is a sub-set of java. [damned I can't keep a straight face ]
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I know JAva != javascript but there is no form for asking about js so i thought may be here thanks anyways
|
|
|
|
|
Don't worry too much, but the Webbie people do more javascript and you'll get a better response there.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
hi
i have developed one application using openoffice and JOD convertor to convert a document in pdf. its working fine but problem is like i have to install openoffice on
my machine. is there other way using any opensource to convert a word document into pdf.
please dont suggest for POI and otehr api..because they not support fully conversion and we had tried it.
if u have any other suggestion please reply.
Thanks
|
|
|
|
|
After a quick Google search I found this[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Hi
Thanks for suggestion but i have already told u like i want to implement using openoffice and JOD convertor ...but now i have to install openoffice in my system..i want to avoid installation of Openoffice just need to include some jar file..
if is there any way...Thanks
|
|
|
|
|
JODConverter must connect to an OpenOffice.org instance in order to work. Typically this is done by connecting to the openoffice.org service on the local machine, hence needing openoffice installed. However, it can connect to an instance on another machine. Have a look at this[^].
If you don't want to connect to different machines and don't want to install open office locally then I suggest using a different API.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Thanks For Suggestion,I thought if i will go for openoffice and JOD convertor then i have to use OO service. it is mandatory thing right ? Thanks for Reply..
i already tried other api .if u have any idea about some other api please suggest me
|
|
|
|
|
Hi people,
I am very new to webservices. I been research on webservices and i understand it is something similar to an API.
I am working on a project that require the use of an GSM Modem. Its like a generic SMS Processing Agent that anyone can use it instead of building the capability into each application that needs it.
I am using an opensource sms library called "SMSlib".
So basically i need to create a web service that allows applications to interface with the processing agent to
-retrieve sms
-send sms
-keep a transaction log of communications with other applications.
So, can someone give me an advice on what kinda of methods do i need to have in my web service in order to achieve my goals.
Thanks
|
|
|
|
|
|
Hi i am new to java,
we have a project of taking that big one file and save the two classes inside two diffrent files, but i recieve an error
the error is :
D:\>java MonkiesDemo.java
Exception in thread "main" java.lang.NoClassDefFoundError: MonkiesDemo/ja
Caused by: java.lang.ClassNotFoundException: MonkiesDemo.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: MonkiesDemo.java. Program will exit
the project i have to make is :
http://www.abelski.com/moodle/mod/assignment/view.php?id=676[^]
http://pastebin.com/m4bdad8f7[^]
http://pastebin.com/m52543652[^]
Thanks
|
|
|
|
|
|
What was the problem. I guess you should call
javac MonkiesDemo.java instead of java MonkiesDemo.java
and then
java MonkiesDemo
Kujtim
|
|
|
|
|
I am doing a micro video application and am experiencing problems with my arraylist.
I have 2 separate frame. One is ListGameFrame and the other ListVideoFrame. When I add new games to the ListGameFrame and selects the ListGame option to view, I will also see my items from the videos section.
This is my coding for the ListGameFrame for adding games.
public void addGamesToList(ArrayList<Item> items)
{
this.clearDataFromTable();
for (Item i : items)
{
String GameID = i.getItemId();
String GameName = i.getTitle();
String[] rowData = {GameID,GameName};
((DefaultTableModel)tblGames.getModel()).addRow(rowData);
}
}
And this my coding for viewing the list of games via a class call VideoManager.
private static void readGameObjects()
{
ObjectInputStream in = openObjectInputFile(gameFileName);
if (in == null)
return;
try {
Item i = (Item)in.readObject();
while (i != null)
{
items.add(i);
i = (Item)in.readObject();
}
} catch (EOFException e) {}
catch (IOException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("Error in reading customer file");
} catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("Error in file format: Customer file");
} finally
{
try {
in.close();
} catch (IOException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
Sorry for the long codes as I do not know how to simplfy the problem I am facing now.
May I know if there is any specific problems in my coding which results the game list to also show the video list?
|
|
|
|
|
I dont think anybody's going to help you in that code. You should try Sun Developer's Network (SDN).
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
What are you playing at? If you don't understand it, because of your abundant lack of knowledge, then don't answer it with pure dribble.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Rajdeep,
You are stupid. Your answers are, at best, wrong and often plain misleading. Please, you obviously have no knowledge of java so don't damage other people's future by poluting their brains with this rubbish.
Stop. Desist. Go away.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|