wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Anyone could explain this script to me? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Anyone could explain this script to me?" Watch "Anyone could explain this script to me?" New topic
Author

Anyone could explain this script to me?

Renato Bello
Greenhorn

Joined: Jun 20, 2012
Posts: 15



I don't understand particularly the relation between the two methods (line 13 and the method "maybeNew"). How to calculate it?

If is possible, explain all this script.

Thanks



Gaurangkumar Khalasi
Ranch Hand

Joined: Jun 02, 2012
Posts: 187
Renato Bello
Greenhorn

Joined: Jun 20, 2012
Posts: 15
Thank you, GK

I still have some questions:

21 if (index < 5) {


- then the index will always be less than 5 because there is nothing that increments this value?

23 Mix4 m4 = new Mix4();
24 m4.counter = m4counter + 1;


- the total value of m4.counter is infinite and has no use for anything, right?

25 return 1;


- I use the return value of the method maybeNew using the parameter value "index" to add to the value of the variable "count"?

13 count = count + m4a[x].maybeNew(x);


- I still do not understand what is the relationship between M4a [x] and the method "maybeNew". (are in different methods and thought that would relate instance variables with class objects)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Please QuoteYourSources.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Renato Bello
Greenhorn

Joined: Jun 20, 2012
Posts: 15
Henry Wong wrote:Please QuoteYourSources.



Sorry, I thought that the questions was related to the script, I didn't need to identify the parts. Have fix it.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Renato Bello wrote:
Henry Wong wrote:Please QuoteYourSources.



Sorry, I thought that the questions was related to the script, I didn't need to identify the parts. Have fix it.



Please click on the link -- and read why we require this. This is not optional.... and BTW, it looks like you quoted the sources for your previous topics, why won't you quote it for this one?

Henry
Renato Bello
Greenhorn

Joined: Jun 20, 2012
Posts: 15
Renato Bello wrote:Thank you, GK

I still have some questions:

21 if (index < 5) {


- then the index will always be less than 5 because there is nothing that increments this value?

23 Mix4 m4 = new Mix4();
24 m4.counter = m4counter + 1;


- the total value of m4.counter is infinite and has no use for anything, right?

25 return 1;


- I use the return value of the method maybeNew using the parameter value "index" to add to the value of the variable "count"?

13 count = count + m4a[x].maybeNew(x);


- I still do not understand what is the relationship between M4a [x] and the method "maybeNew". (are in different methods and thought that would relate instance variables with class objects)


I am still here with the hope that someone help me with these dilemmas.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

Renato Bello wrote:I am still here with the hope that someone help me with these dilemmas.

And we're still hoping you'll comply with Henry's request. As he said, this is not optional.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

@Gaurangkumar:

1. Please don't provide ready-made solutions. We are NotACodeMill (←click).
2. Please don't put enormously long lines inside code boxes. It screws up the windowing. I've broken up yours, but please read the UseCodeTags page thoroughly for future reference.

Thanks

Winston
Renato Bello
Greenhorn

Joined: Jun 20, 2012
Posts: 15
Winston Gutkowski wrote:
Renato Bello wrote:I am still here with the hope that someone help me with these dilemmas.

And we're still hoping you'll comply with Henry's request. As he said, this is not optional.

Winston


I just do not include the reference source because I could not edit the first post. If you can cite the source now, I tell the script that is quoted in the book Head First Java. I apologize again for the fault
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Renato Bello wrote:
21 if (index < 5) {


- then the index will always be less than 5 because there is nothing that increments this value?


No. The index is actually passed in as a parameter -- and it does look like the index is incremented by the calling loop.

Renato Bello wrote:
23 Mix4 m4 = new Mix4();
24 m4.counter = m4counter + 1;


- the total value of m4.counter is infinite and has no use for anything, right?


The code creates a new object, whose counter is zero. It gets incremented to one. And then the object is thrown away. Those two lines of code doesn't do anything useful.

Renato Bello wrote:
25 return 1;


- I use the return value of the method maybeNew using the parameter value "index" to add to the value of the variable "count"?


Well, that is what the expression looks like ... see next question.

Renato Bello wrote:
13 count = count + m4a[x].maybeNew(x);


- I still do not understand what is the relationship between M4a [x] and the method "maybeNew". (are in different methods and thought that would relate instance variables with class objects)


m4a[x].maybeNew(x) is part of an expression. It basically says, take the m4a array; deference it to the x element; use that element to call the maybeNew() method, passing the x value as the parameter.

Henry
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

Renato Bello wrote:I just do not include the reference source because I could not edit the first post. If you can cite the source now, I tell the script that is quoted in the book Head First Java. I apologize again for the fault

No probs. And BTW, you cited it in your last post: citation is simply stating the source of something.

You'll notice that Henry has now replied to your previous one.

Winston
Renato Bello
Greenhorn

Joined: Jun 20, 2012
Posts: 15
Thank you, guys

Have some things that I still can not understand, but I'll keep pushing myself, reading the book and posting questions here. Does anyone know if there is a free online course of java?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

Renato Bello wrote:Does anyone know if there is a free online course of java?

The Oracle Java Tutorials are quite good.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
GeeCON Prague 2014
 
subject: Anyone could explain this script to me?