← Back to Module 2
Debugging Tools and Techniques
IDE Debugging Tools
IntelliJ IDEA Debugger
IntelliJ IDEA provides powerful debugging capabilities:
- Breakpoints: Set breakpoints by clicking in the gutter area
- Debug Window: Access variables, watches, and call stack
- Evaluate Expression: Test code snippets during debugging
- Conditional Breakpoints: Set breakpoints that only trigger under specific conditions
Debug Toolbar
- Step Over (F8): Execute current line
- Step Into (F7): Enter method calls
- Step Out (Shift + F8): Complete current method
- Resume (F9): Continue until next breakpoint
- Stop (Ctrl + F2): End debugging session
Logging Tools
SLF4J with Logback
Example configuration and usage:
// Logger configuration
private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
// Logging examples
logger.debug("Detailed information for debugging");
logger.info("General information about program execution");
logger.warn("Warning messages for potential problems");
logger.error("Error messages for serious issues");
Logback Configuration
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
Performance Profiling Tools
JProfiler
- CPU profiling
- Memory profiling
- Thread profiling
- Database profiling
VisualVM
- Monitor JVM performance
- Analyze memory usage
- Profile CPU usage
- Thread analysis
Memory Analysis Tools
JVM Tools
- jmap: Generate heap dumps
- jhat: Analyze heap dumps
- jstat: Monitor JVM statistics
- jstack: Print thread dumps
Eclipse Memory Analyzer (MAT)
- Analyze heap dumps
- Find memory leaks
- Generate memory reports
- Compare heap snapshots
Code Analysis Tools
Static Analysis
- SonarQube: Code quality and security analysis
- PMD: Static code analysis
- FindBugs: Bug pattern detection
- Checkstyle: Code style checking
Dynamic Analysis
- JaCoCo: Code coverage analysis
- JUnit: Unit testing framework
- Mockito: Mocking framework
- AssertJ: Fluent assertions