Is there a maximum length for a line of code in Java?

2.4k Views Asked by At

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.

4

There are 4 best solutions below

4
On BEST ANSWER

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.

Read more

To directly answer your question (as I should've done already) - No. There is no maximum length of a line in Java.

1
On

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.

0
On

"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.

0
On

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.