Lecture Java programming language: Variables and constants - Ho Dac Hung

Lecture Java Programming Language: Variables and Constants provide knowledge about declaring variables, using variables, primitive data types, abstract data types, java packages, obtaining a value from the user, type casting, formatting numeric ouput, assignment operators, using named constants. | Variables and Constants Ho Dac Hung 1 Declaring Variables A variable is a name for a value stored in memory. Variables are used in programs so that values can be represented with meaningful names. A variable must be declared before it is used. A declaration takes the form 2 Using Variables The value of a variable is changed throught assignment. An assignment statement is formed with the variable name on the left side of an equal sign and the value it is to receive on the right side of the equal sign. An assignment statement can be part of a variable declaration. In addition to being declared the variable is initialized. 3 Primitive Data Types byte short int long float double char boolean 4 Abstract Data Types In addition to primitive data types a variables can be declared using an abstract data type. One kind of abstract data type is the class. A variables declared with a class is called an object. The variable itself actually stores a reference to the area in memory where the object s data and methods are stored. 5 Java Packages Java SE includes numerous packages as part of the JDK. End-users will have the packages as part of the J2SE Runtime Enviroment JRE . Packages follow a certain naming convention. Java packages start with java followed by a dot and than the package name. Companies and other organizations will often name a package with the organization name followed by a dot and then the package name. 6 Java Packages The import statement is used to make the members of a package accessible to an application. To make a single class from a package accessible a statement similar to the following is used import If several classes in a package are to be accessible import statement then the statement that imports the entire package may be used import . 7 Obtaining a Value from the User An application is more flexible when values can be read from an input stream. Input stream is the sequence of characrers received from an input device such

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.