Solved

Explain Java Code

Posted on 2007-03-22
9
341 Views
Last Modified: 2013-11-23
Please, I need some help with this Java code. This is not for a homework. What happens is that I am learning some JAVA, I understand part of the code but I am not sure. Can anyone explain me these two codes. Which are the classes, methods, objects, and what does each of the lines do? This is call that will communicate with an API. Thanks!


CustInquiry
----------------------
public InquiryResultSet searchForCusts (SearchBean search,int pageWanted,Cursor cursor){
        int PageSize = 90;
        CustInquiry inquiry =(CustInquiry) service.createCustInquiry();
        CustFilter Cust = new CustFilter();
        inquiry.setSortDirection(2);
        inquiry.setPageNumber(pageWanted);
        inquiry.setPageSize(PageSize);
        String searchWord = "";
         Cust.setFirstName(search.getFirstName());
         Cust.setLastName(search.getLastName());
         Cust.setSsn(search.getTaxId());
        inquiry.setCustFilter(Cust);
        if(cursor != null){
            inquiry.setCursor(cursor);
        }
        sendMessage(inquiry, "Cust Inquiry failed", "error.CustInquiry", searchWord);
        InquiryResultSet results = inquiry.getInquiryResultSet();
        return results;
    }

--------------------------------------------------------------


AcctInquiry
----------------------
public Collection getAcctInfo(String uniqueId) {
        ServiceAccInquiry acctInquiry = service.createServiceAcctInquiry();
        acctInquiry.setUniqueID(uniqueId);
        acctInquiry.setIncludeExtendedBalances(true);
        sendMessage(acctInquiry, "Info for uniqueId: '" + uniqueId + "'",
                "error.acctInfo", uniqueId);
        return acctInquiry.getAccounts();
    }
0
Comment
Question by:hermor
  • 5
  • 4
9 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 500 total points
ID: 18774496
>> Which are the classes, methods, objects, and what does each of the lines do?

CustInquiry, CustFilter, AcctInquiry etc are classes.

searchForCusts (), getAcctInfo () are methods.

>> CustFilter Cust = new CustFilter();

That creates a new object of type CustFilter and holds it in the object-reference 'Cust'. It had also created an enuiry object before that using the createCustInquiry () method. It then sets the  sort direction, page number, page size, first name, last name, SSN, sets the cursor, gets the inquiry-result set and returns it. Same way getAccountInfo () takes a String argument, creates a service inquiry, sets the parameters like unique-ID and gets the accounts by calling getAccounts () method which returns a Collection object (like maybe a List).
 
BTW that API is probably some 3rd party API or your own so its difficult to tell more without knowing its details.

You might also wanna see the basic Java tutorial to understand classes, objects, methods:

http://java.sun.com/docs/books/tutorial/
0
 

Author Comment

by:hermor
ID: 18774532
The third API is also constructed in Java, as far as I know. It uses some XML to move data from one place to the other. I just know some basics...
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18774564
Which is the third API?

Of course they are all developed in Java but since they are not standard Java API but 3rd party so we can't tell much about what they do unless we have their code or documentation.
0
 

Author Comment

by:hermor
ID: 18774693
Oh Ok, I understand. I am sorry because I don't have that information right now. I can accept more opinions regarding this code as well. Thanks!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Expert Comment

by:Mayank S
ID: 18776178
Is that something in my first comment that you did not understand? Pls feel free to ask Q's....
0
 

Author Comment

by:hermor
ID: 18779084
Thanks for writing again Mayankeagle.

Please confirm the following:
I think that:
Although the 'Cust' object is part of the CustFilter class, I am missing where the class is declared.

        inquiry.setSortDirection(2);
        inquiry.setPageNumber(pageWanted);
        inquiry.setPageSize(PageSize);
        inquiry.setCursor(cursor);
These are object methods right? inquiry is the object and set... are methods. For example 'inquiry.setSortDirection(2);' means that it is invoking the method 'setSortDirection(2)' on the object inquiry. What does the numer '2' mean in this example?

What does this exactly mean?
if(cursor != null){
            inquiry.setCursor(cursor);
        }

Is 'sendMessage' a Java command or what exactly it is?

'ServiceAccInquiry acctInquiry = service.createServiceAcctInquiry();' I understand the first part, It is creating the 'acctInquiry' as part of the 'ServiceAccInquiry' class. Can you explain this part a bit more?

What does service in 'service.create...' mean?

I know these are a lot of questions, but I am sure they will be easy for you to answer. Thank you.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18784294
>>  am missing where the class is declared.

It will probably be in another CustFilter.java file.

>> These are object methods right? inquiry is the object and set... are methods.

Yes.

>> What does this exactly mean?
>> if(cursor != null){
>> inquiry.setCursor(cursor);
>> }

Means you are calling the setCursor () method if the inquiry object and passing the cursor object to it. What the method does internally can be known only by seeing its code.

>> Is 'sendMessage' a Java command or what exactly it is?

No, it is probably also a method defined in some class.

>> Can you explain this part a bit more?

Its creating an object of the class 'ServiceAccInquiry.

>> What does service in 'service.create...' mean?

Its an object of some other class - can't see where service is defined in that method, so it must be a class level data member.

0
 

Author Comment

by:hermor
ID: 18804207
I've been reading a few books about Java during these days and I can understand much better your answer. Thanks a lot!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18804555
Great.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 68
Eclipse Neon and jdk 1.8.0 11 122
Java Timer (static) 9 36
Groovy problem when using SOAPUI : DispatchException occurred 7 27
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now