Environment setup and basics of running code
Master how to configure the development environment, understand the full workflow from writing code to running it, and learn efficient debugging techniques.
Development environment setup
A good development environment is the foundation of efficient programming. Different tech stacks require different runtime environments. Select a development type and tech stack to view detailed configuration guides.
Backend
Server-side development languages and frameworks
Java
The dominant force in enterprise development, the Spring Boot ecosystem is mature
Recommended version: OpenJDK 17+
Installation steps
- • Download and install OpenJDK (17 or higher recommended)
- • Windows: Download from Adoptium or Microsoft Build of OpenJDK
- • macOS: Use Homebrew to install `brew install openjdk@17`
- • Linux: Use the package manager to install `sudo apt install openjdk-17-jdk`
- • Verify installation: `java -version`
Version management (SDKMAN / jenv)
Install:
SDKMAN: `curl -s "https://get.sdkman.io" | bash`
Common commands:
- • Install multiple JDK versions: `sdk install java 17.0.8-tem`
- • Switch version: `sdk use java 17.0.8-tem`
- • Set default version: `sdk default java 17.0.8-tem`
Package manager (Maven / Gradle)
Install:
Maven: Download and extract, configure the PATH environment variable
Configuration:
- • Maven configuration file: `~/.m2/settings.xml`
- • Gradle configuration file: `~/.gradle/gradle.properties`
- • Project configuration file: `pom.xml` (Maven) or `build.gradle` (Gradle)
Mirror source configuration (Maven mirror repository)
Recommended mirror:
Alibaba Cloud, Tencent Cloud, Huawei Cloud
Configuration method:
- • Configure Alibaba Cloud mirror: add the `<mirror>` tag in `settings.xml`
- • Or use the environment variable: `MAVEN_OPTS=-Dmaven.repo.local=~/.m2/repository`
Recommended IDE
Package manager best practices
- • Lock dependency versions:Use a lockfile (package-lock.json, yarn.lock, pnpm-lock.yaml, Gemfile.lock, composer.lock, Cargo.lock, etc.)
- • Distinguish dependency types: production dependencies vs development dependencies
- • Update regularly: Use tools to check outdated dependencies
- • Security audit: Run security scans regularly (npm audit, pip-audit, cargo audit, etc.)
- • Use mirror source: Using a mirror source domestically can significantly improve download speed
Principles of code execution
A deep understanding of the full process from writing code to execution, and of the execution mechanisms of different languages, helps you debug and optimize code more effectively. This section provides a comprehensive explanation of the code execution process, from underlying principles to practical applications.
The complete lifecycle of code execution
From source code to final execution, code goes through multiple stages of processing. Understanding this process helps in understanding the performance characteristics and debugging methods of different languages.
Lexical Analysis
Break source code down into a series of tokens, such as keywords, identifiers, operators, literals, and so on.
Example:
let x = 10;
→ Token: [let] [x] [=] [10] [;]
Syntax Analysis / Parsing
Organize token sequences into an abstract syntax tree (AST - Abstract Syntax Tree) to represent the syntactic structure of code.
AST structure:
VariableDeclaration ├─ Identifier: x └─ Literal: 10
Semantic Analysis (Semantic Analysis)
Check the semantic correctness of code: type checking, scope analysis, variable binding, error detection.
- • Type checking: ensure type matching (statically typed languages)
- • Scope analysis: determine the visible range of variables
- • Symbol table construction: record information such as variables and functions
Code Generation
Convert AST to target code: machine code (compiled), bytecode (JVM, .NET), intermediate representation (LLVM IR), etc.
Compiled
AST → machine code
Bytecode
AST → bytecode
Interpreted
AST → direct execution
Optimization (Optimization)
Optimize the generated code to improve performance and reduce resource consumption.
- • Compile-time optimization: Constant folding, dead code elimination, loop optimization, inlining
- • Runtime optimization (JIT): Hotspot code detection, dynamic compilation, deoptimization
Execution
Execute code in the runtime environment: the CPU executes machine code, the virtual machine executes bytecode, and the interpreter executes the AST.
Execution environment:
- • CPU: Directly executes machine code (C, C++, Rust, Go)
- • Virtual machine: executes bytecode (JVM, .NET CLR)
- • Interpreter: execute the AST line by line (Python, early JavaScript)
Complete flowchart
Debugging tips
Efficient debugging ability is a core skill for developers. Mastering multiple debugging methods enables quick identification and resolution of issues.
Breakpoint debugging
- • Conditional breakpoint: Pause only when conditions are met
- • Log breakpoint: record information without pausing execution
- • Call stack analysis: Track function call chains
- • Variable monitoring: view variable value changes in real time
Log debugging
- • Log level:DEBUG、INFO、WARN、ERROR
- • Structured logging: Use JSON format for easier analysis
- • Log aggregation: Centrally collect and analyze logs
- • Performance logs: Record the time spent on key operations
AI-assisted debugging
Use AI tools to quickly identify issues:
- • Paste the error message into AI to get possible solutions
- • Use AI to analyze code logic and identify potential issues
- • Have AI generate test cases to verify the fix
- • Use AI to explain complex error stacks
Learning outcomes
After completing this chapter, you will:
- 1Can configure a complete development environment, including:
- • Frontend:Node.js/TypeScript、React、Vue、Angular、Svelte、Next.js、Vite、Webpack
- • Backend:Java、Python、Go、Node.js、C#、Rust、C++、Ruby、PHP
- • Mobile devices:React Native、Flutter、Swift/iOS、Kotlin/Android、Dart、Android Studio、Xcode
- 2Understand the full process from writing code to running it (interpreted vs. compiled)
- 3Master basic debugging methods (breakpoint debugging, log debugging, AI-assisted debugging)
- 4Understand package manager best practices and security considerations, and be able to configure mirror sources for different tech stacks