nus-cs2030 / 2122-s2

CS2030 repository and wiki for AY 2021/2022 Sem 2
MIT License
0 stars 0 forks source link

JDT not activating on Vim #5

Open chloeoxe opened 2 years ago

chloeoxe commented 2 years ago

Summary

JDT not activating despite creating a file called 'HelloWorld.java'

Description

I use mac and on my terminal, I managed to create a file using 'vim HelloWorld.java' as what is shown in the Luminus 'Intro to Java' video. However, in the video, right after creating the HelloWorld file, the JDT started loading and activating but this is not the case for me. Instead, the supposed 'Java' file acted more like a regular txt file (see image attached) and I'm assuming it's because my JDT does not activate automatically. Is anyone else a mac user and also experiencing such a problem? Does anyone know how to fix this? Any input would greatly help. Thank you!

Screenshots (if any):

Screenshot 2022-01-12 at 9 41 39 PM

wjahoward commented 2 years ago

Hello! You do not really require JDT in order to run the Java file on Vim, though it might be helpful in writing your code faster as compared to writing the code everything manually from scratch.

Your current file is in a correct and valid .java format. You can test if is working fine by writing the command on Terminal java HelloWorld.java, which your current code will throw an error as there is no public static void main(String[]) function.

Your HelloWorld.java file can include something like this:

class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

And you should expect to see an output after running java HelloWorld.java command on Terminal:

Hello World

I did include some syntax highlighting to identify the keywords easily. These are the steps as such:

  1. vim ~/.vimrc

  2. Type :syntax on

  3. Open any .java file and you should see something like this:

image

Hopefully this helps and clarifies your doubt! :)

chloeoxe commented 2 years ago

Ohhh I see! Initially after watching the Luminus video, I thought that every time we started a java file, shortcuts would be immediately activated which would allow for faster coding like how the TA coded the 'public static void main(String [] args)' in an instant. However, yes I did try coding out the HelloWorld class manually, complied it, and it ran successfully! Now I know that actually Vim and Java does work properly for me and the shortcuts in the video are optional to allow for faster coding, thank you for the help as well as the syntax highlighting tip! It really helped.