ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

ECLIPSE IDE Tutorial - Experimenting with JAVA Expressions and Statements with Snapshot

Updated on August 6, 2014

JAVA Primitive Data Types

Before experimenting with expressions, it might be a good idea to see what the primitive (basic) data types exist in the JAVA language.

The first thing to note that JAVA is a static typed language, that is a variable must first be declared before it is used.

For example, an integer is one of the basic JAVA data types. Suppose we want to have a class field for the year a person is born. We first must have a statement,

int yearBorn;

defined before we can use it in a program. This statement is known as a declaration.

It is permissible to have the statement also perform an assignment, so

int yearBorn=1954;

is a legal statement. Also, multiple variables can be combined on a single statement.

The primitive types in the JAVA language are:

  • byte - is an 8-bit signed two's complement integer. It value range is -128 (minimum) and to 127 (maximum). The byte is an historic artifact in that at one time computers had a word length of 8-bits. Its use is rather infrequent today but can be used in applications which have a large number of occurrences with a limited range of values. Example assignment; variableByte = 0;
  • word - is a 16-bit signed two's complement integer. It value range is -32,768 (minimum) to 32,768 (maximum). Example assignment: variableWord = 0;
  • int - is a 32-bit signed two's complement integer. It value range is -231 (minimum) and to 231 (maximum).In Java SE 8 and later, int can be used to represent an unsigned 32-bit integer, its value range is 0 (minimum) and 232-1 (maximum). Example assignment: variableInt = 0;
  • long - is a 64-bit two's complement integer. Its value range is -263 (minimum) to 263-1 (maximum). In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, with a value range of 0 (minimum) to 264-1 (maximum). Example assignment: variableLong = 0L;
  • float: - is a single-precision 32-bit IEEE 754 floating point value. It should never be used where precise values are required. Example assignment: variableFloat = 0.0f;
  • double - is a double-precision 64-bit IEEE 754 floating point value. For decimal values this is generally the default choice. Example assignment: variableDouble = 0.0d;
  • boolean - has a value of true or false. This type is generally used for conditions which are either true or false. It's size is not predefined. Example assignment: variableBoolean = false;
  • char - is a 16-bit Unicode character whose values range from 0 ( \u0000) through 65,535 (\uffff) inclusive. Example assignment: variableChar = 'A';

If a field is declared but not initialized for numeric field, 0 is generally stored. For character variables an uninitialized field is null and Boolean fields are false. Local variables are treated differently, in that the compiler never assigns a value to an uninitialized variable.

With that out of the way, let's look at how ECLIPSE can help you test code snippets by utilizing the scrapbook page feature.

Setting Up A Scrapbook Page

A scrapbook page is an ideal way of testing out an unfamiliar expression or statement. It's kind of like using a scratch pad to jot down an idea. To create a scrapbook page, you start at New on the tool bar then select other. At the other menu you select Java Run/Debug and click on scrapbookpage. You choose a parent folder (which is important if you will be working on testing expressions for this project on multiple occasions. You enter a name to identify the scrapbook page. Choosing a good name is important, it will help jog your memory as to what types of statements you were working with. The following screenshots should serve as guideposts to get there.

Steps to Open a Scrapbook Page

This illustrates the point after you have selected new followed by other from the tool bar.
This illustrates the point after you have selected new followed by other from the tool bar.

Entering and Evaluating Expressions and Statements

An important point to note is you must highlight the line or lines you wish to inspect or execute. If you don't ECLISPE will be unaware of what expression or statements you wish to inspect or run.

The following three snapshots illustrate inspecting or running three code snippets.

In the first you are merely evaluating a simple mathematical expression. Namely, multiplying 3700 by 5. When the chosen text is merely an expression. To see the result of the expression you can either Choose Run followed by Inspect or click on the magnifying glass icon.

The second screenshot is a a multi-line example. Test snippets can be as involved as you have a need for them to be. Again, to evaluate you must highlight all of the lines in the snippet, then either click on the magnifying glass or choose run followed by inspect.

The third example illustrates having a JAVA statement as the code snippet. In this case you Choose run followed by execute. We will revisit the scrapbook in future to illustrate examples which involve methods from multiple packages.


In this multi-line example there are several assignment statements and an calculation. The assignments must follow JAVA syntax rules.  The last line is an expression which requires no special formatting.
In this multi-line example there are several assignment statements and an calculation. The assignments must follow JAVA syntax rules. The last line is an expression which requires no special formatting.
This is a JAVA statement. In the case of statements, select Run followed by Execute.
This is a JAVA statement. In the case of statements, select Run followed by Execute.

Scrapbook Fundamentals

view quiz statistics

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)