is it true

There is constraint in java while using a public , that a file with Java source code can only contain one public class whose name must also match with the filename

Yes it is.
I would have liked you to first having gone through the langauge documentation, since this is something that even the very first program requires you would have found this immediately and also learnt a few things with that. Search your question on the internet first if you do not get a satisfactory answer only then post it here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.