Java Programming Notes # 1516

  • Preface
    • Normal
    • Viewing tip
      • Figures
      • Listings
      • Tables
    • Supplementary materials
  • Preview
  • Dialogue
    • Getting began
    • Creating and animating an Alice world
    • Objects in 3D house
    • A easy Alice program
  • Assets
  • Full program listings
  • Copyright
  • Concerning the creator


Target market

The target market for this text consists of skilled programmers who would really like an attention-grabbing diversion from work whereas consuming lunch at their desk, and skilled programmers who’ve youngsters, grandchildren, siblings or associates who must learn to program.

An attention-grabbing diversion

In the event you spend your lunch hour at your desk consuming a sandwich, enjoying Cub Rummy, watching outrageous movies at YouTube, or watching bad-news movies in your favourite information channel, all it’s a must to present for it on the finish of the lunch interval is indigestion.  Nonetheless, for those who spend that point utilizing Alice to create an animation video of the ice skater proven in Determine 11 leaping over three or 4 of the characters in Determine 1, you could possibly present it off to your friends and brag somewhat on the finish of the lunch interval.

Educating youngsters to put in writing pc packages

On a barely extra severe observe, have you ever ever had the thought that you simply wish to educate your teenager to program?  Your motive could merely be to attempt to make them conscious that there’s extra to a pc than a device for hanging out at, visiting YouTube, or enjoying pc video games written by others.

No approach!

While you talked about that chance to your teenager as casually as you could possibly, did she roll his eyes and provide you with a glance which means “No way!”

No matter your motive for considering that it could be helpful to your teenager to study somewhat about pc programming, there may very well be a approach to curiosity that teenager in studying to program.  That approach is a really spectacular Java program named Alice, which may make studying to put in writing pc packages enjoyable even for youngsters.  (It would give them the looks of being players, which might be extra socially acceptable than the looks of being nerds.)

Disclaimer: Professor Baldwin has no vested curiosity in Carnegie Mellon College or the Stage3 Analysis Group.  He’s an unbiased creator whose solely curiosity in Alice is that {of professional} growth.

A Java program from Carnegie Mellon College

Alice is a pc program written in Java by the Stage3 Analysis Group at Carnegie Mellon College that makes it simple to put in writing object-based, occasion pushed, 3D animation and sport packages with a forged that may be chosen from tons of of accessible objects.  A small sampling of the out there objects from the Alice class gallery is proven in Determine 1.

Determine 1. A sampling of the objects out there in Alice.

On this article, I gives you some background on the Alice program, and describe a few of its options.


Alice just isn’t a toy

Alice just isn’t a toy designed solely to create fairly footage.  Relatively, Alice is a full-featured programming language designed to be used in instructing programming to newbies on the idea of programming rules which are nicely acknowledged inside the pc science group.  For instance, Alice helps virtually all the elementary programming ideas that now we have taught for a few years within the programming fundamentals course on the group faculty the place I educate.

A severe 3D graphics programming atmosphere

Here’s a citation from the initiatives web page of the Stage3 Analysis Group:

Alice is a 3d graphics programming atmosphere supposed to be a delicate first introduction to college students starting from sixth grade to school, sometimes college students who wouldn’t take (or go!) a programming course.

Elimination of frustration

The Alice undertaking was motivated by the truth that for many first-time college students, the expertise of studying to program has been crammed with frustration. Hours of making an attempt to grasp syntax errors in pursuit of a working Fibonacci sequence era program have lead many college students to conclude that Laptop Science is uninteresting earlier than they’ve accomplished a single course.

The purpose of Alice

The purpose of the Alice undertaking is to alter the primary expertise college students have with pc programming. We consider that Alice will change the expertise of studying to program in two important methods: eradicating pointless frustration and offering an atmosphere by which starting college students, of each genders, can create packages they discover compelling.

Drag-and-drop as an alternative of sort

Persevering with with quotations from the Stage3 Analysis Group:

When college students create packages in Alice, they don’t sort. As an alternative, they drag and drop phrases representing instructions that objects within the 3D scene perceive.

For instance, a scholar could instruct a bunny within the 3D scene to “move forward” or “look at the camera.”

Alice is full featured

Along with straight-forward instructions, college students also can drag conventional programming constructs, corresponding to “if,” “loop N times,” “do while something is true,” and many others. College students can assemble “If” statements by dragging questions like “is the carrot near the rabbit” or “how tall is the tree” into them.

Though the terminology is deliberately simplistic, Alice is definitely an entire programming atmosphere, supporting arrays, lists, features with parameters, recursion, and an object-based knowledge mannequin. As well as, strategies could be saved as a part of an object after which loaded into totally different 3d “worlds” created with Alice.

