If you run an java file(as an .class or .jar file) there's always 1 method being called: The main(String[] args) method.
The method is only called once.
Example of an main method:
public static void main(String args[]) throws IOException {
LoggingBootstrap.bootstrap();
gui = new GUI();
}
In this case it only bootstraps the logger and uses the constuctor method of GUI(the graphical user interface of the program)
Yes. Using the method InetAddress.getByName( String name) for instance.
the method of an class that can is triggered when starting a Java application e.g. by running the command: "java MyProgram" Answer Public is an Access Specifier,static is a keyword which illustrates that method shared along all the classes.void illustrates that this method will not have any return type.main is the method which string has an argument. Public specifier makes the method visible outside the Class and because of the static nature of the method, JVM can call this main method without instantiating the class 'MyProgram'.
if some method is static, then you can not call that method through the oobject of that class. but the name of the class. let us see a example: class Test { int a; int b; static void show() { System.out.println("we are in show"); } } class Main { public static void main(String args[]) { Test t=new Test(); t.show();\\thiss is an erroraneous code. because, the method "show()" is static. Test.show();\\this is correct } Arnas Sinha
The String array args refers to the arguments that the program may require before starting. In many cases you may want the program to take some values as input for processing. this string array is for that purpose.
If the method is static you can do this way: Classname.method() If the method is not static then you would have to instantiate the class that contains this method and then call it using that object. Classname obj = new Classname(); obj.method()
Calling a method in Java is when you run code associated with a specific class, using the name of an instance object of a class, followed by the dot operator, followed by the name of the method, followed by the arguments of the method, enclosed in parentheses.
Yes. Using the method InetAddress.getByName( String name) for instance.
By using command line arguments we can pass values to the static void main method at the time of running the Java class. For example: if Class name is A,then to run this class and accepts command line then run this by using below line java A <argument1> <argument2> ....
functions have independent existence means they are defined outside of the class e.g. in c main() is a function while methods do not have independent existence they are always defined inside class e.g. main() in Java is called method. ######## I've been studying OOP lately and had this question myself, so I will share my thoughts; I was taught that "A Function should do 1(one) thing and do it well." In specific Regards to PHP; The difference between a Method and a Function is that a Method is tied to a specific class. Hope this helps. -------------------------------------------------------------------------------------------------------- function can return value where as method can't that is the main difference between function and method --------------------------------------------------------------------------------------------------- Actually you are describing the difference between a function and a procedure. Function returns a value, procedure does not unless you are using c#, then everything is a function. In c# a function, to paraphrase the first answer, does and thing and does it well. A method contains functions. The most important method is the Main method. All functionality of a program must be referenced in the Main method because when you run a program, it starts at the beginning of the Main method, and stops wehn it hits end of the Main method.
the method of an class that can is triggered when starting a Java application e.g. by running the command: "java MyProgram" Answer Public is an Access Specifier,static is a keyword which illustrates that method shared along all the classes.void illustrates that this method will not have any return type.main is the method which string has an argument. Public specifier makes the method visible outside the Class and because of the static nature of the method, JVM can call this main method without instantiating the class 'MyProgram'.
JAVA
You can run a Java application from the command line using "java <name of the class>"
if some method is static, then you can not call that method through the oobject of that class. but the name of the class. let us see a example: class Test { int a; int b; static void show() { System.out.println("we are in show"); } } class Main { public static void main(String args[]) { Test t=new Test(); t.show();\\thiss is an erroraneous code. because, the method "show()" is static. Test.show();\\this is correct } Arnas Sinha
The String array args refers to the arguments that the program may require before starting. In many cases you may want the program to take some values as input for processing. this string array is for that purpose.
A function is a piece of code that can be reused by calling its name while a method is a function that is associated with a class. In Java, functions are usually referred to as static methods.
If the method is static you can do this way: Classname.method() If the method is not static then you would have to instantiate the class that contains this method and then call it using that object. Classname obj = new Classname(); obj.method()
Any function or method in Java that is coded by the programmer is called a user defined method in Java. The JAVA API (Application Programming Interface) has a set of predefined classes & methods that are for our usage. Whatever methods we create apart from these are termed as user defined methods. In java we not use the term functions. We call them "Methods"