473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Converting VB to Java - 'type' convert for record

2
I have zero Java knowledge, what would be the equivalent of the following in java?

Expand|Select|Wrap|Line Numbers
  1. Public Type hdrmail1rec                             'Output rec header 1
  2.     hdrcust As String * 20
  3.     filler1 As String * 3
  4.     hdrpo As String * 20
  5.     filler2 As String * 3
  6.     hdrdate As String * 23
  7.     filler3 As String * 3
  8.     hdrstat As String * 40
  9. End Type
Jun 3 '13 #1
3 2763
Nepomuk
3,112 Expert 2GB
Hi Jack and welcome to bytes.com!

Java doesn't have an own type for records and Strings aren't fixed length either. The closest to the above would be a Bean with String members or, if you insist on fixed lengths, char arrays. A bean is a very basic Java class with private variables as well as getter and setter functions for those variables. Of course, you could enforce a certain length in those setter functions.
Here's a truncated example:
Expand|Select|Wrap|Line Numbers
  1. public class hdrmail1rec {
  2.    private String hdrcust;
  3.    // ...
  4.  
  5.    public String getHdrcust() {
  6.       return hdrcust;
  7.    }
  8.  
  9.    public void setHdrcust(String hdrcust) {
  10.       if(hdrcust.length() > 20) {
  11.          this.hdrcust = hdrcust.substring(0,21);
  12.       } else {
  13.          this.hdrcust = hdrcust;
  14.       }
  15.    }
  16.    // ...
  17. }
In theory, you could make the String variables public and do without the getters and setters; this is however considered bad practice due to security reasons (as any class could then access the variables without you having any control over it). Also, many libraries and frameworks follow the convention of having getters and setters.
Jun 4 '13 #2
jack25
2
thanks for the info nepomuk! I am stumbling through converting a program to Java, kind of as a learning experience and it's also something that would help out at work.

I appreciate the info!

-jack25
Jun 4 '13 #3
Nepomuk
3,112 Expert 2GB
You're welcome. Java uses a few concepts that are probably quite different from VB (though just guessing, as I never seriously developed in VB myself) so just converting it probably won't be the best method if efficiency is essential. As a learning experience of course, it can be very useful.
Jun 5 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jaYPee | last post by:
I have created a stored procedure that contain this field (below) in order to meet certain criteria. But my problem is when I try to run the stored procedure I encounter an error "Error converting...
1
by: luna | last post by:
got so far then it broke and i cant get it working again - it was updating fine but not inserting and now im getting a "Error converting data type varchar to numeric" which i didnt have before.......
1
by: Andrew Baker | last post by:
this seems to be an SQL Server error but I cant work out how it is occuring. Itr is also after 3am and I cant keep working but need to demo by tomorrow. TIA. The code is: Private Sub...
0
by: rajmgopal | last post by:
Hello Everyone I am getting the following error when i try to insert a record into Sql Server 2005 from my VB 2005 application. sqlEx = {"Error converting data type numeric to numeric."} I...
2
by: Curious Trigger | last post by:
Hello, if have an asp.net web page with a detailsview. This detailsview uses a sqldatasource connecting to a sql server 2005 database with a select statement simliar to this one: SELECT...
3
by: delirman49 | last post by:
Hello, Sorry for my english. This is my problem : I must create for a great french company a webmethod with 2 "in" parameters. The first is an object, no problem. The second must be a...
0
by: Adele | last post by:
Please help, I'm new to SQL and I use a script to import data and when I tried importing data tonight it gave me "error converting data type nvarchar to float". I have no idea what this error...
2
by: ive | last post by:
Server: Msg 8114, Level 16, State 5 Error converting data type varchar to numeric. Hello... I new in MS SQL. Given: 2 servers, same SQL statements, same input, same tables, same data types,...
0
by: bluepiper | last post by:
Hi everyone. I have created a linked server on SQL Server 2005 to access data from visual foxpro database. I execute a query Select * from OpenQuery(members, 'Select * from memfile') but Im...
3
by: lornab | last post by:
Hi I wonder if anyone can help - I think the answer is simple but it's been a really long day and I need to get this done!! My select statement goes like this... SELECT client, ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.