javanetbeanscharacter-encodingspecial-characterscharset

IDE does not recognize special characters when compiling Java code


I'm having a big problem with my computer, as I try to compile source code made in Java language, hence a great frustration:

The variable of type String is poorly read and interpreted by the compiler and prints squares instead of special characters.

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Name:");
        String name = sc.nextLine();
        System.out.println(name);
    }   
}

Result:

enter image description here

My attempts were:

With this problem, I can't:

enter image description here

Was it some configuration that was left behind or is it a solution that I am not able to develop to fix this problem? And if so, what would be the best explanation for solving this problem? Will it be necessary to contact the technician for more information?


Solution

  • I am grateful that @Tigris helped me with this problem, which actually when I went to check I ended up making a storm in a glass of water. The @Tigris solution in the comments gave me an idea that became immediate when I analyzed the error I was giving with the answer he initially gave me.

    The problem was simple, it was basically a character encoding error in the IDE's terminal that was solved with the line I typed in CMD:

    chcp 1252
    

    This solution is related to the link at the end of the comments and in it you notice that the explanation of the post indicates that the problem can be solved with a simple line of code that sets a system property.

    But after solving this problem and analyzing the link that @Tigris shared here in the comments, I was thinking: If my problem hadn’t solved and still insisted on showing special characters in an unreadable way, then I would have to insert the answered line of code posting on all my projects?

    That is why it is always good to check the device's character string right when it comes from the factory or even a repair, because depending on the occasion when this display problem of special characters can change the database that the user is working in case be a developer or even to build an API or Webservice for a client without paying attention to these details of textual stress, which can cause inconvenience and headaches when finishing a project in any IDE that is installed on the computer.