Programming in Java on Your Computer
- Classes and Objects in BlueJ
- Trying out Code in BlueJ
- The Code for Creating and Using Objects
- Source Code and Methods
- Accessors and Mutators
- Constructor Code
- Class Code
- Simple Debugging
- Interactive Picture
- Refactoring Code with Inheritance
Trying out Code in BlueJ
Premium Content - Free Preview
While the previous node demonstrated trying things out with BlueJ's visual interface, this node will cover trying things out in code.
Trying Out Code
It is often convenient to quickly try out code without having to put it into a whole program and compile it. However, since Java is a Compiled Language, it doesn't come with a built-in "tryer-outer". BlueJ solves this issue by providing a CodePad for this purpose.
The codepad should be visible on the bottom right corner of BlueJ. If it isn't, click on View > Show Codepad.
Using the Codepad
To evaluate an expression in Java, just type it into the codepad and hit "enter" . Don't put a semicolon at the end of the line. For example:
1+1 2 (int) "hello".length() 5 (int)
You can also access objects that were created earlier in the codepad, or on the Object bench. For example, if you created a Student
student1 earlier, you could type:
student1.getStudentID() "ID 00234" (String)