MAIN METHOD EXPLANATION - JAVA PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our Channel now let us see the importance of main function that means we have we are writing the main function as public static void main string arguments so let us see one by one what is the importance of all those things right so we do that in Java programming or any programming language the execution will start from the main function and everything we have to write it in the main function so whatever the classes we are creating and whatever the objects we are creating everything for everything the reference it should be in this main function we have to write the reference in this main part so unless you write the reference in this main function the particular class or object will not be executed so if you observe with the previous sessions we are writing on caps and we are creating the objects in this main function so that we can access the variables and methods of the particular class by using that object which is created in main function so for that the main function we are writing public static void main right so everything will be for a regular thing there will be an importance so this is not a syntax you should not call it existing text right so the only syntax I will tell you so public we know this is the access modifier access modifier so there are different access modifiers available in Java that means access permissions given so that is public private protect and a default so if any method or a class is a public that method can be excessively in any class in the package so public methods or the all the public classes can be accessed through the program so the scope is to the entire program so here I am using the public for the main function because any class reference must be written in main function so from the main function we can we can invoke any object or any method or any variables of different classes so that's why we have losing here public and coming to this static so in just before previous sessions we have explained regarding the static variable static methods and the static block so once go through that so that you know the importance of a static so normally a class consists of variables and a methods in order to access the methods or variables compulsory we'll have to create an object for that particular class and through the object all you will have to access the variables and methods so those are called instance variables and instance methods coming to the static variables so a variable can be declared as a static by using the static keyword so such type of variables we can access directly similarly the static methods also can be executed directly without creation of object without creation of any object we can access the methods static methods directly or by using the class name so here main is also one type of method main is also one type of method so in order to access this method and where we are writing this main function we are writing this main function in one class in one class we are reading the main function right so in order to access this method so main is a method so in order to access this method compulsion we have to create an object and through that object we have to access the main function right so if you detailed this main method as a static we need not create an object for accessing this main function we can directly access this main function so for that purpose we are creating this static keyword but using we are using this static keyword so that access without object right next wild so for every method there must be a return type so that's a rule we have discussed in the previous sessions right so if you are unable to write this return type it will be treated as a constructor so here main function is also a method so it should also have a return type so that need not be avoided it can be int so depends upon the logic depends upon you approve them you can change this void in to eat right so this is the real time and this is the main name of the main function name of function and what is the importance of these string arcs so Java programming supports the command line arguments so in the command line arguments also we can give the inputs so that already we have seen in the previous session right so in order to take the inputs from the command prompt we have using this index string arcs so this is for come on lane ornaments right so our compiler will search the syntax for this one main strength arts so this is the only syntax given by the compiler and this we have to write it okay so if you want fail to write these string arts it will return I mean it doesn't return any error by compilation but it doesn't execute okay so this is the syntax which is to be compared and this we have to write the public static void main so this is the actual importance of this statement so for accessing the main function for all the classes we have to include this public and without any object we have to access the main method so we are hiding static and the every function should have a return type that's why we have using this return type right so hope you understood this simple thing if you really understood my sessions like my sessions share my sessions and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 68,765
Rating: 4.8991919 out of 5
Keywords: sundeep, saradhi, kanthety, java programming, java basics, java fundamentals, beginners, programming fundamentals, java faq, bytecode, java introduction, source code, object oriented, oops, oop concepts, set classpath, abstraction, inheritance, polymorphism, encapsulation, class, object, virtual machine, java compiler, program execution, method overloading, method overriding, javac, class file, os dependent, static, void, main method, main function, public, access modifier
Id: t1neoRWGLrA
Channel Id: undefined
Length: 7min 45sec (465 seconds)
Published: Thu Jan 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.