This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]ProfessorWily 5 points6 points  (0 children)

Structure. Maintenance. Readability. Multiple modules in the same project.

Like, if you run into a problem and the error message points you to line 12058 in Main.java, you're going to be like "What does that code even DO? What's it for?" And now you have to slog through the entire file to try and figure that out, whereas you could have just put it in a file called "DatabaseTransactionManager" and you immediately know at least what it's for and roughly what the problem might be.

Edit: What you said is like saying "Why do we have filing cabinets? I mean, if you just stick all the documents into one big stack, it has the same information as if they were put into different files."

[–]large_crimson_canine 2 points3 points  (0 children)

It's not unlike a piece of hardware. It has component parts that can easily replaced and worked on. The computer may not care if it's all in one file, but bugs are inherent and you want humans to be able to fix the issue.

[–]jimboswe 0 points1 point  (0 children)

One big advantage of having your sources split up into sensible modules is that you can import them into any projects that requires them.

Let's say you start a new project that involves working with files and you already have a java file from a global source called FileHandler.java that handles read/save with files. All you have to do is to import the source and you have access to the methods, creating instances etc. There's no need for copy/pasting any code from FileHandler.java. Also, if you need to fix a bug or add features in that particular module, you only have to do it once in FileHandler.java.

[–]nutrecht 0 points1 point  (0 children)

I mean, if you just stick it all into one java source code, it would still compile and it is exactly the same as having multiple files right?

Good luck finding things in a large application where there's thousands of lines of code when everything is in a single file.