Welcome back to Java Code Online. We all know that Java is an Object oriented language based on the Principle of OOPS. The basic principle of Java is to recognize your Objects. Whenever you need to start coding, just ask yourself, what are the Objects involved in this Java code.
Now once you have finalized your Objects, then you need to put them in code. But if you start putting all your Object code in a single large Java file, then it will look very unclean and messy, moreover the beauty of the code is lost. What best can be done is that we put the code in classes.
A class is a blueprint of an Object, so it define the Object. So as a natural process of coding in Java, you recognize your Objects put them in separate classes and then write a main class that make Objects of those classes and perform the operations required.
It is simply equivalent to the human body, where the main class is the brain of our human body, we have limbs, legs, fingers, joints, heart, etc. each performing its own function. So it is like all the parts are Objects in Java for which we write separate classes, now these separate classes are used by the main class (brain of the human body), and so we see that all the parts coordinate and perform the tasks they are made for. Simple.
If you really want to understand the basics of Java, then do often relate it to practical life things, and you will find Java very easy, this is because Java is built to work on practical situations.
I hope the article answered the question that why everything in Java is written in a class. If you liked the article then do leave a comment. For more info on Java, keep buzzing Java Code Online.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.