And would possibly I add that Alice offers a rudimentary system for writing event-driven packages, making it appropriate for writing video games and tutorial packages for youthful youngsters.

Why does Alice succeed?

Alice succeeds for a number of elementary causes

  1. By eradicating typing and the flexibility to make a syntax error, Alice removes a lot of the preliminary frustration for brand new programmers,
  2. The concepts of information and objects are very concrete when college students can *see* what they’re, and
  3. Virtually all adjustments to this system state are seen and animated, so debugging is a a lot much less obscure process it’s a lot simpler to appreciate that “the rabbit moved backwards when I meant to for it to move forward” than to appreciate that “I subtracted one from the integer ‘x’ when I intended to add one” (significantly when ‘x’ isn’t instantly seen on the display screen).

Alice 2.0 is free and sensible

See also  Best Settings to Speed up uTorrent [Guide With Screenshots]

The Alice 2.0 programming atmosphere could be downloaded freed from cost from Carnegie Mellon College.  Moreover, it doesn’t require a Home windows set up.  All that’s required to run Alice is to:

  1. Obtain the zip file containing the Alice atmosphere.
  2. Extract the information and directories from the zip file into an area listing.
  3. Double-click on one of many exe information which are extracted from the zip file.

As soon as the zip file is downloaded, additional entry to the Web just isn’t required.  Many lessons for creating 3D objects are saved regionally in an space that known as the gallery.  Nonetheless, as a way to preserve native disk house, the lessons for a lot of different objects should not routinely included within the native class library.   Relatively, they are often accessed from an internet model of the category gallery.

Matches on a 256 mbyte USB flash drive

Your entire native model of the Alice growth atmosphere will match on a 256 mbyte USB flash drive, and could be executed instantly from the flash drive.  This makes it attainable for college kids to hold the event package with them from one pc to a different.

Improved accessibility

The usage of the drag-and-drop programming paradigm causes Alice to be far more accessible to starting programming college students than languages corresponding to Java, C++, and C# that require in depth keyboard exercise to be used.  A scholar who can sort a number of strings with one finger and function a finger-driven mouse pad can write Alice packages simply as quickly and successfully as a scholar who can sort 60 wpm.

What about Alice documentation?

Having been instructing and programming in Java for the previous ten years, I’ve turn out to be spoiled by the supply of in depth detailed Java documentation.  In my view, the primary factor that’s missing from Alice 2.0 is nice documentation.

As a result of I’m planning to show a programming fundamentals course utilizing Alice within the close to future, I contemplate a very good set of documentation to be very important to the success of that course.  Apparently nevertheless, a lot of the efforts of the Stage3 Analysis Group at Carnegie Mellon are actually being devoted to the event of Alice 3.0.  Subsequently, I don’t count on a lot in the best way of extra documentation on Alice 2.0 to be forthcoming from that group.

Alice documentation by Dick Baldwin

Subsequently, I’m creating a type of documentation by myself.  I’m making it freely out there on-line at

Sending e-mail to Dick Baldwin
Ship your e-mail message to and embody the phrase Alice surrounded by areas within the topic line to trigger the message to bypass my spam blocker.  (Notice that if the spammers catch onto this, I’ll modify these directions later.)

This documentation will embody a mixture of educational classes explaining the way to program utilizing Alice and appendices containing barely extra formal descriptions of assorted options of the language corresponding to strategies, features, and occasions.  Please be happy to make use of the documentation, and likewise be happy to contact me through e-mail to make ideas relating to attainable enchancment within the documentation.

Viewing tip

