hey guys since im new to java i don;t to why im getting such error in my program my code is given below
can u please help me out in setting the environment variable so i can run my program... i have set the path variable as my jdk path ..do i nedd to also set the classpath as my jdk or where my program is saved...
class program {
String nm = "";
public static void main(String args[]){
nm = "myname";
System.out.println(nm);
}
}
im getting error "main class not found"...
please help..!!!!!!!!!!
Please mark your class
as public
public class program{
}
And as a side note :please follow the java naming conventions .
program
should be Program
Try this:
Public class program
{
String nm = "";
public static void main(String args[])
{
nm = "myname";
System.out.println(nm);
}
}
Fisrt of all change your code
class program {
static String nm = ""; //this should be static
public static void main(String args[]){
nm = "myname"; //other wise you can't refer it here
System.out.println(nm);
}
}
then save this as program.java
javac program.java
then run this
java program
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.