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:12
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию 03 Basic Java Syntax and Coding Conventions

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



Lesson Aim

This lesson introduces the basic constructs of the Java language. You learn conventions, standards (that is, capitalization, spacing, and so on), compiling, and running applications. You become familiar with the basic language constructs so that you can recognize and manipulate them with or without using Oracle JDeveloper. The lesson explores JavaBeans as an example of good coding practices.

Overview

Java Components

The Java environment is made up of a run-time engine, documentation tools, debugging utilities, and predefined classes and methods that are designed to decrease development time.

Conventions

When programming in Java, you must use established naming, capitalization, indenting, and commenting conventions.

Classes, Objects, and Methods

In Java, almost everything is an object. Objects are created from blueprints called classes. The objects contain attributes (data) that can be accessed by functions that are contained within the object. Functions that act on the data are called methods.

Using Javadoc

Javadoc is a facility that is provided within J2SE and produces HTML documentation from your program. It reads the source code and parses specially formatted and positioned comments into documentation.

Compiling and Running Java

Java is an interpretive language, which means that the code is interpreted to machine code only at run time. This is what makes the write once, run anywhere (WORA) concept work. There are several steps in the process of interpreting program source code into a running program. Java code is first compiled into bytecodes by the Java compiler. Bytecodes are interpretable, intermediate representation of the Java program. The resulting bytecodes are interpreted and converted into machine-specific instructions by the Java Virtual Machine (JVM) at run time.

Security Concerns

Using the jad.exe, you can make the code so confused or opaque as to be difficult to perceive or understand. Obfuscation of your code can make field debugging more difficult. For example, stack traces are often very useful in isolating bugs. After compression or obfuscation by one of these tools, however, the stack trace may no longer contain the original method names. In general, refrain from using obfuscation, unless you really want to make it difficult to modify your code.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 11:00.
Ответить с цитированием
  #3  
Старый 14.01.2010, 01:13
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Examining Toolkit Components



Examining Toolkit Components

Sun J2SE Components

- The Java compiler is javac; it compiles Java source code into Java bytecodes.
- The Java bytecode interpreter is the engine that runs Java applications.
- The program that generates documentation in HTML from Java source code comments is javadoc.

Other J2SE Tools

- jdb : Used as a Java class debugger and it is similar to the dbx or gdb debuggers on UNIX
- jar : Used to create Java Archive (JAR) files, which are zipped Java programs
- javah : Used to generate C files for native methods
- javakey : Provides support for generating certification keys for trusted Java code
- javap : Used to disassemble Java bytecodes into human-readable format
- native2ascii : Used to convert Java source code to Latin 1 characters
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 11:04.
Ответить с цитированием
  #4  
Старый 14.01.2010, 01:14
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Exploring Packages in J2SE/J2EE



Java Packages

The Java language includes a series of classes that are organized into packages, depending on functional groups. For example, there is a set of classes that helps create and use network connections; these classes are contained in the java.net package. The basic package for the Java language is named classes.zip in 1.1.x and is renamed rt.jar since 1.2.x.

Standard Java Packages

These packages contain the classes that form the foundation for all Java applications.

Built-in Classes That Are Distributed with Java Language:

java.lang: Basic language functions
javax.swing: Parent package to all Swing-related packages
java.util: Facility supporting interfacing, implementing, sorting, and searching on collections
java.awt: Utility to managing layout, handling events, and rendering graphics for AWT
java.io: General interface for all I/O operations
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 11:06.
Ответить с цитированием
  #5  
Старый 14.01.2010, 01:14
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Documenting Using the J2SE



Documentation

There are two types of documentation methods in Java that you can specify in your source code. One is for the internal documentation, and the other is for external documentation.

Comments

Implementation comments are included in the source code. They are useful for programmers who are examining the code. When writing implementation comments, you must explain the code and any special processes that may need detailed explanations. Use:

Код:
-	// to start comments up to the end of the line
-	/* to start comments across multiple lines, and end with */
Documentation comments are created using javadoc. Javadoc is a utility that is provided with J2SE and that creates an HTML document from the documentation comments in Java source code. You can use the javadoc utility to document classes and methods, so that they can be better understood when used by other programmers. Use:

Код:
-	/** to start documentation comments across multiple lines, and end with */
Documentation Generator

Javadoc is a documentation generator that is part of J2SE.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 11:09.
Ответить с цитированием
  #6  
Старый 14.01.2010, 01:14
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Contents of a Java Source



RentalItem.java