I like to recommend that you simply open one other copy of this doc in a separate browser window and use the next hyperlinks to simply discover and think about the figures, listings, and tables if you are studying about them.


  • Determine 1. A sampling of the objects out there in Alice.
  • Determine 2. The Alice splash display screen.
  • Determine 3. The scene edit mode.
  • Determine 4. An airplane with its 3D axes uncovered.
  • Determine 5. A Coach object.
  • Determine 6. Left arm of the Coach object.
  • Determine 7. Coach’s arm turned 90 levels to the appropriate.
  • Determine 8. Coach’s arm turned backwards by 180 levels.
  • Determine 9. Coach’s arm rolled proper by 45 levels.
  • Determine 10. Coach’s arm pointing to the left and up with palm up.
  • Determine 11. Skater’s beginning and ending pose in program Alice0125f.
  • Determine 12. Animation shot from program Alice0125f.
  • Determine 13. A decreased display screen shot of the Alice program edit mode.
  • Determine 14. Object tree with iceSkater object expanded.
  • Determine 15. Diminished display screen shot of Occasions space in program edit mode.
  • Determine 16. Diminished display screen shot of edit pane in program edit mode.
  • Determine 17. Display screen shot of strategies tab in particulars space for iceSkater object.
  • Determine 18. Display screen shot of properties tab in particulars space for iceSkater object.
  • Determine 19. Display screen shot of features tab in particulars space for iceSkater object.


  • Itemizing 1. Occasions for this system named Alice0125f.
  • Itemizing 2. The primary technique for this system named Alice0125f. 
  • Itemizing 3. Supply code for the tactic named setTheStage.
  • Itemizing 4. Supply code for technique named playTheShow.
  • Itemizing 5. Supply code for this system named Alice0125f.


  • Desk 1. Normal primitive strategies in Alice.
  • Desk 2. Normal features belonging to things.
  • Desk 3. Classes of features on the earth.
  • Desk 4. Customized strategies for a penguin object.
  • Desk 5. Occasion varieties in Alice.
  • Desk 6. Allowable varieties in Alice.
  • Desk 7. Management buildings in Alice.

Supplementary materials

I like to recommend that you simply additionally research the opposite classes in my in depth assortment of on-line tutorials.  One can find a consolidated index at


The remaining sections of this text will comprise temporary discussions on the next matters as they pertain to Alice:

  • Getting began
  • Setting the stage
  • Objects in 3D house
  • A easy Alice program


Getting began

Alice just isn’t an object-oriented programming (OOP) language

Whereas Alice is an excellent product for instructing object-based programming, in my view Alice just isn’t an object-oriented programming language.

A real OOP language should make the next options out there to the programmer:

  • Encapsulation
  • Inheritance
  • Polymorphism

Alice helps encapsulation fairly nicely.  As well as, it makes an inexpensive gesture in direction of making inheritance out there to the Alice programmer.  Nonetheless, there is no such thing as a semblance of help for polymorphism.

As well as, there are quite a few detailed options (such at sort casting) which are anticipated from a real OOP language which aren’t out there in Alice.

See also  Spider Man Homecoming Full Movie Download online HD

Makes writing 3D graphics a breeze

Nonetheless, the Alice program makes it attainable for a scholar to study in a number of months the way to write 3D animation packages that might in all probability require the coed to review for years if he have been programming in hard-core Java 3D as an alternative of utilizing a Java program to put in writing his packages in Alice.

Whereas Alice just isn’t a totally object-oriented programming atmosphere, it’s object-based and subsequently may be very appropriate for getting a scholar began down the street in direction of object-oriented programming.

Downloading, putting in, and working Alice

The set up of Alice on a Home windows XP pc may be very simple.  No formal “Windows Installation” is required.  All the coed must do is to obtain a zipper file from the Alice web site (see Assets) and to extract its contents right into a listing of his selection on his exhausting disk.  (Alice can be out there for the Macintosh, however I’m not certified to supply any info in that space.)

As soon as the coed has extracted the information from the zip file, he double-clicks on one in every of two executable information to begin Alice working.  The 2 information are:

  • Alice.exe
  • SlowAndSteadyAlice.exe

Why two information?

As I perceive it, the file named Alice.exe is to be used with computer systems having high-quality {hardware} graphics functionality, whereas the file named SlowAndSteadyAlice.exe is to be used with computer systems that don’t have that functionality.

The scholar ought to first strive double-clicking on the file named Alice.exe.  If that works OK, use it.  If not, double-click on the file named SlowAndSteadyAlice.exe.

When issues go proper

If issues go proper when the coed double-clicks on the exe file, the flash display screen proven in Determine 2 ought to seem on the display screen.

Determine 2. The Alice splash display screen.

For extra info on the Alice growth display screen and the testing of an set up, comply with the hyperlink to the tutorial titled “Getting Started” in Assets.

Creating and animating an Alice world

Creating and animating an Alice world consists of two very distinct steps.  Step one, which I discuss with as setting the stage, is just like setting the stage for a stage play or a film manufacturing.  It entails the method of portray surroundings, deciding on costume colours, placing the gamers, the surroundings, and different objects of their appropriate positions on the stage, and preparing for the curtain to rise, or the cameras to roll.

A small portion of the hassle required to set the stage have to be completed manually exterior of this system code.  The rest of the hassle to set the stage could be completed both exterior of this system code or utilizing program code, relying of the preferences of the programmer.  As I’ll illustrate within the easy Alice program that I’ll current and clarify later, my desire is to perform that effort utilizing program code.

