Results 1 to 18 of 18
Thread: Type casting
- 08-23-2010, 09:00 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 8
- Rep Power
- 0
Type casting
Hi im really new to understanding the conversion of C to java especially with objects and since java doesnt have objects but classes im trying to figure out.
basically i have a char[1000] in java.
so its just raw data btu i want to convert it into a class i have.
os is there a way to get the char[1000] into it i keep thnking something liek this should be possibleJava Code:class data{ char [] name = new char[50]; } class arrayofdata{ data [] d = new data(20) }
foo [1000];
arrayofdata gg = new arrayofdata(foo);
- 08-23-2010, 10:23 PM #2
Don't try 'converting C to Java'
Learn Java and produce a program that has the same functionality as the original C program.
db
- 08-24-2010, 09:15 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
And Java does have objects.
- 08-24-2010, 09:14 PM #4
Member
- Join Date
- Jul 2010
- Posts
- 8
- Rep Power
- 0
Yeah i meant java doesnt do structs like C does. Im just trying hard to basically once i gather a big chunk of data how can i convert that data to a structure would i just have to do it the brute force where every byte.something = what i want it to be or is there a simple method like C
- 08-24-2010, 11:18 PM #5
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
do you just want to convert the syntax of C to java? or ....
Edit : thnxLast edited by [RaIdEn]; 08-24-2010 at 11:23 PM.
- 08-24-2010, 11:21 PM #6
The opposite. He wants to convert the syntax of C for usage in his Java application.
@OP: You will be best to brute-force the operation; simply loop through each object in the array and convert it. There is no easy method of conversion of this type as in C/C++.
- 08-24-2010, 11:50 PM #7
There is no easy way to "convert" bytes into a class object. It requires a class loader.i have a char[1000] in java.
so its just raw data btu i want to convert it into a class
What is you are trying to do? what is in the 1000 characters? Where are they? In a file?
Java Code:something like this should be possible foo [1000]; arrayofdata gg = new arrayofdata(foo); In java: char[] foo = new char[1000]; .. fill the 1000 chars with data ??? class ArrayOfData { char[] data; // constructor ArrayOfData(char[] x) { data = x; // copy ref to array } } ArrayOfData gg = new ArrayOfData(foo); // create arrayOfData object
- 09-01-2010, 06:21 PM #8
Member
- Join Date
- Jul 2010
- Posts
- 8
- Rep Power
- 0
Sorry for responding late this array of 1000 chars is basically just 1000 data bytes and were transfering them over with jni from a C applications but we want to put them in a java Class structure that follows the protocols of a wmv file. Like header and type and sound and data load then end of data load.....like thats the structure of a wmv file
- 09-01-2010, 07:03 PM #9
What java Class structure follows the protocols of a wmv file?
If you are able to create this object, what would you do with it?
What methods/classes would use it?
- 09-01-2010, 07:23 PM #10
Member
- Join Date
- Jul 2010
- Posts
- 8
- Rep Power
- 0
okay so im kinda new to java then but couldn't i just create one my self like i would in C then or is there standards to making java classes if i was trying to implement structures. I basically trying to do this so when the C data processes the selection sends back a chunk of data in unsigned chars then I need java to descipher that data for a java application
- 09-01-2010, 07:34 PM #11
There are 10,000 plus different ways you can make a java class.
What do you want to do with the class that will hold your data?
What is the java application? What does "descipher" mean?when the C data processes the selection sends back a chunk of data in unsigned chars then I need java to descipher that data for a java application
- 09-01-2010, 10:14 PM #12
Member
- Join Date
- Jul 2010
- Posts
- 8
- Rep Power
- 0
I just want a class to represent a C structure without the extra features java has like i dont want a function in the class just data types and my application is juts basically to have a union of a data structure for java even though java doesnt support union they use hierachy but i thought if i could typecast the bulk of data into a class i created it would work out
- 09-01-2010, 10:46 PM #13
Why have a class? How about an array?
What are you going to do with the data in a java program?
- 09-01-2010, 11:47 PM #14
Member
- Join Date
- Jul 2010
- Posts
- 8
- Rep Power
- 0
well the big chuck of data is basically an array of unsigned chars and in the data its giong to be a list of adapters . so thats y if we had a structure we could easily break up the data in parts for each adapter and reconize the first [50] char is one adapter the second [50] char is a different adapter and then list it out in a java gui for the user
- 09-02-2010, 01:11 AM #15
Sounds like an array would be the way to store it.
- 09-02-2010, 08:44 AM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
I'd store it in an array as Norm says, but I'd stick that array in a class that has the methods that do the work you are describing, since that data and the procesing you describe are intertwined.
- 09-02-2010, 01:31 PM #17
The OP is confused about what s/he wants.like i dont want a function in the class
- 09-02-2010, 01:58 PM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
I know.
The idea of a basic struct-substitute in Java seems to occur a lot, but it's not really the Java Way...:)
From what I read of the OPs requirements, there's some data coming in that then needs some work done on it to display on a GUI. I say that work code should be part of the same class that holds this data as an attribute. That's what I'd expect to see.
From their posts, though, I can see they're thinking in terms of having a lump of data that they then pass around...
Similar Threads
-
Type Casting
By Shaheen Mohamed in forum New To JavaReplies: 6Last Post: 08-17-2010, 07:56 PM -
Casting Object to another type
By green_river48 in forum New To JavaReplies: 12Last Post: 04-03-2010, 10:52 AM -
help with type casting.
By ramsrocker in forum Java AppletsReplies: 15Last Post: 02-26-2009, 11:28 PM -
type casting
By alvations in forum New To JavaReplies: 1Last Post: 10-13-2008, 07:07 PM -
Type Casting Help
By rhm54 in forum New To JavaReplies: 2Last Post: 02-07-2008, 12:06 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks