Eclipse Scrapbook to quickly test Java code

Scrapbook is a special function provided by Eclipse, through which it can quickly run a piece of code. You don't need to write any Class and main methods, you can directly write arbitrary Java code to execute the test.

1) Create a Scrapbook Page
Click File menu > New > Other > Java > Java Run/Debug > Scrapbook Page, enter the File name, select the save location, and a new file with the extension .jpage will be created.



2) Write test code You can write any test code
in the .jpage file, including defining classes and creating objects, such as:
System.out.println("Hello world");

***Be careful not to define static methods!


3) Execute the test code
Select the code to be executed, right-click and select Inspect, Display, Execute, the code can be executed, and the output of the program can be seen in the Console.


Select "Display" to execute, you will see the execution return value of the selected code.


Select "Inspect" to execute, you can check the specific information of the variable.


***It is the same as when the code stops at a breakpoint when debugging a program!

4) Stop the execution
Click the red box Stop the Evaluation to end the code execution.

The problem with Package is that by
default, no package or class is imported in the .jpage file. Each class needs to use the full class name, such as: java.util.ArrayList. The method of importing a package: Click on the Import Declaration of the Toolbar and import it through Add Type/Add Packages.


The problem of third-party jars The
Scrapbook page uses the classpath defined by the project, and all jars imported in the project (Project Properties > Java Build Path > Libraries) can be used directly.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327063369&siteId=291194637