As a novice coder, I'm confused about how to organize and manage my code.
I immediately noticed how methods made my life easier - All I need to do is get all the hard work done once and simply recall it whenever I need it! However, I also noticed the same thing with classes: They're just like methods, but with more flexibility!
I've heard a lot of talk about Java being a really inefficient language to code in (Given the JVM and whatnot), so I'm constantly trimming my code to speed my programs up. However, I've been bothered by a question Google can't seem to answer: Does the overuse of extra classes and methods have any effect on performance?
For example; let's say I have a class that reads user input and does calculations to it. Would it be more efficient to write it like this
public Calculator(); {
otherclass.getInput();
doCalcs();
}
or
public Calculator(); {
( Insert block of code that was originally in otherclass.getInput() and doCalcs() )
}
[Both methods no longer exist, and otherclass.java doesn't exist either]
?
I'm using Eclipse, and I'm not making a calculator, this is just an example, so don't give me specific calculator advice!
Also, I've only been at this for about 3 weeks. If I made any silly mistakes or misconceptions about methods and classes, please say them!
So Cosimo, you're saying that It's a better idea to stick with using methods and the like until I encounter a performance issue? What about classes? Should I use them freely like methods, or should I do something differently?
Currently, I use classes as "Folders" or my methods. For example, I'll have a class that reads input, and within that class is methods that interpret that input. Whenever I want to use them later, I'll invoke the methods out-of-class. Is there a major difference between using methods from other classes to using methods in its own class? Or should I write methods in the classes they're meant to be used in?
I immediately noticed how methods made my life easier - All I need to do is get all the hard work done once and simply recall it whenever I need it! However, I also noticed the same thing with classes: They're just like methods, but with more flexibility!
I've heard a lot of talk about Java being a really inefficient language to code in (Given the JVM and whatnot), so I'm constantly trimming my code to speed my programs up. However, I've been bothered by a question Google can't seem to answer: Does the overuse of extra classes and methods have any effect on performance?
For example; let's say I have a class that reads user input and does calculations to it. Would it be more efficient to write it like this
public Calculator(); {
otherclass.getInput();
doCalcs();
}
or
public Calculator(); {
( Insert block of code that was originally in otherclass.getInput() and doCalcs() )
}
[Both methods no longer exist, and otherclass.java doesn't exist either]
?
I'm using Eclipse, and I'm not making a calculator, this is just an example, so don't give me specific calculator advice!
Also, I've only been at this for about 3 weeks. If I made any silly mistakes or misconceptions about methods and classes, please say them!
So Cosimo, you're saying that It's a better idea to stick with using methods and the like until I encounter a performance issue? What about classes? Should I use them freely like methods, or should I do something differently?
Currently, I use classes as "Folders" or my methods. For example, I'll have a class that reads input, and within that class is methods that interpret that input. Whenever I want to use them later, I'll invoke the methods out-of-class. Is there a major difference between using methods from other classes to using methods in its own class? Or should I write methods in the classes they're meant to be used in?