File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes for loop in constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "for loop in constructor" Watch "for loop in constructor" New topic
Author

for loop in constructor

Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
Is it possible to put a cicle for in a class costructor?
I tryed but it doesnt' work, however no compilation errors in output..
If it is's not possible why?

tnk

[ September 14, 2005: Message edited by: Marco Vanoli ]
[ September 14, 2005: Message edited by: Michael Ernest ]

bye, <br />Marco
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What is a cicle?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

I don't understand what you mean. could you post your code? and tell us exactly what you think it SHOULD be doing vs. what it IS doing.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

I'm guessing he means "cycle" -- we call them "loops".

So "Is it possible to have a for loop in a constructor?" Yes, absolutely. Here's one:




[Jess in Action][AskingGoodQuestions]
koushik maiti
Greenhorn

Joined: Jul 22, 2005
Posts: 9
What do u mean by a circle ? plz give ur correct meaning...
bye
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

What do u mean by a circle ? plz give ur correct meaning...

While we're making requests...

Please make the extra effort to write out words such as "please", "you", and "your". The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership.

http://faq.javaranch.com/view?UseRealWords

Thanks!

P.S. I don't see where the OP mentioned a "circle"...
[ September 14, 2005: Message edited by: Steve Morrow ]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

I've edited the topic title for clarity, but left the term 'cicle' in order to support the discussion so far.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

my guess is that when the Original Poster (OP) wrote "cicle", Ernest took it to mean cycle = loop. My first thought, too, what they meant "circle".

Now, assuming Ernest was correct, that still doesn't help the OP with why HIS version didn't work. So, again, if Marco could post his code and explain what he thinks it SHOULD do vs. what it DOES do,

p.s. Steve, do you see the irony in asking someone to spell out words, then you yourself use the abberviation OP???

[ September 14, 2005: Message edited by: fred rosenberger ]
Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
lol what chaos
Yes Ernest, i wanted to say loop!
In Italy we say "ciclo" for loop so at the moment i used cicle, but the right word was cycle.. however also it was wrong.. my english little poor..

Returning to the topic before yesterday i thought that loop in a constructor is possible but using this code nothing happened..


I want to istantiate class Setting and get immediatly the list classNames filled of 10 javabens.. probably i am wrong on something..
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Well, you need a constructor for you Setting class. The only method you have is

public Setting2(){...}.

A proper constructor uses the same name as the class. So for you it would be

public Setting(){...}.


GenRocket - A Test Data Generation Platform
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

I see two problems:

1) Your constructor name does not match your class name.

2) Your loop won't run if i is set to zero and the loop should only run if it is equal to 10. You probably meant to write:
Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
Originally posted by Michael Ernest:
I see two problems:

1) Your constructor name does not match your class name.

2) Your loop won't run if i is set to zero and the loop should only run if it is equal to 10. You probably meant to write:

oh my god what an idiot error

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: for loop in constructor
 
Similar Threads
calls servlet onchange event
New yahoo mail user interface
Is Filter Mutli-threaded?
SCJP 1.4(77%) in one month
selectOneRadio - javascript get value