none
I am planning on switching from Eclipse to Visual Studio. How would I get this simple hello world java code to run.

    Question

  • This is the code

    public class Helloworld {
    
        public static void main(String[] args) {
            // Prints "Hello, World" to the terminal window.
            System.out.println("Hello,j World");
        }
    
    }

    On eclipse to test if the code is running, I press the "Run" button.

    The closest i have found in Visual studio Code is the debug button which returns the error. Could not find the preLaunchTask 'npm

    If i could get a step by step guide on how to get started with running a java hello world code successfully in Visual Studio Community 2017 or Code it would help.

    Thursday, January 5, 2017 2:08 PM

All replies

  • Visual Studio doesn't include support for the Java language. There is C#, which has a similar syntax.

    If you really want to use Java with Visual Studio, you need some 3rd party tool from the MarketPlace, such as:

    https://marketplace.visualstudio.com/items?itemName=SamHarwell.JavaLanguageSupport


    My portal and blog about VSX: http://www.visualstudioextensibility.com
    Twitter: https://twitter.com/VSExtensibility
    MZ-Tools productivity extension for Visual Studio: https://www.mztools.com

    Thursday, January 5, 2017 4:33 PM
  • Thanks Carlos J. Quintero.

    Hi Cocks,

    Welcome to the MSDN forum.

    I agreed with Carlos J. Quintero, we cannot directly use the java language in VS. VS includes the languages like C#, C++, VB and others. I found some Hello World tutorials of different languages as the following, which may be helpful for your development in VS:

    Hello World -- Your First Program (C# Programming Guide)

    Visual Basic Version of Hello, World

    Getting Started with C++ in Visual Studio

    If you still want use the java language in VS, like Carlos J. Quintero said, you can install the Java Language Support extension, open VS and go to Tools--Extensions and Updates, click 'Online' tab then search it and install. I tried to install it and then I can find the java project template as below:

    When you choose the Console application from the above screenshot, it defaults includes the hello world command, but when you click ‘Start’ or the shortcut F5, you will get an popup windows with error message ‘This preview version of the Java debugger only supports starting execution in a named class; the class name may be configured in the project properties on the Debug tab.’, which you can find the workaround from here.

    hbrtxito: Right click the project name and choose ‘Properties’, then click Debug tab, you will see "Start Class within project:" radio button. Make sure it is clicked and then in the text field alongside it type in the class name that has your main method in it. Default, you should put in the "Start Class within project" field: "pkg/Program"

     

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 6, 2017 3:06 AM
    Moderator
  • Hi Cocks,

    Sorry to trouble you again, does your issue is solved or not? If not, please feel free to let me know.

    If it is solved, could you please share your solution in here, that will help other community members who meet the same or similar issue, thank you for your understanding. If you think Carlos's reply is helpful for your issue, you can also mark it as answer, so others can easier search this useful information.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 16, 2017 9:07 AM
    Moderator