Eclipse learning 3
1. Use SCRAPBOOK
There is another way to run the code in Java Project, and does not require the main method at all - using the Scrapbook Page. Scrapbook Page can be used to perform or even part of the code, which is a great help for development. It is not very useful to use Scrapbook Page.
Create a scrapbook page: Select File- "New-" Scrapbook Page Open a new Scrapbook Page dialog box, enter: EX01_SCRAPBOOK in the file name column, then click Finish. This will save a file called EX01_SCRAPBOOK.JPAGE. This file will be displayed in the package explorer and automatically open in the edit view. Figure:
【image】
This way, you can enter the code we want to test in the edit view. It should be noted that you must use the package name of the reference main () method in your code. such as:
String [] args = {};
com.test.ex01.helloWorld.main (args);
Figure:
【image】
Check all the code, right click, select Execute (Like, you can select RUN- "Execute). The result will be shown in DEBUG observation mode, as shown in the above figure.
2. Use Quick Fix
Add two lines of statements on the basis of the previous code to output today's date.
Package com.test.ex01;
/ ** * @Author kevin lee * * / public class helloworld {
Public static void main (string [] args) {outstring = "Hello, World!";
Calendar rightnow = calendar.getinstance ();
System.out.println (outstring rightnow.gettime ();}}
Figure:
【image】
There are some problems here: Variable Outstring has no statement, and the Calendar class is not imported.
Eclipse will automatically display these errors and give the corresponding prompts based on the error. Note that there is a yellow light bulb and red × on the left side of the code editor, which is called Maker Bar. The logo and red × mark indicates that Quick FIX is valid for these errors. Similarly, note the red rectangle on the right side of the code editor, which is called OverView Ruler. This means that these statements Quick FIX can be repaired. The red rectangle represents a compile time error.
If you put your mouse in the first bulb, you will find the "Outstring Cannot Be Resolved", as shown in the figure:
【image】
You can use double-click on the bulb flag and select the changes you want to make. In the first error, click "CREATE LOCAL VARIABLE 'OUTSTRING'" to fix, the second error can be corrected by "Import 'Calendar'".
Eclipse's Quick FIX enables developers to find faster, and change errors. This is very good!