C structure in JAVA equavilent
by oo » Wed, 09 Jul 2003 17:29:23 GMT
I am doing this in c/c++:
struct MY_REC
{
short nLen;
char szName[9];
} myRec;
myRec.nLen = 9;
strcpy(myRec.Name, "Superman");
write(&myRec, sizeof MY_REC);
The write() function will take the address of myRec and write the whole
structure to file. The binary value of nLen will be wriiten to file.
How can I achieve this in Java?
Re: C structure in JAVA equavilent
by Joseph Millar » Wed, 09 Jul 2003 19:25:21 GMT
See the java.io.Serializable interface and its use in the API docs.
Also, there is nothing to prevent you having a read() and write()
method as part of your class that know now to dump/get saved state
information.
--Joe
Re: C structure in JAVA equavilent
by Steve Horsley » Wed, 09 Jul 2003 19:32:21 GMT
I asume you want to write a compatible file in java?
First you need to specify the exact file format:
* What characterset / text encoding scheme does the file use?
Is is ASCII, CP2125, 8859-1 etc.
* What encoding does the short use?
How many bytes, and in what order? Is it signed?
* What happens if the name is <> than 8 characters?
Use shift-and-mask to make up the bytes for the short.
Use String.getBytes(String encoding) to get the string bytes
Don't forget to write the trailing zero byte.
e.g.
byte[] stringBytes = name.getBytes("ISO8859-1");
byte msb = (byte) ((nLen >> 8) & 0xFF);
byte lsb = (byte) (nLen & 0xfF);
myOutputStream.write(msb);
myOutputStream.write(lsb);
myOutputStream.write(stringBytes);
myOutputStream.write((byte) 0);
Steve
Re: C structure in JAVA equavilent
by Jon A. Cruz » Thu, 10 Jul 2003 01:09:28 GMT
Chances are the C code is broken and you don't even know it.
That's a *very* bad thing to do. When you write C/C++ code like that,
you get broken results. Running on different types of computers will
break it. Compiling with different switches will break it. Compiling
with different compilers might break it. Even using all the exact same
settings, but a newer version of the same compiler from the same vendor
might break it.
*Never* read and write structs directly.
Write clean, proper C code. The write the same code in Java. It can end
up almost identical.
Follow the advice from Steve Horsley in doing this.
Similar Threads:
1.CS installs of Java Web Start and JRE
Just installed CS4 web premium and as per CS3 web standard, multiple
copies of Java Web Start and Java JRE are installed. With CS4 web
premium, individual copies of Web Start and JRE are installed for
Acrobat (Designer), Version Cue, Service Manager and Flash. If that were
not enough all CS4 Java installs are already superseded by Java security
updates e.g. at the time of writing the current version of Java JRE is 6
update 7 (6.0.70.6) and the CS4 installed version is 5 (5.0.90.1).
Now it's a known problem with Java that previous insecure versions are
not removed during the SUN Java update install but from my experience
with CS3 neither are any CS Java installs updated by the SUN Java
install.
How do others deal with this? Manually update all the CS installed
copies each time there is a security update or can the CS installed
copies be removed entirely from the CS directories (i.e. will Flash etc
then locate and use the 'system' Java code)?
Chris
--
Chris Salter
2.selection structure nested within another selection structure
Hey guys i am having some trouble with nesting one selection structure
within another selection structure. At the moment i am unclear what
selection structures are and just need a simple example of a selection
structure within another selection structure. I am supposed to use
function definitions with parameters to validate a form. my code for
what i have done so far is as follows(cropped):
function mainFunction() {
var dateFormat = (document.dateFormat.date.value + " " +
document.dateFormat.month.value + ", " +
document.dateFormat.year.value);
window.alert("The date is " + dateFormat);}
return; }
function checkDate( ) {
if (0<parseInt(document.dateFormat.date.value) &&
parseInt(document.dateFormat.date.value)<=31) {
return true;}
else {window.alert("Problem with the date");
return false;} }
Basically how can i change the above checkDate function in include a
selection structure nested within another selection
structure.Eventually i will have another 2 functions which will b used
to validate the year and month the user enters. Your help would be
great :)
Have a nice day
3.Structuring JUnit tests for large package structures?
4.javascript file won't work with .cs file...
Hello. I'm reposting this because my prioe post's subject line was
incorrect.
I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all
the updates. I have an aspx page with javascript that works fine until I
try to separate the script into a .js file. I've found that only the script
that is called from events set in the aspx.cs file don't work. I eliminated
all script except two functions. One is used with the .cs file and the
other one is not.
First, here's the functino used with the .cs file:
if (!this.IsPostBack)
{
btnFirst.OnClientClick = "return btnFirst_Click()";
}
... the javascript function is...
function btnFirst_Click()
{
alert("This is btnFirst_Click"):
return false;
}
Now the second javascript function is only
function ShowAlert()
{
alert("This is ShowAlert");
return false;
}
This function is called from another button - button1 - from the
OnClientClick event which I set in the property page..
When I have all the javascript in the aspx page, it all wokrs, but when I
move it to a .js file, the first function doesn't work, but the second one
does.
I don't want to add all my javascript in rhe .cs file because that would
expose all my code - that's why I'm teying to put it in a .js file.
How can I make all the code work using both methods?
Thanks...
--
Matthew.Wells
XXXX@XXXXX.COM
5.Calling a javascript function from .aspx.cs file
Hi,
I wanted to call a javascript function
function showAddress(address)
{
....
}
from the aspx.cs file from the Gridview_RowCommand function
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
.....
//got a string value a
//showAddress(a);
}
How would i be able to call the function from here.
Any help will be appreciated.
Thanks alot...
6. calling cs method from javascript
7. Calling a javascript function from aspx.cs file
8. who uses algorithms learned in cs studies?