The second step in creating and animating an Alice world is to put in writing this system code to animate the world inflicting the gamers to behave based on the script.

Two main edit modes

The Alice growth display screen could be switched between two main edit modes:

  • Scene edit mode
  • Program edit mode

Determine 3 reveals a drastically decreased display screen shot of the scene edit mode.

Determine 3. The scene edit mode.

An image of the world

The image of the inexperienced grassy space on the prime middle reveals a picture of the present state of the world together with the objects which were added to the world.  (The one object that has been added to the world in Determine 3 is the bottom.)

The gallery

The underside of the display screen in Determine 3 reveals the graphical consumer interface into the category library referred to as the gallery.  That is the place you go to search out lessons from which to instantiate objects and add them to the world.  This space additionally comprises a hyperlink to a web-based gallery the place you can find much more lessons from which to instantiate objects.

The rest of the scene edit display screen

You’ll be able to find out about all the different options of the event display screen in scene edit mode by following the hyperlinks to the assorted tutorials listed in Assets.

More often than not, you’re employed within the scene edit mode whereas setting the stage.

Instantiating new objects

One of many limitations of Alice as in comparison with different programming environments corresponding to Java, C++, and C# is that objects can’t be created and destroyed dynamically at runtime.  Relatively, all objects have to be manually created and added to the world in scene edit mode exterior of program code.  These objects that aren’t wanted in a selected scene can both be moved off digicam or made invisible or probably each.

Strategies, features, and properties
In Alice, features all the time return a worth and strategies by no means return a worth.  A property is a variable belonging to the item, which might in all probability be referred to as an occasion variable in Java.

The members of an Alice object

All the things in an Alice world, besides probably the world itself is an object.  All objects in Alice (apart from the world itself) encapsulate twenty customary primitive strategies, about twenty-nine customary features, and a good variety of properties.  This consists of the objects that symbolize the digicam, the sunshine, the bottom, and objects instantiated from lessons within the gallery.

A listing of the twenty customary primitive strategies is introduced in Desk 1.

Desk 1. Normal primitive strategies in Alice.

Primitive strategies in Alice 2.0

  1. transfer(path,quantity)
  2. flip(path,quantity)
  3. roll(path,quantity)
  4. resize(quantity)
  5. say(what)
  6. assume(what)
  7. playSound(sound)
  8. moveTo(asSeenBy)
  9. moveToward(goal,quantity)
  10. moveAwayFrom(goal,quantity)
  11. orientTo(asSeenBy)
  12. turnToFace(goal)
  13. pointAt(goal)
  14. setPointOfView(asSeenBy)
  15. setPose(pose)
  16. standUp()
  17. moveAtSpeed(path,pace)
  18. turnAtSpeed(path,pace)
  19. rollAtSpeed(path,pace)
  20. constrainToPointAt(goal)

To study extra concerning the primitive strategies in Alice, comply with the hyperlink to the tutorial titled “Appendix A, Behavior of Primitive Methods” in Assets.

Controlling movement and viewpoint

As you possibly can see, a lot of the primitive strategies proven in Desk 1 need to do with movement, place, and orientation (viewpoint).  The Alice programmer has full movement management over all the objects on the earth together with the digicam, the sunshine, and the bottom.  (The world has no primitive strategies and can’t be moved or re-oriented.)  Moreover, the programmer could cause the motions of various objects to happen both concurrently, so as, or a mixture of the 2.

See also  Best Neva Tech Air Buds Review Based On User Rating

Technique parameters

With one exception, all the primitive strategies have one or two required parameters, that are pretty intuitive in nature.  (A number of should not so intuitive, which is likely one of the causes that I wrote and revealed Appendix A, which is referenced in Assets.)

As well as, most and doubtless all the primitive strategies have optionally available parameters with default values.  (In my writings, I refer to those parameters as default parameters.) When writing an Alice program and calling one in every of these strategies, you possibly can both settle for the default values, or present totally different values.

Three very attention-grabbing default parameters

Three of the default parameters that a lot of the primitive strategies have are:

  • length
  • fashion
  • asSeenBy

These should not the one default parameters.  They’re merely those that I elected to focus on on this article.

The length parameter

The length parameter specifies the period of time that will probably be required to perform the motion dictated by the tactic.  The default worth is one second, however you possibly can set it to any worth you select, together with zero for those who want the motion to be accomplished in a short time.  This can be a parameter whose worth you’ll ceaselessly change.

The fashion parameter

The fashion parameter specifies the conduct of the motion firstly and the tip.  The choices are:


The default is the primary merchandise within the listing.  That selection could be acceptable, for instance for the movement of an object in house beneath the affect of mass and inertia.  I discover a want to alter the worth of this parameter a lot much less ceaselessly than the worth of the length parameter for instance.

