JGrasp+Tutorial

Here's how to use JGrasp. Add tips/tricks as you come across them. We're looking for pictures to go along with this text.toc

^ Alternative to "GetConsoleString"
Here's some code you can type instead of the entire GetConsoleString method. Note the comments for what needs to be added to a simple java program you already know how to write.

code format="java" import java.io.*; // needed for keyboard reader import java.util.*; // ditto

class NewInputClass {

// This statement sets up a keyboard "reader" called "keyboard" static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

public static void main(String args[]) throws IOException //add the "throws IOException" {       String myStringVal = new String(" "); //create a simple string

System.out.print("Enter your name: "); myStringVal = keyboard.readLine; // this runs the keyboard reader System.out.println("Hello " + myStringVal);

} }

code

^ Compiling a class
click on the + sign click the running man to make sure what you created works basically just follow the directions and examples in the book

^ Running a compiled program
click the running man

^ Saving
Remember: the name of your .java file MUST be the same as your class declaration in the text. For instance:

MyFirstProg.java must include this as the first line of your class statement: class MyFirstProg

^ Common errors and what they mean

 * expected:
 * forgot to put a semicolon
 * some part of the code is wrong, and the compiler expected an end of line

possible loss of precision
 * you probably tried to set a float to a value, but you needed to type (float) before the value (i.e. **float x = (float) 4.45** )

cannot resolve symbol means you didnt declare the variable

Already defined in main/java.lang.String
 * You defined the same thing twice.