Skip to content

Hello, World!! JavaShell Introduction

Zhibo Chen edited this page Feb 8, 2017 · 7 revisions

##This guide is written on Release 0.1.x

#This is a Hello, World guide on JavaShell.

##Setup Development Environment After following install instructions, you should have four class files in your directory. If not, compile the source.

$ javac *.java

##Boot the shell

$ java JavaShell

There should be a welcoming message.

##Load a class Objects are the building blocks of this shell script. Before execute any method, make sure that there is at least one working instance.

We are going to play around Integer class first.

>>> load java.lang.Integer 12

JavaShell will attempt to construct an Integer object with the constructor that takes String 12 as argument. You should see a message that says the construction is successful. Also notice that the command prompt changes the current operating instance's class name.

##See what actions are available Type ls followed by a space at the prompt.

java.lang.Integer >>> ls

ls will list all the methods with their arguments at the command line prompt. You can call any method listed with apporiate argument.

##Calling a method on a java object To call a method with no argument, simply type the method's name followed by a space. For example, if we were to call this Integer's toString method, we simply type

java.lang.Integer >>> toString

As you can see, the return value is 12, which is the return value of calling toString() on a Integer.


In fact, what the two lines really do is just a Java Statement.

load java.lang.Integer 12
toString

is the same as

new Integer("12").toString();

Clone this wiki locally