Skip to main content

Source File Structure in java

Welcome to world of Programming ! Whether you are a notice beginner coder, student understanding the fundamental structure of Java source file is crucial. In this article , we will unravel the mysteries behind java source file ,providing you with a solid foundation for writing clean ,efficient ,and maintainable code ,and clear the concept behind java source file and Tips .

In this article we discuss this concept with Question and Answer based .


Q1. In Java Program How many Class can we Take ? 


Ans. In java program we can take any no of classes .and we can compile them but we cant run without Main method 

Demo with code : 

Java code snippet of Multiple class without public access modifier

Code Out Put Snippet

Snippet of of Generated .class file for every class created in Java program



Q2. Which class name do we give for the Java programm? 

Ans : Any Class name we can give for Java program( as like shown in above demo with code) but if we declare any class of them as Public we have to compulsory create a java program file with that class name . 

important  conclusion :  java program contain any no of classes but at most one public class can be declare and more than one public class is not allowed .

Demo with code 1(with public class but name of file is different ) :

It generate following Error: 
Demo.java:6: error: class B is public, should be declared in a file named B.java
public class B {
       ^
1 error


public class declaration but file name is different



Demo with Code 2(with public class and same name of file ) :






Q3. Can we only give that Class name to file Which contain Main method ?

Ans :  No . We can give Any class name to that file , But if there is one class who declared as public and which contain Main method in that condition we have to compulsory file name same as that class name. Other wise without public class we create many classes in one program with many Main method It will be compiled and Executed. 

Demo with Code (number of classes with no of Main methods with Different File name ) :



Conclusion :

This Post contain basic guidance ,tips which should know every student and beginner who is learning java programming.

Comments

Popular posts from this blog

UML Diagram For Blogging Platform Mini Project -1

In this Article first of all we learn about what is UML?   then we will see the Uml Diagrams for Blogging Platform mini project that helps to student to develope a the Blogging Platform mini project . It helps to student who are studing in BCS,BCA, BTech,BE,MCA for drawing UML diagram for thier acadmic project .they can get referance from this diagrams. Lets Start, What is UML? UML is Stands for Unified Modeling Language . It is a part of Software Engineering . Typically ,software architects or designers aften take the lead in creating UML diagrams to communicate and document the system's design. It's a standardized way to visually represent and design software systems. Followings are UML Diagram 1. ER Diagram for Blogging Platform : 2. Class Diagram : 3. Use Case Diagram: System Use Case Diagram : Use Case Diagram: User Management ,Blog Management,Commenting and interaction Module : Use Case Diagram ...

"Python programiTutorial Part 2: "

  Hey guys , Welcome back in new post Python Tutorial part-2 . Lets start the remaining part here.. First Python Program: Before starting a code we have to install python on your machine for more about installation click me We will discuss the basic syntax of python. now firstly we will see the first and simple "HELLO WORLD "program. Run this program. Python provides us two way to run the program: 1.Using Interactive interpreted command prompt. this is image of Interactive interpreted command prompt with the "HELLO WORLD" program with output. 2.Using a script file. This is the image of  script file with the code of "HELLO WORLD ' program with out put.  Script mode has some advantages and disadvantages : 1.We run multiple lines of code at a time in script mode.  2.Run and interpretation process or debugging is easy in the script mode. 3.It is best for beginners and expert also. Disadvantages:-...

Unveiling the Magic of Model View Template (MVT) in Django | Django Tutorial

Demystifying Model View Template (MVT) in Django Introduction: Have you ever wondered how Django manages to handle data, logic, and user interface? Dive into the world of Model View Template (MVT) architecture to unravel the secrets behind Django's framework. Understanding MVT: Breaking Down the Components  MVT, also known as Model-View-Template, comprises three essential components: the model, the view, and the template. The model handles the data logic, the view processes user requests, and the template manages the user interface. Let's dissect each component to grasp their intricate roles and interactions within the Django framework. Model: The Backbone of Data Handling  In MVT, models are synonymous with templates, simplifying the software design process. They are pivotal in organizing and managing data and templates, streamlining the development journey. Furthermore, the model in Django serves as the representation of the database lo...