Академический Документы
Профессиональный Документы
Культура Документы
Learning objectives
At the end of the topic you will be able to:
Define the syntax of variables in the Java language. Define the syntax of the main commands in the Java language. Define the syntax of the procedures and functions in the Java language. Id tif the Identify th characteristics h t i ti of f the th web b browsers. b Solve logical problems.
Introduction
Now that we have enough tools to structure real problems in representations that the Java language can understand, we will look more closely to the way Java language instructions are written. Have you ever wondered why there are so many programs to surf the Web? Have you wondered why, when we login in to our e-mail e mail account account, the page adjusts itself to fit in our screen? And the same goes for our PDA or cell phone.
Introduction
Do you know why some websites seem distorted or different when viewed from a Mac computer? In this topic you will find the answer to all of these questions as well as their relation with the Java language.
Introduction to Java
This file is called source file and it is a text file that you
can generate in any text or word processor such as Notepad or Microsoft Word.
Introduction to Java
Some things to consider when generating a source file:
Uppercase / lowercase sensitive The sentences end with a semicolon. Blocks of instructions delimited with curly brackets { } Comments of a line and multiline. The word class is not equal to the word Class. Any statement (sentence) in Java must end with a semicolon (;). The blocks of instructions define the beginning and the end of a module in our source file which is performed independently. Comments are instructions within a program that are not executed and which main task is to allow us to document the steps. o / / Comment of a line o / * multiline comment * /
Definition of variables
A variable is a space in memory where a program can store data and use it later. There are different types of data. We define a data type according to a variable to determine the amount of "space" that will be required in memory to store the data we require.
Definition of variables
1.
Primitive Type: a. byte b. char b c. short d. integer a. long b float b. c. double d. boolean
A. Whole numbers
There are the byte, short, integer and long type. The char type represents a character. B. Character The float and double types represent the C. Decimal numbers d i l numbers. decimal b The boolean type is the logical data and D. Logics its only two values are true or false.
Definition of variables
Data type byte char short integer long float double boolean
Values it can save 125 S 31,425 217483647 92233720368575807 43.2421 6.3 x 10242 true / false
In this expression we can determine that the first operation performed is the sum of data1 and data2, and the result of this operation is divided by data3.
Definition of procedure
Procedures are a set of statements grouped with its own y have a p particular g goal. name and they You can define as many procedures as you want. The use of procedures allows a program to be modular, which means that it is organized by different modules (procedures) that perform certain particular tasks, but when integrated they fulfill the ultimate objective of the application. application
Definition of procedure
You can write procedures in a Java program as follows:
Definition of procedure
Example: Lets suppose that you need to create a procedure that calculates the amount of days in 5 years years. Knowing that a year has 365 days, you just require an arithmetic operation that multiplies the value 365 by 5: static void amount_days(){ years=5; days=365; value1=(years * days) stores the result }
//value1
Logical problems
Logical problems show up in Java programs when we need to make a decision.
For example, why when you press the button in the right side of our cell phone the calendar is y and when y you press displayed the button in the left side it shows the contact list?
Logical problems
This is because your cell phone is making decisions to accomplish certain actions. Said in fewer words words, it could be defined as follows:
If you press the right button, then the "Calendar" application is run.
Logical problems
10
Logical problems
In the following table are shown the logical operators and a brief description..
Logical operators Symbol
Description Returns a true result only when both conditions are true, otherwise returns false. Returns a false result only when both conditions are false, otherwise returns true. Affects only one condition and returns true if this is set to false and vice versa. Returns a true result if one condition is true and the other one is false, otherwise returns false.
&& || ! ^
Logical problems
If: data1=true; data2=false; d t 2 f l The logical expression: data1 AND data2; Returns false because the data2 operator is false. For the expression: data1 OR data2; Returns true because there data1 is true. For the expression: p NOT data1; Returns false because data1 is true For the expression: data1 XOR data2; It is true because one value is true and the other is false.
11
Closing arguments
23
Closing arguments
We must forget those false ideas like the computer does not work or the computer was wrong. Rather, Rather we must pay more attention to warning or error messages generated by the computer and to be more cautious and more patient when trying to identify what is happening when we are confronted with messages of that nature. Now that y you know the structure and syntax y for Java programs we will go into developing them on the computer, run them and detect and solve errors during the development process.
24
12
Bibliography
Fundamentals of the Java Programming Language (SL-110-SE6) http://www.sun.com/training/catalog/courses/SL-110 SE6.xml
25
Credits
Content Author Ing. Javier Castro Ruiz, MATI Academic Coordinator Lic. Nelly Maldonado Gonzlez, MEA Translating Teacher Lic. Nelda Contreras Leal, MA Instructional Designer Lic Dalila de Len Bauelos Lic. Bauelos, MTE Graphic Designer Lic. Miguel ngel Reynosa Castro, MANM
26
13