Are there Record structures classes in JAVA?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Manish_Haria
Posted On:   Friday, October 5, 2001 07:47 AM

Hi,

I am trying to rewrite a COBOL program in JAVA. This program reads in a file (record length = 10000) and has a large number of fields. I was wondering if there are in-built JAVA classes which can do the same work as COBOL record layouts or C structs.


My idea would be to write a generic class (say RecLayout) which has a method to add fields with name, starting position and length, a method to get any predefined field etc.

Re: Are there Record structures classes in JAVA?

Posted By:   Luigi_Viggiano  
Posted On:   Friday, October 5, 2001 02:40 PM

What a bad idea to think to Cobol writing Java ;) !


With Java your records are represented by object that are defined by classes. Object can be made persistent writing other classes that handle their persistence on the db.

example


/* Those are what you can compare to C structs:
*/
class Address {
String street;
String city;
String cap;
//get & set if you want...
}

class Customer {
String name;
int age;
Address address;
//get & set if you want...
}

class CustomerHandler {
Collection customers;
public void readCustomerFromFile(java.io.File file) {
//reads the file and populate the collection.
}
public void storeCustomersToDatabase() {
//...
}

public void storeCustomersToFile(java.io.File file) {
//...
}
}

For the class RecLayout, if you are making a real-world application, it's better to think about using a good database instead of thinking to implement your own. If you are playing with java, it could be an interresting exercise ;-) & good luck.

Re: Are there Record structures classes in JAVA?

Posted By:   Arun_Bharathan  
Posted On:   Friday, October 5, 2001 08:47 AM

There are no record structures in JAVA.You could construct classes to wrap the COBOL data record. There are tools which help in this regard. The enterprise access builder in Visual Age java (IBM's IDE) is a good example.
About | Sitemap | Contact