package practice16; // collection of classes of similar functionality
import java.util.*; // import for Date class
public class RentalItem {
private InventoryItem inventoryItem;
private String dueDate;
private Date dateReturned;
public RentalItem(int aInventoryItemId) {
try {
inventoryItem = DataMan.fetchInventoryItemById(aInventoryItemId);
}
catch (ItemNotFound e2) {
System.out.println("Invalid Item ID");
}
dueDate = calcDueDate();
} // end constructor

__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 11:12.
Ответить с цитированием
  #7  
Старый 14.01.2010, 01:14
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Establishing Naming Conventions



Naming Conventions

File Names

Java source code is stored in files with the .java extension. Use the name of the class held within the file as the file name. Remember that Java is case sensitive, and the names must match exactly, including case. Compiled Java code, or bytecodes, is stored in files with the .class extension.

The name of the Java source file must be the name of the public class in the file; otherwise, the code will not compile. You may have source code for more than one class in the file, but only one can be public, and the file name must be the same name as the public class.

Class Names

Use descriptive nouns or noun phrases for class names. Capitalize the first letter of each word in the class name, including the first word (for example, MyFirstClassName).

Method Names

Use verbs or verb clauses for method names. Make the first letter of the method name lowercase with the first letter of each internal word capitalized (for example, getSomeInformation() ).

Packages

The Java documentation states that package names must nearly always be in lowercase, and resemble a reverse notation of a Domain name. For example, when Oracle Corporation develops class libraries, package names begin with oracle. followed by a descriptive name. The naming convention ensures that a package name is unique to avoid clashing when using APIs from multiple vendors in the same application.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 11:17.
Ответить с цитированием
  #8  
Старый 14.01.2010, 01:14
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию More About Naming Conventions



Naming Conventions (continued)

Variables

Use short, meaningful names for variables. Use mixed-case letters with the first letter lowercase and begin all internal words with uppercase letters (for example, int squareFootage). Choose names that indicate the intended use of the variable. Avoid using single-character variable names except for temporary variables. Common names for temporary variables are c, d, and e for character fields and i, j, k, m, and n for integers.

Код:
String customerName;	  	// string variable
int customerCreditLimit;	// integer variable
Constants

Declare constants with descriptive names in all uppercase. Separate internal words with underscores (for example, int MIN_WIDTH).

Uppercase and Lowercase

Java is case sensitive. You must adopt and follow a strict capitalization scheme. The scheme that is presented above is a generally accepted practice.

Numerics and Special Characters

Numbers, underscores, and dollar signs may be used for names in addition to uppercase and lowercase letters. The only syntactic restriction is that identifiers must not begin with a number. This rule prevents them from being confused with numeric literals. Underscores are not generally used except for private and local variables.
__________________
Чат форума (требуется аккаунт на github или twitter)

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



Class Definition

A class is an encapsulated collection of data and methods to operate on the data. A class definition, data and methods, serves as a blueprint that is used in the creation of new objects of that class.

A class definition typically consists of:


Access modifier: Specifies the availability of the class from other classes
Class keyword: Indicates to Java that the following code block defines a class
Instance fields: Contain variables and constants that are used by objects of the class
Constructors: Are methods having the same name as the class, which are used to control the initial state of any class object that is created
Instance methods: Define the functions that can act upon data in this class
Class fields: Contain variables and constants that belong to the class and are shared by all objects of that class
Class methods: Are methods that are used to control the values of class fields

The order of the fields, constructors, and methods does not matter in Java. Ordering the parts of a Java program consistently will, however, make your code easier to use, debug, and share. The order listed in the slide is generally accepted.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 11:24.
Ответить с цитированием
  #10  
Старый 14.01.2010, 01:15
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Rental Class: Example



Rental Class: Example

This slide shows the syntax of a class definition. Every Java program needs at least one class definition, even if the class contains only a static main() method.

The First Line

The class definition usually starts with the public access modifier. If you omit the public modifier, then the class is visible only to other classes within the same package. The access modifier is followed by the class keyword, followed by the class body enclosed in braces.

Instance Variables

The class body contains declarations of instance variables and instance methods. Instance variables constitute the state of an object. Instance variables are usually declared private; if no access level is specified, then they can be accessed by any class in the same package. The access modifier is followed by the class keyword, followed by the class name then the class body enclosed in braces.

Instance Methods

Instance methods define the operations that can be performed on objects of this class type. Each instance method has a name, an optional list of arguments, and a return type. If no access level is specified, then instance methods can be accessed by any class in the same package.

Class Variables and Class Methods

Class fields and class methods are defined by using the static keyword.
__________________
Чат форума (требуется аккаунт на github или twitter)

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

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

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

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


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


Powered by vBulletin®