JShell guide - variables

created onJanuary 28, 2022

declaring variables

Variables can be explicitly declared. For expression that don’t have a named variable, an implicit variable (scratch variable) is created so that the value can be referenced later. All variables of a session can be listed with or

jshell> int whatever = 23 whatever ==> 23 jshell> 23 + 42 $2 ==> 65 jshell> /var | int whatever = 23 | int $2 = 65 jshell>

listing variables

Variables can be listed with the command. without parameter lists all active variables. accepts the follwing parameters:

  • : lists all variable definitions including, failed, overwritten, dropped and startup variable definitions. Failed and dropped variable definitions are marked as ‘(not-active)’
  • : lists the variable definitions in startup scripts.
  • : lists the variable definitions with name . One or more names can be provided as parameter, separated by space
  • : lists the variable definitions with id . One or ore ids can be provided as parameter, separated by space. Ids can also be provided as one or more id ranges, separated by space.