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

Interface - Object Oriented Programming : Java

Table of Content Introduction What is Interfaces in Java Why Interfaces are important Some Important Point To Be Noted Syntax Java Interface Examples Introduction :  In the dynamic world of Software Development , Object Oriented Programming (OOP's) stands as a cornerstone for building robust , scalable applications . One of the key features that empowers OOP's is the concept of interfaces. In this article , we will discuss the interfaces and exploring how they enhance code modularity and flexibility. What is Interfaces in Java?  Java interfaces provide an abstraction archiving mechanism. The Java interface can only include abstract methods; method bodies are not allowed. In Java, it is used to archive both multiple inheritance and 100% abstraction.  Stated differently, it is possible for interfaces to contain abstract variables and methods. There cannot be a method body for it.  It s...

Designing a Student Grading Android App: A Step-by-Step Guide

 Introduction: In this blog post, we will walk through the process of designing an Android application that takes student details and subject marks as input, calculates the student's grade based on the obtained percentage, and displays the result using ViewGroup components. Step1: Setting Up the Project Start by creating a new Android Studio project. Choose an appropriate project name and set up the basic configuration. Ensure that you have the latest Android SDK installed. Step2: Desinging the User Interface (UI): Write a below code in activity_main.xml file located in res ->layout-> activity_main.xml  Xml code: <? xml version ="1.0" encoding ="utf-8" ?> < LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android" android:layout_width ="match_parent" android:layout_height ="match_parent" xmlns:tools ="http://schemas.android.com/tools" a...

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