Solved

java function

Posted on 2011-09-23
8
304 Views
Last Modified: 2013-11-23
I saw a java code snippet which was something similiar to this

Fetch.func1().func2()

I understand that Fetch is a class and func1 is method in that class, but i am not sure what is func2 is it also a method in class fetch ? and also want to when can i use this type of function call...please help

~manu

 
0
Comment
Question by:manugeek
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 20

Expert Comment

by:a_b
ID: 36585454
Fetch.func1().func2() => Fetch is a class that has a method func1().

Fetch.func1() returns an object that has the method func2(), therefore you can invoke func2().
0
 
LVL 20

Assisted Solution

by:a_b
a_b earned 25 total points
ID: 36585457
Eg -

Class A
{
    public B func()1
   {
        .......
   }
}

Class B
{
   public void func()2
   {
        .......
   }  
}

You can try writting a test harness for these classes.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36585459
Well there is no gurantee in this notation, but one may assume that Fetch is a class, func1() is a static methid of this class which returns an instance of another class, and then method func2() is invojed on the instance of the result of funnc1()
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 25 total points
ID: 36585478
We can make conclusion that Fetch is a class and func1() is a static method because first letter of Fetch is capitalized and the convention is that class names are written starting with capital leeter
Howerver convention is not a law, so we cannot exclude that Fetch is an instance of some class. If so, then func1() would be an instance method - we should see more code to know for sure
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 13

Accepted Solution

by:
Hugh McCurdy earned 200 total points
ID: 36597016
I thought it might help to give an example from a program.  This example is from a simple interactive fiction ("adventure") game.

Path path = player.getRoom().getPath( direction );

Open in new window


Here the player is trying to leave the room he's currently in.  player is an object for the player.  getRoom() is a method in Player that returns the room the player currently occupies.  getPath() is a method in Room that accepts a compass direction and returns a path object (which may be null, meaning the direction is invalid).

The method continues.  I'm showing it just to give you some context.

If the path isn't null, we use a method in Path to get the room at the end of the path.  (The path can be very short, ie a door or doorway).

We have more "chained" messages (function calls).  I will explain what those do if you indicate it will help.  Better would be, if you can, explain to me what you think they do and get me (or someone) to review your answer.  (My assumption is you want to learn.)

        if ( path == null )
        {
            myScreen.setDescription ( "You can't go that way." );
        }
        else
        {
            Room nextRoom = path.getRoom();
            
            if ( player.getRoom().getPath ( direction ).getLocked())
            {
                myScreen.setDescription ( player.getRoom().getPath ( direction ).getWhyLocked() );
            }
            else // unlocked
            {
                if ( player.setRoom ( nextRoom ))
                myScreen.setDescription ( player.getRoom() );
            } // else
                
        } // else

Open in new window



0
 

Author Comment

by:manugeek
ID: 36597255
Thank @hmccurdy: for the detailed explanation. Now this makes sense to me :-)

0
 

Author Closing Comment

by:manugeek
ID: 36597259
Thanks all for the answers...
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36598821
Thanks.  Never mind for the program bug that remained (oops) after I removed some lines of code that would be confusing.

I'm glad it makes sense to you now.  Gets my day off to a good start.
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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

911 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

20 Experts available now in Live!

Get 1:1 Help Now