Home > Java > javaTutorial > body text

How to use Jupyter Notebook to debug Java code in VSCode

WBOY
Release: 2023-05-12 09:28:05
forward
1649 people have browsed it

What is Jupyter Notebook?

Jupyter Notebook is a program that is opened in the form of a web page. You can write and run code directly in the web page, and the results of the code will be displayed directly under the code block. If you need to write a description document during the programming process, you can write it directly on the same page to facilitate timely description and explanation. Jupyter Notebook official introduction

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 is to run the code directly on the web page.

Environment preparation

  • Java environment installation will not be introduced in detail. Note that JDK 9 or above is required. I personally use JDK11.

  • VS Code installation, synchronous installation of Python, Jupyter, extensions pack for Java plug-ins, no detailed introduction.

  • Python environment preparation. 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 packages for scientific computing and is relatively heavy. Miniconda is the smallest conda installation environment, related to conda python pip, relatively lightweight and faster to install. Here, I take Anaconda as an example

Add conda to the system Path environment variable:

C:\ProgramData\Anaconda3\Scripts
Copy after login

Download IJava

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

Create conda virtual environment

#创建conda虚拟环境,python环境为3.8
conda create -n your_env_name python=3.8
#删除conda 里的虚拟环境
conda remove -n your_env_name --all
Copy after login

Build a running 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:

#创建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
Copy after login

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:

How to use Jupyter Notebook to debug Java code in VSCode

The above is the detailed content of How to use Jupyter Notebook to debug Java code in VSCode. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template