Skip to main content

Java main method explanation

Explantion and Importance of main() method in java programming


Explanation of main() method in java programming

The entry point of executing a Java program is the main method.We know that Java programs work in oops concepts.Java programs are treated as objects and classes.If there is more than one class in a program,The program should be named using the class containing the main() method,because main() method is the entry point of Java program.

java main method explanation


Syntax of main method

public static void main (String args[]){

 }

Importance of main function in java programming


Here the public is an access modifier.There are different modifiers available in java If a function is declared public, the scope of the function is the entire program.Static keyword is the keyword where we can directly access the method without object.If the method is static, then such method can be accessed directly.Here void is a return type.Every method has a return type.When writing a method, the return type is compulsory. The return type will change based on the program logic.Here main is method name Java programming supports the command line arguments.In the command line arguments we can give the inputs.Here String is a predefined class in java and args is the array name.It is the user defined name.


Java basic interview questions for freshers


1 purpose of main method in java?

A: Main is method,its the entry point for executing a java program

The main method can contain code to execute or call other methods,

and it can be placed in any class that's part of a program.

2 why main method is public in java?

A: If a function is declared public, the scope of the function is the entire program.

without object creation, to access directly

3 why main method is static in java?

If a function is declared static its can be accessed directly.

why main method is void in java?

A: Every method has a return type.Return type must be written in Java program.

Return type is not always void. It can change according to program logic.

 




Comments

Popular posts from this blog

Introduction to java programming-very important theory notes

Introduction to java programming what is java? Java is a high level object oriented computer programming language(OOPS). Java is a general purpose programming language used in computers and other applications. Java, an object-oriented programming language developed by Sun Microsystems under the leadership of James Gosling, Bill Joy, etc., is used today in many electronic devices such as web servers, computers, and mobile phones. Although it is mostly used for web programming, it is a multi-purpose programming language that can be used to do many other things. After Oracle bought Sun Microsystems in mid-2009, Java came under Oracle's control. (Wikipedia). What is a computer? A computer is an electronic device for storing and processing huge amounts of information. What is a computer program? A computer program is a set of instructions for a computer to perform a specific task. A computer cannot do anything by itself, if it wants to do something, it must get clear instructions, the i...

JAVA BUZZWORDS

     JAVA BUZZWORDS & H istory of the development of java java buzzwords explanation     Features of java is called as Java Buzzwords Platform independent —> Run on any Environment Object oriented concept(oops) —> Abstraction,Encapsulation,Inheritance and polymorphism Simple —>  No concept of pointers,explicit memory allocation, structures,operator overloading etc  Secure —> Secure for internet application (Raise  out of boundary exception in arrays and it is strong typed language) Robust —> Early checking of error it can achieved garbage collector, exception handling Portable  —> Java program written on one environment can be executed or implemented another environment Multithreading  —> Concurrent execution of several parts of same program at same time(This will improve CPU utilization) Distributed Application —> This are software that runs on multiple computers connected  to a network at ...

How to run java program using while loop

 Java program how to print Happy New Year in 10 times(using while loop) java buzzwords static keyword in java The AI ​​Revolution- Malayalam article step by step explanation Before writing Java code Install Jdk on your system and Set the path properly. Then type the Java code in the notepad and save it as a class name with the .java extension. Select the file type 'all file' while saving. Open cmd, Change the directory where the file is saved, using the cd command. Type javac class name.java then press the enter key, If you type java and give the class name, If there is no error in the program, the output will be generated. Observe the directory change using the cd command. Give the class name and watch it compile and run. How to run java program in notepad and cmd Where to code in Java and how it works? method 1 A text editor is required to write Java code The code can be run using the command prompt method 2  using an integrated development environment (IDE), such as Eclips...

Oops concepts in java

oops concepts in java with example programs Oops concepts in java Oops concept is very very important to make java programming easier and increase your programming skill.Four pillars of oops are Abstraction,Encapsulation,Inheritance,Polymorphism.Another technique to carefully understand in Java is classes and objects. This article covers very simple notes for Java programming beginners. What is object and class? The basics of oops is class and object Class is a blueprint which defines some properties and behaviors.  An object is an instance of a class which has those properties and behaviors attached.A class is not allocated memory when it is defined. An object is allocated memory when it is created Class and object —> object is defined as real word entities .Object consists of property and some task Class is a blueprint that object follows, Class  consists of many number of objects Four pillars of oops are Abstraction   —> Means showing only essential parts and hi...

Command Line Arguments In Java

Command Line Arguments In Java No input statement needed in the program itself. we can pass the input as an argument while running the program. Sometimes you will want to pass information into a program when you run it. This is accomplished by passing command line arguments to main function. To access the command line arguments inside a java program is quite easy are stored as string in string array passed to main function. Example program of command line arguments in java class CommandLineExample {    public static void main(String args[]) {    System.out.println("\nMy first input is  :"+args[0]);    }    }    Addition of two numbers in java using command line arguments  Example:write a program add two integer number    class AddCommandLine { public static void main(String args[]) { int num1=Integer.parseInt(args[0]); //type cast int num2=Integer.parseInt(args[1]); //type ...

Keywords in java programming

Keywords in java programming Keyword is a predefined word given by the compiler which has some specific task. Keywords also known as reserved word. All the java technology keywords are lower case . Java programming has a richer set of keywords than C language or C ++ language. Some java keywords are import —>In java programming implementing classes and methods import the packages that purpose using the keyword import. class —> In order to create a class we have use the keyword class to see an example written using the class keyword ) this —> This keyword is used to represent the method belongs to particular current object Super —> It can used in inheritance concept extends —> Also used in inheritance concepts. Accessing methods one class to another class that can done by extends keyword package —> In java there will be package which consists of number of classes and interfaces in order to access that package, using the key word package return —> Return key wor...

Naming Convention In Java

Naming Convention In Java-camel case example Naming Conventions are rules to be followed by giving a name to the identifier.Identifiers are program elements(such as class,object,variable,method so on ).For building software you should follow this rule to make your code look good, more efficient and more readble.Java has certain rules for naming identifier. This are given below Digit, letters, underscore or currency symbols( £, €, $ ) are allowed                The first letter of any identifier cannot be a digit An identifier name must not be a reserved words or keywords Java follows camelCase rule what is camelcase rule? CamelCase is a way to separate the words in a phrase by making the first letter of each word capitalized and not using spaces (ex :- MyFirstJavaClass) Class name —> should begin with a capital letter(In a single word) If it is multiple words, the first letter of every word begins with a capital letter. Ex :- class Stu...