This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
1. In my knowledge maximum size of a java .class file can be 64K. Is it true?If yes then what happens if I've .java file having code so big in size that it would exceed this limit.
2. In C++ to make things clean i can write different methods of a class in different .cpp files, Is any such feature exist in java too...or if a class of mine is having 1000 functions i'll have to write all of them in the same .java file?
1. No. Where did you read this? 2. It doesn't sound like spliting methods out to different files helps make things cleaner, but I thats what you like I'm afraid you can't do it in Java.
This is a bit of a catch-all statement, but: if you have a class which has 1000 methods(there are no functions in Java) then I'd review your design. A class which does that much would have to be very much the exception not the norm. For example in the app I'm working on just now (which has c4000 classes), I can only think of one which has more than around 20 methods and its a wrapper class to some legacy functionality provided in a different language.
There are some limits imposed by the class file format. There can be no more than 64K fields in a class, for example, nor more than 64K methods in a class. A single method can have no more than 64K local variables, nor more than 255 arguments.
You'd have to try mightily to write a class horrifying enough to bump into any of these limits, but there is one that people do hit from time to time: the bytecode for a single method is limited to 64K bytes. This essentially never happens in normal coding, but it can arise in two special situations: first, if someone is trying to translate an old, badly-written C or FORTRAN program line-for-line into Java, all inside the main() method; or second, in machine-generated code (if, again, the generator is a badly-written one.)
I concur with Paul's assessment that classes should be small(ish) and do one thing well, and such a class will never come anywhere near any of these limits.
There is also a limit of 64KB per method in a classfile. We've run up to that limit several times in large JSPs, prompting the largest of them to be cut up into sections which are dynamically included into the result.
If you have to worry about having too many methods in a class you're almost certainly in need of a very hefty lesson in design...