Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: run time error: same program running in jdk19 but not in jdk1.7.5 Why?

  1. #1
    Junior Member
    Join Date
    Feb 2023
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default run time error: same program running in jdk19 but not in jdk1.7.5 Why?

    run time error: same program running in jdk19 but not in jdk1.7.5 Why?

    In my laptop i installed jdk19 program successfully runned,but in my college old version jdk 1.7.5 same program compiled,but runtime error. What should I do?
     
    import java.util.Scanner;
    public class ReplaceExample
    {
        public static void main(String args[])
        {
            Scanner sc = new Scanner(System.in);
            System.out.println("Enter a String");
            String str = sc.nextLine();
            System.out.println("The String input using Scanner class is: " +str);
    	  System.out.print("String before replacing : ");
            System.out.println(str);
     
            System.out.print("After replacing all e with A : ");
            System.out.println(str.replace('e', 'A'));
     
            System.out.print("After replacing all Engineering with Arts : ");
            System.out.println(str.replace("Engineering","Arts"));
     
     
        }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: run time error: same program running in jdk19 but not in jdk1.7.5 Why?

    but runtime error. What should I do?
    Please copy the full text of the error messages and paste it here so we can see what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2023
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: run time error: same program running in jdk19 but not in jdk1.7.5 Why?

    k. Tomorrow I have Lab Session. I will note that error.

  4. #4
    Junior Member
    Join Date
    Feb 2023
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: run time error: same program running in jdk19 but not in jdk1.7.5 Why?

    Error:could not find or load main class JavaExample
    caused by java.lang.classNot FoundException:JavaExample

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: run time error: same program running in jdk19 but not in jdk1.7.5 Why?

    Error:could not find or load main class JavaExample
    caused by java.lang.classNot FoundException:JavaExample
    The code you posted declared the class: ReplaceExample

    Where is the code for the JavaExample class?

    Have you confused the names?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Feb 2023
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: run time error: same program running in jdk19 but not in jdk1.7.5 Why?

    ReplaceExample.java,JavaExample.java both my lab program shows this Exception.
    Error:could not find or load main class JavaExample
    caused by java.lang.classNot FoundException:JavaExample

    Error:could not find or load main class ReplaceExample
    caused by java.lang.classNot FoundException:ReplaceExample
    both programs compiled without error,but the class file does not create in this saved location.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: run time error: same program running in jdk19 but not in jdk1.7.5 Why?

    If the classes are not in a package, then the java command needs to be executed in the same directory that holds the .class file.
    If the .class file is in another folder, the java command will not find it. The java command looks for the .class file in the directory that it is executed in.

    The posted text of the error messages does not show what directory the java command was issued in.

    For example using the java command without a .class file in the Norm directory:
    C:\Users\Norm>java TheClass
    Error: Could not find or load main class TheClass
    There was not a file named TheClass.class in the Norm folder.

    Where is the file: JavaExample.class? That is the directory that needs to be used when the java command is issued.
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    nandhutee (February 25th, 2023)

Similar Threads

  1. Replies: 8
    Last Post: June 30th, 2017, 08:08 AM
  2. Replies: 5
    Last Post: August 19th, 2014, 03:30 AM
  3. Replies: 21
    Last Post: June 12th, 2013, 11:33 AM
  4. Difference between JDK1.6 and JDK1.7
    By noorul11 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 11th, 2013, 01:05 PM
  5. [SOLVED] Program is running successfully but still getting error message..
    By sumit043020701 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 24th, 2011, 12:26 AM

Tags for this Thread