Campbell Ritchie wrote:What’s a header file? Just because C/C++ has them doesn’t mean Java™ has them, too. I made a suggest about C++ earlier: here.
Why are you thinking of class methods at all? You should be thinking of objects and object methods. You create a class which represents the sort of object you plan to create, create an instance, and call the methods on that. If the new class is marked public, it usually must go in a file of its own.
Using class fields and class methods when you do not want them to refer to the class usually suggests you do not understand object-oriented programming.
Marius Constantin wrote:So header files do not exist in java ?
Marius Constantin wrote:Could you please tell me the best practice regarding the proper way to store your methods in a file different than the one who has the main method ?
Marius Constantin wrote:Question : it's best practice to use the first or second approach ?
Marius Constantin wrote:Well, this great book that I am reading, and many amazon users who bought this book agree with me, goes through all the building blocks of the Java language, like constants, variables, methods in general, arrays , multidim arrays and maintains a procedural approach towards creating apps in this early stage, for short, until it dives into creating classes , and complicated topics, for a beginner anyway.
Marius Constantin wrote:A bit harsh onthe greenhorn, aren't we, without knowing the background of the problem.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Matthew Brown wrote:Regarding the book - in my opinion the best introductory Java books go straight into the object-oriented stuff, because to get the most out of the language you want to start thinking in that way. E.g. "Thinking in Java" by Bruce Eckel: chapter 1 "Introduction to Objects".
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
SorryMarius Constantin wrote: . . . A bit harsh onthe greenhorn, aren't we, without knowing the background of the problem.
I am surprised; I had thought Liang was a book to recommend. I was obviously mistaken.Well, this great book that I am reading, . . . multidim arrays and maintains a procedural approach . . .
Anayonkar Shivalkar wrote:You are welcome.
So, in my opinion, what you need is - redesign.
You can identify 'actors' in your application, create corresponding classes (in different files) and invoke corresponding methods in corresponding objects. e.g. you can have one class to read/write a file which is in specific format, another class which performs a set of critical operations, yet another class which transmits this data over the network and so on.
Further, you can import those classes in your main class file and continue the workflow (like creating corresponding objects, and invoking respective methods etc.)
I hope you got the idea.
Marius Constantin wrote:I have a class with 20 methods that do certain jobs.
My goal is to easily manage the calls between main method and the 20 methods that do certain jobs in order for the application to display proper output, and the C++ approach of all 20 methods in a file and main methods in another file seemed good to me, since I don't have to go up and down one file 100 times looking for certain lines of code and lose focus.
since the import java.util.Scanner, for eg, is bringing code to your application.
SCJP 6
Larry Chung wrote:Probably what could satisfy Marius is to implement his classes and methods by using Inheritance. He could put all the methods in the Parent class and all his child classes simply call on those methods. Could that be what he was trying to articulate?
Campbell Ritchie wrote:This is what happens when people come to object-oriented programming (OOP) from a procedural background. They take ages to learn OOP and try to program as they used to in C.
Marius Constantin wrote:
Campbell Ritchie wrote:This is what happens when people come to object-oriented programming (OOP) from a procedural background. They take ages to learn OOP and try to program as they used to in C.
I think it depends on the Dumb, in your opinion, person, you are referring to, and I also think that this last sentence is way beyond the constructive scope of this forum.
I wonder if this is the right attitude for a Sheriff ? To subtile insult the intelligence of a person.
I personally come to this forum to learn about Java and because people here were always given me constructive advice not insults.
if this happens again,I will be forced to press the magic button.
still kind regards,
marius
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|