Step 2 : Set breakpoint Step 3 : Click the debug button Step 4 : Confirm switching to debugging Perspective Step 5 : Switch back to development Java Coded Perspective Step 6 : Debug Perspective Step 7 : Single step operation Step 8 : Look at the upper right corner Variables Change of Step 9 : sign out
This is a for Cyclic Java code , It is helpful to observe the effect of setting breakpoints
public class HelloWorld { public static void main(String[] args) { int moneyEachDay = 0; int day = 10; int sum=0; for (int i = 1; i <= day; i++) { if(0==moneyEachDay) moneyEachDay = 1; else moneyEachDay *= 2; sum+=moneyEachDay; System.out.println(i + " Days later , The total amount of money in the hands of Lord Hong Gang is : " + sum ); } } }
public class HelloWorld { public static void main(String[] args) { int moneyEachDay = 0; int day = 10; int sum=0; for (int i = 1; i <= day; i++) { if(0==moneyEachDay) moneyEachDay = 1; else moneyEachDay *= 2; sum+=moneyEachDay; System.out.println(i + " Days later , The total amount of money in the hands of Lord Hong Gang is : " + sum ); } } }
Breakpoint concept : A breakpoint is when you are in debug mode , When the code runs to the breakpoint , Will stop , It is convenient for developers to observe relevant data , Analyze the code logic , Troubleshooting .
There are several ways to set breakpoints , For example, set a breakpoint on line 8 1. In line number 8 That position , Right click the mouse , Then select Toggle Breakpoint You can add or delete breakpoints 2. In line number 8 That position , You can also add or delete breakpoints by double clicking the left mouse button . 3. Menu ->Run it's fine too , Not commonly used , No mouse is convenient .
At ordinary times, use the left side of the run button , There's a bug button , namely debug Button .
Click to debug . notes : It should be noted that , Current class , There must be a master method , Otherwise, it will debug to Last successful program
If this is the first run , A dialog box will pop up asking if you want to switch to debugging , click YES.
Click in the upper right corner Debug lateral Java, You can switch back to the original familiar Java Development environment
Debugging vision , What needs attention is that 4 Regions
1. Which thread is currently , Because it's a non multithreaded program , So it's the main thread 2. The values of several variables that affect the operation of line 8 , This is the main function of debugging , Observe how much of these values , Analyze the problem or understand the code logic 3. Current code , express You're about to run line 8 , But I haven't had time to run line 8 yet 4. console output There are other areas , Not commonly used
Click this button , You can execute it line by line , Or use the shortcut keys F6
This is the main area to pay attention to during commissioning , Through observation , analysis , Understand the changes in these values to enhance the understanding of the code , Or look for the error in the code
Red button , Click exit
The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .
![]()
Q & A area
2020-12-04
teacher , When I first click debug, I can do one-step debugging , Then I ran the code , hold debug The view is off , Then open , Single step debugging is black and can't be clicked , What's going on ?
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2020-03-11
Debug The debugging perspective console does not display the currently executed content ?
4 One answer
meige Jump to the problem location Answer time :2020-08-18
I also know that you are a fool
luodawei Jump to the problem location Answer time :2020-06-03
Just click step by step
ProgramApe Jump to the problem location Answer time :2020-03-29
yes
XUTIEZHU Jump to the problem location Answer time :2020-03-11
Teacher, I know again , I'm really a fool .
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2020-01-27
Can debugging leap forward
2019-09-16
I learned another trick , Thank the webmaster , Make a little progress every day
2019-07-20
idea How to debug breakpoints
Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 5 Previous questions , please Click to view
Please... Before asking questions land
The question has been submitted successfully , Auditing . Please
My question Check the question record at , thank you
|