Oracle DBA Forum  

Вернуться   Oracle DBA Forum > Oracle University Official Study Notes (ENG) > Oracle 10g Java Programming > Oracle 10g Java Programming

Ответ
 
Опции темы Опции просмотра
  #1  
Старый 14.01.2010, 01:19
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию 04 Exploring Primitive Data Types and Operators

__________________
Чат форума (требуется аккаунт на github или twitter)
Ответить с цитированием
  #2  
Старый 14.01.2010, 01:19
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию Objectives



Lesson Aim

This lesson introduces Javas decision-making and repetition constructs. You learn how to use those constructs to build nonlinear applications. Java provides eight primitive data types and a large number of operators to manipulate these types. This lesson introduces the primitive types and describes how to use the most common operators to construct simple algorithms.


Primitive Data Types in Java

Java is an object-oriented programming language, which means that a Java program is made up of objects. For example, a Java program dealing with video rentals may have objects representing the various videos and games that are available, the customers who have rented videos, the numerous titles that are available, and so on.

If you take a look at one of these objects in more detail, however, you see that it contains fundamental values such as whole numbers, fractions, and characters. Java provides eight predefined data types to represent these atomic entities; the Java community calls these the primitive types, as opposed to object types (user-defined types) that you may define yourself, such as Customer or Title.

Declaring and Initializing Primitive Variables

Declaring primitive variables is quite straightforward. For example, to declare and initialize an integer variable to hold the number of days that a video can be rented, you can write a statement, such as the following:

Код:
  int numOfDays = 3;
This lesson describes how to declare and initialize variables of each of the eight primitive types.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:34.
Ответить с цитированием
  #3  
Старый 14.01.2010, 01:19
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию Reserved Keywords in Java




Reserved Keywords in Java

All the words in this slide are keywords in the Java language. These reserved words must not be used as variable names. There are 51 reserved words in Java2.

Additional Reserved Keywords

In addition to the keywords listed in the slide, const and goto are reserved and cannot be used as identifiers.

Instructor Note

Do not go through the list of keywords. Briefly describe the category of keywords in each box. Also make students aware of the reserved keywords in the notes.

Also, technically speaking, true, false, and null are literals, not keywords as such. Java2 has a new reserved keyword, strictfp. Null is not a Boolean type as in PL/SQL.

strictfp is used to allow for double variables to perform calculations, where the result is larger than Double.MAX_VALUE. strictfp is equivalent to FP-strict, which allows for a double expression to be evaluated as positive infinity (which the program prints as Infinity).
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:36.
Ответить с цитированием
  #4  
Старый 14.01.2010, 01:19
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию Variable Types



Variable Types

Variables are the basic storage unit in Java. A variable is a symbolic name for a chunk of memory. Variables can be defined to hold primitive values (which are not real objects in Java) or to hold object references. The object references that they hold can be user-defined classes or Java-defined classes.

Primitive Data Types

A variable declaration consists of a type and a name. Consider the following example:

Код:
  	double balanceDue;
This statement declares a variable called balanceDue, whose type is double. double is one of the eight primitive data types that are provided in the Java language. These types are called primitive because they are not objects and they are built into the Java language.

Unlike similar types in other languages, such as C and C++, the size and characteristics of each primitive data type are defined by the Java language and are consistent across all platforms.


Classes, Interfaces, and Arrays

Classes, interfaces, and arrays are user-defined types with specific characteristics. After they are defined, you can declare variables of the new type just as you declare primitive variables.



Instructor Note

Primitive types are passed by value, unlike objects. Students who are programmers already will know the concept of call-by-value versus call-by-reference.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:38.
Ответить с цитированием
  #5  
Старый 14.01.2010, 01:20
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию Primitive Data Types



Primitive Data Types

Integer

Java provides four different integer types to accommodate different size numbers. All the numeric types are signed, which means that they can hold positive or negative numbers.

The integer types have the following ranges:
  • byte range is 128 to +127. Number of bits = 8.
  • short range is 32,768 to +32,767. Number of bits = 16.
  • int range is 2,147,483,648 to +2,147,483,647; int is the most common integer type. Number of bits = 32.
  • long range is 9,223,372,036,854,775,808 to +9,223,372,036,854,775,807. Number of bits = 64.

Floating Point

The floating-point types hold numbers with a fractional part and conform to the IEEE 754 standard. There are two types: float and double. double is so called because it provides double the precision of float. float uses 32 bits to store data, whereas double uses 64 bits.

Character

The char type is used for individual characters, as opposed to a string of characters, which is implemented as a String object. Java supports Unicode, an international standard for representing a character in any written language in the world in a single 16-bit value. The first 256 characters coincide with the ISO Latin 1 character set, part of which is ASCII.

Boolean

The boolean type can hold either true or false.
If a value is not specified, a default one is used. The values in red in the slide are the defaults used. The default char value is null, represented as ?\u0000?, and the default value for boolean is false.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:41.
Ответить с цитированием
  #6  
