A series of exercises for learning Java programming basics using BlueJ IDE. Topics covered include installing BlueJ, creating a new project, writing and running a method, printing statements, and understanding variable declarations and assignments.
Download BlueJ Lab Exercises: Java Programming Fundamentals and more Exercises Java Programming in PDF only on Docsity!
LAB 01: BlueJ
EXERCISE 01:
Install BlueJ on PC. Figure 1
Create a new project in BlueJ, name it LAB1. Figure 2
Create a class in that project called MyFirstLabFigure 3
Write a method in that class called printStuff
In printStuff , print a line like this but use your own name Hi! My name is Bruno Mars Figure 4
OUTPUT:
Figure 7
EXERCISE: 03
Add a println statement that prints the sum of the numbers 8355 and 429
Add a println statement that multiplies the numbers 34 and 17 and prints the result
The multiplication operator in Java is * Figure 8
OUTPUT:
Figure 9
EXERCISE :
Add a println statement that prints the following sentence on one line:
This is a pretty long sentence if you ask me not that you asked me but if you did I'd say it was.
We want to keep each line of code relatively short (easier to read).
But you can't split a character string across two lines of code! Try it.
Instead, split the string up into separate strings and concatenate them together.
Figure 12 OUTPUT: Figure 13
EXERCISE:
Add a block comment to your program above the class: **/**** *** This is my program for Lab 1.
@author your-pid-here
@version 2018.01. /*
If you type /** and hit return it will add the * automatically.
Add another comment above the method: /**** *** This method helps me practice printing. */
Figure 14
EXERCISE:
A variable is the name given to a memory location in which a value is stored.
The variable's type must be declared before it is used. It can also be given a value in the declaration: int total = 54;System.out.println("The total is " + total);
Change the value with an assignment statement: total = 75;