The asSeenBy parameter

The asSeenBy parameter is especially attention-grabbing.  The default worth is the item on which the tactic known as.  Nonetheless, some very attention-grabbing results could be achieved by setting the worth to a distinct object.  In that case, the impact will rely upon the elemental conduct of the tactic.

For instance, one of many pattern packages that I clarify within the classes referenced in Assets makes use of this parameter to trigger a hungry shark to circle a hapless bunny within the water.  A second use of this parameter causes the digicam to circle the unlucky scene under as if the digicam is in a information helicopter witnessing the scene.

One other instance that I current in these tutorial classes makes use of this parameter to trigger an airplane to fly loops.

Normal features

Desk 2 reveals the usual features that belong to most, if not all objects aside from the world, together with the digicam, the sunshine, and the bottom.  These features are referred to as for quite a lot of functions in an Alice animation program.

Desk 2. Normal features belonging to things.

Normal features

  1. isCloseTo(threshold,object)
  2. isFarFrom(threshold,object)
  3. distanceTo(object)
  4. distanceToTheLeftOf(object)
  5. distanceToTheRightOf(object)
  6. distanceAbove(object)
  7. distanceBelow(object)
  8. distanceInFrontOf(object)
  9. distanceBehind(object)
  10. getWidth
  11. getHeight
  12. getDepth
  13. isSmallerThan(object)
  14. isLargerThan(object)
  15. isNarrowerThan(object)
  16. isWiderThan(object)
  17. isShorterThan(object)
  18. isTallerThan(object)
  19. isToTheLeftOf(object)
  20. isToTheRightOf(object)
  21. isAbove(object)
  22. isBelow(object)
  23. isInFrontOf(object)
  24. isBehind(object)
  25. getPointOfView
  26. getPosition
  27. getQuaternion
  28. getCurrentPose
  29. partNamed(key)

Features on the earth

The world offers greater than fifty different features, most of a really utilitarian nature.  They’re organized into classes.  The classes together with some examples are proven in Desk 3.  You’ll observe that lots of the features in each Desk 2 and Desk 3 have a definite Java-like look.

Desk 3. Classes of features on the earth.

Classes of features on the earth

  • boolean logic instance:  (a && b)
  • math instance:  a != b
  • random instance:  Random.nextDouble()
  • string instance:  what.toString()
  • ask consumer instance:  NumberDialog(query)
  • mouse instance:  Mouse.getDistanceFromLeftEdge()
  • time instance:  getTimeElapsedSinceWorldStart()
  • superior math instance:  Math.IEEERemainder(a,b)
  • different instance:  getVector(proper,up,ahead)

You’ll ceaselessly want to tug these features and drop them onto placeholders in expressions within the edit pane to assemble the specified expressions in your statements.

Customized strategies

Some objects instantiated from lessons within the gallery comprise customized strategies along with the primitive strategies.  For instance, Desk 4 reveals the customized strategies which are supplied by Alice for a penguin object.

Desk 4. Customized strategies for a penguin object.

Customized strategies for penguin object

  • wing_flap(occasions)
  • leaping(top)
  • turn_head_right()
  • turn_head_left()
  • glide()
  • soar(occasions)
  • stroll(move_times)
  • strolling(x)

Customized strategies could or could not have default parameters, relying on whether or not or not the creator of the tactic created them.

Defining and saving a category

When you create an object and add it to a world, you possibly can outline and add new strategies, features, and properties to the item.

After you add strategies, features, and/or properties to an object, you possibly can export and save the category that’s represented by the present configuration of the item.  You need to use that new class to create extra objects in the identical world, or you should use it later to create objects for a distinct world.  If you want to take action, you possibly can add it to the gallery.  This represents a rudimentary type of inheritance, and is the mechanism by which you’ll be able to create a library of customized lessons.

Varied selections for setup

Apart from the guide creation of the objects, which is required, the method of setting the stage could be completed both manually or utilizing setup code firstly of this system (as I’ll do in a pattern program later on this article), or utilizing a mixture of the 2.

Objects comprise part elements

Most of the Alice objects comprise varied part elements (see Determine 14), that are additionally objects.  Examples of part objects are the legs, arms, and palms of an object that represents an individual, the propeller, wheels, and fuselage of an airplane, the top, wings, and toes of a penguin, and many others. 

Creating and saving a pose

Typically the method of setting the stage entails manipulating the assorted elements of an object to create a pose.  If you’re doing a guide setup, you’ve a selection of doing

Leave a Reply

Your email address will not be published.