Scanner class Methods in Java

Structure of Java Program

Java Program Structure

Before jumping to coding, I want you to have basic knowledge of java program structure. It will help you to understand how to write a java program and what is the format of writing program. Lets understand the structure of a program.

Structure of Program in Java

As in above, there are five sections of java program.  Lets see what these sections are in details.

  1. Documentation Section :- It includes comments. Comments provides information about the program and also the author of program can mention his name in comments. It can contain information regarding the name,use,author etc. We can write comments anywhere in the program. This is optional section.   For example:-   //this is a comments
  2. Package Statement Section:- A package is a collection of  classes and interfaces. This section helps in creating packages. It contains package declaration. When we declare package, it means the class or interface we write in program are parts of this package. It is an optional section. For example:-   package student;
  3. Import Statement section:-  Import statement is used to import class and interfaces from a package. When we want to use a class from particular package we write this statement. It is optional. For example:-  import java.util.Scanner;  Here java.util is a package which contains Scanner class. It will only import Scanner class.If you want to import whole package you can use *(Asterisk) For example:-   import java.util.*;
  4. Interface Section:-  In this section, we specify interface.An interface is similar to class but only contains constants and method declaration. We cannot define methods in interface.Interface are used for abstraction in java. They provide 100 percent abstraction.It is also a optional section. Syntax:-   
                                        interface bird //bird is the name of interface
                                        {  

                                           void chirp();
                                             void fly();
                                             void eat();
                                            }
5.Class section:- Class is most important part of java program. A java program must have at least one class. Java is Object oriented language, so it requires class to execute programs.Java class contains main method.Class contains constants,variable and method definitions also.This is mandatory part of java program. Syntax:-

                                        class Student//student is the name of interface

                                        {  

                                           public static void main(String[] args)
                                             {
                                                //code here
                                              }
                                        }
 Note:- Remember java is a case sensitive language, the declaration of class,interface, package & import statement starts with smalls letters. 

Happy Coding!



Comments