Skip to content

elvisbejko/java-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java

Overview

Compile to bytecode

javac HelloWorld.java

It outputs a .class file which is the bytecode that the JVM understands. To execute:

java HelloWorld

The above command executed the compiled class not the .java file. Notice that it is ran without the .class extension, in fact java looks for the class in the current directoy or CLASSPATH. The class must have a main method.

maven

We need a pom.xml to define the project structure and dependencies. Then we run

mvn install

and maven will install the dependencies in ~/.m2/repository.

maven is much like cargo, it manages the project entirely. You need a specific structure for maven to execute properly: you need to have your code in ./src/main/java and then execute it, not through javac, but rather

mvn exec: java -Dexec.mainClass="EnvToken"

static

If a method within a class is static then that means that we can invoke the method without having to instantiate the class itself.

Java installation

Install latest java development-kit:

sudo pacman -S jdk-openjdk

To check the default version:

java -version
javac -version

Since I first installed jdk17, this is set as the default. To see all available versions,

archlinux-java status

I set the latest java as default

sudo archlinux-java set java-23-openjdk

Install maven to have the java language server. Maven is used for managing dependencies and building projects.

sudo pacman -S maven

maven requires jdk18 and upwards.

Then install the java-language-server in nvim's Mason.

About

Playground for java development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages