Detailed process of debugging Java code using Jupyter Notebook in VSCode

Table of contents
  • What are Jupyter Notebooks?
  • Main advantages of Jupyter Notebook
  • Environmental preparation
  • Download IJava
  • Create a conda virtual environment
  • Build the operating environment
  • test

The computer I used before was a bit old, and after running the program for a while, it reported that there was not enough memory. I originally wanted to consider buying a new computer with a GPU. When browsing the products, I considered that the wallet is not thick enough. I chose another computer with a slightly higher configuration at home to toss.

Usually I develop personally, mainly on Eclipse, and the new environment is also installed. In fact, if you usually study, you mainly run code segments, and you don’t know how to run large-scale projects. There is always a feeling of driving downstairs to buy food (mainly considering the cost of gas, no, memory).

Given that VS Code is relatively lightweight, cross-platform meets my usual toss; rich plug-in functions meet the needs of different development scenarios. So, the goal of tossing is achieved. In VS Code, use Jupyter Notebook to debug Java code segments, okay?

I searched on the Internet, and there are some who use VSCode to develop Python; there are not many who develop Java; in VS Code, there are not many materials for writing Java code snippets using Jupyter Notebook. Well, we have a set of tossing goals: VS Code + Jupyter Notebook + Python + IJava, assembling a fun development environment.

What are Jupyter Notebooks?

Jupyter Notebook is opened in the form of a web page. You can directly write and run code on the web page, and the running result of the code will also be displayed directly under the code block. If you need to write an instruction document during the programming process, you can write it directly on the same page, which is convenient for timely explanation and explanation. Official introduction to Jupyter Notebook

Main advantages of Jupyter Notebook

  • When programming, it supports syntax highlighting, indentation, and completion functions.
  • Supports Markdown syntax, and can explain the code through rich text.
  • Supports using LaTeX to write mathematical formulas, etc.
  • What you see, what you get, is to run the code directly on the web page.

Environmental preparation

  • The Java environment installation is not described in detail. Note that JDK 9 or higher is required. Personally I use JDK11.
  • VS Code installation, synchronous installation of Python, Jupyter, extensions pack for Java plug-in, no detailed introduction.
  • Prepare the Python environment. If it is a Windows environment, installing Python is a bit complicated. It is recommended to install it through Anaconda or Miniconda. Anaconda contains some commonly used scientific computing packages, which are relatively heavy. Miniconda is the smallest conda installation environment. Compared with conda+python+pip, it is lighter and faster to install. Here, I take Anaconda as an example

Add conda to the system Path environment variable:

?

1

C:\ProgramData\Anaconda3\Scripts

Download IJava

IJava is the kernel that executes Java code inside the Jupyter kernel. The IJava kernel executes Java code through the new JShell tool. You can download the code or download the compiled binary package. The latest version is: ijava-1.3.0, the specific github address is: https://github.com/frankfliu/IJava

Create a conda virtual environment

?

1

2

3

4

#创建conda虚拟环境,python环境为3.8

conda create -n your_env_name python=3.8

#删除conda 里的虚拟环境

conda remove -n your_env_name --all

Build the operating environment

Unzip the downloaded ijava-1.3.0.zip and open it with VS Code. Bring up the VS Code terminal and enter the following command:

?

1

2

3

4

5

6

7

#创建conda虚拟环境,python环境为3.8

conda create -n ijava python=3.8

conda activate ijava

#安装内核

conda install ipykernel

python -m ipykernel install --name ijava <自己取名字可与虚拟环境名字一致>

python install.py

test

Create the HelloWorld.ipynb file.
Create a code block in the file, select the Java runtime environment, and click Execute. The effect is as follows:

 

Guess you like

Origin blog.csdn.net/qq_15509251/article/details/131623996