You have already declared it. The thing you are missing is your function body.
public static void main(String[] args)
should be
public static void main(String[] args){
//DO Some Stuff
}
Now here is some additional info: The main function will be started whenever the application is started and the
String[] args
are the arguments that you are going to pass while starting the application. You can declare as many functions as you want within your class
public class demo{
public static void main(String[] args){
//Do Some Stuff
}
private void someFunction(){
//Do Some Stuff
}
}
For more you can start learning some basics from the internet. There are tons of tutorials. Hope that helps. :)
Answer from Shobuj on Stack OverflowJava: When to use method and when to create a class
Methods vs Functions in Java
Videos
You have already declared it. The thing you are missing is your function body.
public static void main(String[] args)
should be
public static void main(String[] args){
//DO Some Stuff
}
Now here is some additional info: The main function will be started whenever the application is started and the
String[] args
are the arguments that you are going to pass while starting the application. You can declare as many functions as you want within your class
public class demo{
public static void main(String[] args){
//Do Some Stuff
}
private void someFunction(){
//Do Some Stuff
}
}
For more you can start learning some basics from the internet. There are tons of tutorials. Hope that helps. :)
you can write code like that
public class Emp{
//Instance variable or class level variable even variable as static
String id;
String name;
//static variable
static int count=0;
{
//non static block
}
static{
// static block
}
public Emp(){
//default constructor
}
//parameterized constructor
public Emp(String id, String name){
this.id=id;
this.name=name;
}
// Non-Static Method
public String getId(){
return id;
}
public String getName(){
return name;
}
//Main method
public static void main(String[] args){
//Instance of class
Emp emp=new Emp("1","Xyz");
System.out.println(emp.getId());
System.out.prinln(emp.getName());
}
}
So I know that creating a class will be more secure.
When should I just go ahead and create a method in my 'main' class, and when should I create a whole new class to then invoke from my 'main' class?
Is it only to prevent users from messing up my program?
or is there a 'aesthetic' reason for doing this?
I'm not trying to program a huge project as i'm just a student beginning to learn this. My project is really just solving a given maze.
One thing is clear: There is not much of a difference when it comes to methods or functions in java.
The question now is : are they physical or logical entity? which will determine weather they occupy memory or not, if they do occupy memory, where exactly? (stack? heap? elsewhere?)