Старый 14.01.2010, 01:20
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию What Is a Variable?



What Is a Variable?

A variable is a symbolic name for a chunk of memory in which a value can be stored. Because Java is a strongly typed language, all variables must be declared before they can be used.

Variables also have a scope that determines where you can use the variable. Scope also determines the life span of the variable. When a variable is defined within a method, the variable is available only within the execution of the method. When the method ends, the variable is released and is no longer accessible. When defining a variable with a local scope use braces.

Variables can also be explicitly initialized; that is, given a default value.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:43.
Ответить с цитированием
  #7  
Старый 14.01.2010, 01:20
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию Declaring Variables



Declaring Variables

As mentioned earlier, you must declare all variables before using them. The declaration consists of the type, followed by the variable name. Do not forget to terminate the statement with a semicolon. You can declare a variable anywhere within a block, although it is often preferable to declare it at the start.

You can declare several variables in one statement. All the variables that are declared in one statement must be of the same type, such as int, char, float, and so on. The syntax is as follows:

Код:
int itemsRented, numOfDays, itemId;
Initializing Variables

You can declare and initialize a variable in the same statement by using the assignment operator (=). Even though they are in the same statement, each variable is initialized independently. Each variable needs its own assignment and value.

Код:
int itemsRented = 0, numOfDays, itemId = 0;
In this case, itemsRented and itemId are initialized, whereas numOfDays is not. The compiler accepts this statement as valid.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:45.
Ответить с цитированием
  #8  
Старый 14.01.2010, 01:20
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию Local Variables



What Is a Local Variable?

A local variable is one that is defined inside a method and can therefore be accessed only inside that method. In contrast, a variable that is defined outside a method can be accessed by any method in that class. Consider the following example:

  class Rental {
private int memberId; // Use in any method in the class
public void addItem() {
float itemCost = 3.50F; // Accessible only in addItem()
int numOfDays = 3; // Accessible only in addItem()
}
}


Local Variables Must Be Assigned a Value Before They Can Be Used

A local variable that is declared inside a method must be given a value before it can be used in an expression. If you use a local variable that has not been assigned a value, then the compiler issues an error.

Local variables are also known as method variables or even method local variables. In this course, they are referred to as local variables.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:47.
Ответить с цитированием
  #9  
Старый 14.01.2010, 01:21
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию Defining Variable Names



Rules for Legal Variable Names

A variable name must start with a letter of the alphabet, an underscore, or a dollar sign, although most Java programmers avoid the use of underscores and dollar signs. Subsequent characters can include the digits 0 through 9. Note that the Java language is case sensitive, and so lowercase letters are different from uppercase letters.

There is a 64 K restriction on the length of variable names, and so it is recommended that you choose meaningful names that combine several words. By convention, the first word must be set in lowercase, and subsequent words must start with uppercase letters, such as customerFirstName.

Examples of Illegal Variable Names

The variables in the box on the right in the slide are illegal for the following reasons:
  • item#Cost is illegal because # is not allowed.
  • item-cost is illegal because (minus sign, not underscore) is not allowed.
  • item*Cost is illegal because * is an operator.
  • abstract is illegal because abstract is a keyword.
  • 2itemCost is illegal because it starts with a digit.

Instructor Note

Variable names starting with underscore are usually reserved for private variable names.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:49.
Ответить с цитированием
  #10  
Старый 14.01.2010, 01:21
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,384
По умолчанию What Are Numeric Literals?



What Is a Literal?

Variables hold values, whereas literals are the values themselves.

Код:
float itemCost = 4.95F;
The variable is itemCost, and 4.95 is the literal. Literals can be used anywhere in a Java program, just like a variable. The difference is that literals cannot be stored or held without the use of variables.

Integer Literals

By default, integer literals are 32-bit signed numbers. Integer literals can be specified in decimal, octal, or hexadecimal. When assigning values to a variable, do not use commas to separate thousands. To specify a literal in decimal form, simply use a number (12317.98). Literals with a leading zero are in octal form. Octal numbers are in base 8 and can contain the digits 0 through 7. To specify a hexadecimal value, use a leading 0x or 0X. The valid characters are 0 through 9 and A through F (which can be set in uppercase or lowercase).

A long integer is a 64-bit type. It can hold a larger number than the 32-bit version (int). Remember that the 32-bit version can hold up to 2,147,483,647. If you need to store or use a number larger than that, then you must use a long integer. You can force any integer to be treated as long by appending an uppercase or lowercase L.

Floating-Point Literals

Floating-point literals can be specified in standard format, such as 123.4, or in scientific notation, such as 1.234e2. By default, floating-point literals are taken as double precision. You can obtain single precision by appending an uppercase or lowercase F.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 10.03.2010 в 15:53.
Ответить с цитированием
Ответ
Опции темы
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.

Быстрый переход


Текущее время: 17:38. Часовой пояс GMT +3.


Powered by vBulletin®