Paypal hosting - JavaSercer Pages 6.1.1.1 Data Data, often called variables,

JavaSercer Pages 6.1.1.1 Data Data, often called variables, can consist of primitive datatypes such as integers, Booleans, and floating-point values (both the width and height in this example are integers, represented by the keyword int). In addition, data can also be objects. The type value that a variable holds must always be declared. The following example declares a variable of the object type String: String title; Until you give a variable a value, it contains a default value (0, false, or null). The name of the variable must start with a letter followed by a combination of letters and digits. There are many special characters, such as dots and plus signs, that are not allowed in a variable name. By convention, variable names often start with lowercase letters and do not have spaces: String titleOfBook; 6.1.1.2 Methods Methods are functions that take in zero or more primitive datatypes or objects, and perform some task on the object that may or may not result in a return value. If it does, the return value is also a primitive datatype or object. Here is an example of a method: public void setHeight(int h) { height = h; } This method, called setHeight( ), takes in a single integer, uses it to set the object variable height, and returns nothing (note the void keyword before the method name). One special method that appears in Example 6.1 is the constructor. The constructor method always shares the same name as the class, and its return type is never declared. The constructor allows the object to initialize itself; it is invoked when the new keyword is used to create an instance of the class: Rectangle rect1 = new Rectangle(28,72); Here we create an instance of the class Rectangle and keep a reference to it in a variable called rect1. The new Rectangle object saves the value of the two integer constructor arguments, 28 and 72, in its internal variables, width and height. Note that Java is a case-sensitive language: height and Height are not the same. The standard naming convention for class names, unlike for variable names, is to capitalize the first letter. For both class and variable names, the first letter in internal words is also capitalized; for instance: aVeryLongNameForAVariable // VARIABLE ANameForAClass // CLASS 6.1.1.3 Statements A statement is simply an instruction to do something. For example, the following are statements in Java: area = width * height; return area; The first statement takes the value of width and height, multiplies them together, and places the result in the variable area. The second statement uses the variable area as the return value for the current method. Statements almost always appear inside of methods. In addition, all statements and variable declarations must end with a semicolon (;) in Java; this takes after other programming languages, such as C and C++. page 56
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services


Comments are closed.