Intro to Java Web-Notes_Part44

Intro to Java Web-Notes_Part44 - The more intuitive result...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The more intuitive result of "value is: 7" can be accomplished by forcing the addition of the integers to happen first, via a pair of parenthesis "value is: " + (5 + 2) The + operator is often used to concatenate values to Strings in println statements: int rate : 8; int hours = 40; int pay = rate * hours; System.out.println("Pay will be $" + pay); The println will print the string "Pay will be $320" to the output console. Identifiers There are two issues to consider when choosing a name for a variable -- is it a legal name, and does it have good style? A legal name is one which the compiler is able to successfully translate. The Java rules for creating an identifier (e. g., a variable name), are that it: 0 can contain upper and lower case letters (a—z and A-Z), - can contain numeric digits (0-9) 0 can contain the special symbols of underscore ('_') and dollar sign ('$’) - the first character of an identifier cannot be a digit - it cannot be a reserved word Therefore, the following are valid identifiers - taXRate ° taX4Me ° TAX_ME - taX$toPay and these are not valid ° 4best (cannot start with a digit) - three@front (@ is not an allowed character) ° tax me (the blank between "tax" and "me" is not an allowed character -- an identifier is one continuous word) Style is a separate issue. Just because an identifier will compile successfully does not mean it is one that a Java programmer would find acceptable. Java programmers, generally, prefer that variable names use all lower case letters (including the first character of the identifer) and except when starting an interal word (i.e., the first letter of an internal word is upper case). Using digits is generally acceptable, but do not use the underscore or the dollar sign. Therefore, the following all good identifiers, with respect to style, for variable names: 0 taXRate - taxes4December 0 doors - houseSalesBeforeSummer These are generally not considered to be good style for variable names (or at least I do not consider them to be good style): - taX_rate - TaxRate ° taXRATE - Doors 0 taX$s - house_sales_before_summer 0 _bread The style for class names is the same as for variable names, except class names should always start with an uppercase letter. Therefore, these are good style for class names: - Houses - FederalTaxes - Auto - FirTrees and these are not good style for class names: - houses - federalTaxes - federalTAXES - Fir_Trees Binary Numbers A computer is just a machine, but it is a machine that keeps track of information, such as letters and numbers. Unfortunately, the computer does not have anything as fancy as a human brain, so keeping track of letters and numbers is a bit difficult. The computer records information in its memory using rows of bits. A bit is something like a tiny light bulb which is either on or 015’. In realitiy, a computer bit is a capacitor and a transistor working together -- the capacitor is either storing a small electric charge (i.e., is on) or is not storing a charge (ofl). The transistor helps the process of turning the capacitor on and off, and also is used to read the current state of the capacitor (i.e., it can check if the capacitor is on or ofl). A set of bits can have different patterns of on and ofl to represent to different values. A similar system that we see everyday is a traffic light. A traffic is a row of three light bulbs, and different on/off patterns have different values: on off means STOP off off on means YIELD off off off means G0 on On a computer the different on/off patterns indicate different numeric values. The computer puts the bits into small groups called bytes (a group of eight bits). Each group is given a different on/off pattern to represent a specific number. For example, if we look at a byte that has all of the bits turned off: off off off off off off off off means 0 and if only the last transistor turned on off off off off off off off on means 1 If the last two bits are turned on off off off off off off on on means 3 When referring to the value of bits people typically write a 0 for ofl and a l for on. So the values shown above could be written as follows: 0 O O O O O O 0 means 0 ...
View Full Document

This note was uploaded on 11/17/2010 for the course CIS 1500 taught by Professor Staff during the Summer '08 term at Oakland CC.

Page1 / 2

Intro to Java Web-Notes_Part44 - The more intuitive result...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online