How to Create a Project
- 1) After opening up BlueJ, select 'new project.' Let's call our first BlueJ project "FirstProject".
- 2) Your screen should now look like this picture. The blank document with the turned corner represents the project:
How to Create a Class in a Project
- Not surprisingly, the way that you create a new class is to click on the "new class" button!Hello World
- Let's call our first class "HelloWorld". By convention class names start iwth a capital letter though Java does not require this.
You cannot have a blank space in the name of a class. ie "HelloWorld" is perfectly ok. "Helloworld" is just as valid of a classname but "Hello World" is NOT a valid class name.
- Now let's actually start programming!. To do so, right click on the "HelloWorld" icon and select 'Open Editor'
- Now, if you've never programmed before, you may see a lot of daunting looking stuff! Eventually though, what you are looking at below will seem quite familiar and not daunting at all. Here's what my version of BlueJ has as the default code of each class.
- Now, let's add the code that will print out Hello World when we run the program. Add the following line of code inside the Constructor of HelloWorld.
- Now that we are done writing our code, let's close the the editor. We must now 'compile' our source code into bytecode. To do so right click on the project and select 'compile'
- Once the class has been compiled it is no longer striped. We can now run our class.
Running our first BlueJ Class
- To run the class, just right click on the HelloWorld icon and select 'new HelloWorld()'
- There will be a prompt asking you for the instance name. You can use whatever you want here. You can use any valid identifier (an identifier can't have spaces and can't start with a number)
- Finally, our first BlueJ class has been compiled and run. You should see the output that is pictured below
- (see lower part of the page)