There are ways to program that use little text, but many lines of code. There are others that require more typing, but use fewer lines of code. If there is a maximum length for a line of code, this means it exists as a predefined space of memory in the computer, and making many short lines will waste this predefined space. If this is the case, your program can be a lot smaller by putting in the time to consolidate onto fewer lines. Otherwise, many short, easier to program lines would be the obvious choice.
-
1There is no "global limit", but you could have an IDE large limit. Anyway, it's a good practice to have a limit because the code has to be readable ( E.g.: 80-120 characters ). – ROMANIA_engineer Dec 16 '14 at 23:25
-
3You have a question in your title, but you don't have an actual question in your question. I'm *really* not sure what it is you're trying to do; are you asking a question or starting a discussion about it? Bear in mind that only [one of these](http://stackoverflow.com/help/dont-ask) is acceptable on Stack Overflow. – Makoto Dec 16 '14 at 23:26
-
2I think this question shoul be on http://programmers.stackexchange.com/ – PeerNet Dec 16 '14 at 23:26
-
2@PeerNet: I'm not convinced. First, there has to be a question. Second, this is really more a language limitation, so it could potentially fit on SO. – Makoto Dec 16 '14 at 23:27
-
His question is ambiguous but seems to be related to JVM restrictions. – Juxhin Dec 16 '14 at 23:28
-
1Seems to me to be more about whether there are compiler restrictions, than about JVM restrictions. The JVM doesn't see the layout of the original source. – Dawood ibn Kareem Dec 16 '14 at 23:28
-
1This question is a joke, isn't it? – mikyra Dec 16 '14 at 23:28
4 Answers
There is no maximum length for a line of Java except the maximum your computer can handle however I doubt you'll end up writing a line that long.

- 322
- 2
- 11
-
This is currently the only answer that explicitly answers the question. – Dawood ibn Kareem Dec 16 '14 at 23:58
A method has give or take 65k bytes of bytecode. However there are no limits on how many lines you write apart from the system's possible limitations (if any).
However you should always follow code-style guidelines in respect to your language to make code readable.
To directly answer your question (as I should've done already) - No. There is no maximum length of a line in Java.
-
Referring to the class file format for a question that asks about "lines of code" may be a bit off. But ... admittedly, not as irritating as the question itself, which seems to be caused by a basic misunderstanding (or at least, on having no idea what "compiling" means...) – Marco13 Dec 16 '14 at 23:34
-
@Marco13 Well yea that's true, was more of me letting him know that yes there are JVM restrictions but not *lines of code* restrictions. I'll be very honest though, I have no clue as to why I felt the need to add that. I think it was more of me not wanting to just reply, "no." – Juxhin Dec 16 '14 at 23:38
-
Right. The key point - that there is no limit on the length of a line - is not actually mentioned in this answer. Perhaps Juxhin could make another edit. Of course, this point is also not mentioned in the (currently) accepted answer. – Dawood ibn Kareem Dec 16 '14 at 23:56
-
If there is a maximum length for a line of code, this means it exists as a predefined space of memory in the computer
Just because there's a limit doesn't mean the memory is preoccupied up to that limit. The allocation could happen dynamically.
And the code is not executed, but compiled into the program. So the lines of code do not exist in the program.

- 5,207
- 1
- 19
- 35
"If there is a maximum length for a line of code, this means it exists as a predefined space of memory in the computer, and making many short lines will waste this predefined space."
Being able to read code is important. Writing short lines would be better for readability. In fact, this is why we have such practices like DRY (don't repeat yourself) and Object oriented programming for methods (you can class similar functions together if need be).
Imagine writing an entire program, and you write it all up on 1 line without using any white space.

- 1,107
- 2
- 16
- 41