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 8 of 8

Thread: Mkyong - why i recieve the ERROR? Thanks!

  1. #1
    Junior Member
    Join Date
    Mar 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Mkyong - why i recieve the ERROR? Thanks!

    JavaChronoUnit.java
     
    package com.mkyong.java8;  ERROR - Uncaught SyntaxError: Unexpected strict mode reserved word
     
    import java.time.LocalDateTime;
    import java.time.temporal.ChronoUnit;
     
    public class JavaChronoUnit {
     
        public static void main(String[] args) {
     
            LocalDateTime from = LocalDateTime.of(2020, 10, 4,
                    10, 20, 55);
            LocalDateTime to = LocalDateTime.of(2020, 11, 10,
                    10, 21, 1);
     
            long years = ChronoUnit.YEARS.between(from, to);
            long months = ChronoUnit.MONTHS.between(from, to);
            long weeks = ChronoUnit.WEEKS.between(from, to);
            long days = ChronoUnit.DAYS.between(from, to);
            long hours = ChronoUnit.HOURS.between(from, to);
            long minutes = ChronoUnit.MINUTES.between(from, to);
            long seconds = ChronoUnit.SECONDS.between(from, to);
            long milliseconds = ChronoUnit.MILLIS.between(from, to);
            long nano = ChronoUnit.NANOS.between(from, to);
     
            System.out.println(years + " years");
            System.out.println(months + " months");
            System.out.println(weeks + " weeks");
            System.out.println(days + " days");
            System.out.println(hours + " hours");
            System.out.println(minutes + " minutes");
            System.out.println(seconds + " seconds");
            System.out.println(milliseconds + " milliseconds");
            System.out.println(nano + " nano");
     
        }
     
    }
    Last edited by GabIul; March 26th, 2022 at 12:57 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Mkyong - why i recieve the ERROR? Thanks!

    Uncaught SyntaxError: Unexpected strict mode reserved word
    What line in the source code was that error?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mkyong - why i recieve the ERROR? Thanks!

    This line :
    package com.mkyong.java8;

    Thanks!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Mkyong - why i recieve the ERROR? Thanks!

    The posted code compiles without any errors for me.

    How are you trying to compile the code? What IDE or command are you using? What is the version of java?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mkyong - why i recieve the ERROR? Thanks!

    i use Visual Studio Code "strict mode" and when i go live to console i am receiving the error. I need to implement in one special way? Or just paste this code?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Mkyong - why i recieve the ERROR? Thanks!

    Sorry, I do not know anything about using Visual Studio in strict mode.
    Do you know what word(s) are reserved? If so can you change them in your source?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mkyong - why i recieve the ERROR? Thanks!

    or for the same line sometimes is showing : Unexpected identifier

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Mkyong - why i recieve the ERROR? Thanks!

    What word is identified as the Unexpected identifier
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: January 18th, 2021, 03:59 AM
  2. Replies: 3
    Last Post: May 8th, 2014, 06:25 AM
  3. Replies: 2
    Last Post: March 23rd, 2014, 08:44 AM
  4. Replies: 3
    Last Post: November 30th, 2013, 05:52 PM
  5. Problems with A* Map Search - GC Overload Error and Null Error
    By puneeth.meruva in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2013, 03:01 PM

Tags for this Thread