-
Notifications
You must be signed in to change notification settings - Fork 0
First steps in jshell
The Java 'shell' allows testing simple one-line Java expressions without writing an actual program.
- Open File Explorer and navigate to the folder
C:\Users\Public\wpilib\2021\jdk\bin
(in earlier years it wasC:\Users\Public\frc2019\jdk\bin
) - Start the
jshell.exe
Things to try:
-
2+3
, followed by ENTER - Same, but with many spaces between
2
,+
and3
-
2*(3 + 4)
, followed by ENTER -
2*(3
, ENTER,+ 4)
, followed by ENTER -
Math.sin(Math.PI/2)
, ENTER
==> The computer can compute, it understands how formulas "work", and spaces usually don't matter.
At the end of each line, remember to type ENTER:
10/5
10/3
10%3
10.0/3
"Hello !"
"Two and two make " + 2 + 2
"Two and two make " + (2 + 2)
==> There are different data types. Integer vs. floating point numbers, Strings.
int points=0
points
points = points + 10
points += 5
"I have " + points + " points"
String name = "Freddy"
"Hello, " + name + ", nice to meet you!"
==> Variables can store values.
When you define a variable, you need to specify its type:
int
for whole numbers,
double
for floating point numbers,
String
for text
(more details will follow in https://github.com/team2393/FRC/blob/master/src/main/java/first/Types.java).
When you count people, you tend to count whole people. Do you count whole apples, or is there such a thing as half an apple? How many apples will there be per person?
- int people = 2
- double apples = 5
- apples / people