Oracle DBA Forum  

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

Ответ
 
Опции темы Опции просмотра
  #21  
Старый 14.01.2010, 01:17
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Compiling and Running a Java Application



Java Development Kit (JDK) Tools

J2SE includes javac.exe and java.exe, two executables for compiling and executing a Java program.

Compiling Java Code

Run javac.exe from the command prompt to compile .java files into .class files. For example, to compile SayHello.java into a bytecodes file named SayHello.class, enter the following at the command prompt:

Код:
javac SayHello.java
Running a Java Application from the Command Line

The java.exe executable loads the class, verifies the bytecodes, interprets it into machine language, and executes the code. Start the interpreter by entering the following command at the command prompt:

Код:
java SayHello
This starts JVM, which loads SayHello.class and tries to call its main() method. JVM expects the SayHello.class to have a main() method, where the program execution will start. If SayHello.class calls methods in other classes, then JVM loads these other classes only when they are required.
__________________
Чат форума (требуется аккаунт на github или twitter)

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



Setting the CLASSPATH

If the CLASSPATH variable is not set, then a default is used. The default includes the absolute path to the jdk1.4.2_03\bin, \lib\, and \classes\ directories, which house the J2SE packages (contained in the rt.jar file). You can create a /classes/ directory, add your class files, and CLASSPATH will find them.

CLASSPATH examines individual class files, or those stored in .zip or .jar files. Set the CLASSPATH variable by using the commands: setenv in UNIX (in a C-Shell), and set in NT. Separate directories with a semicolon ; (for example, c:\myClasses;d:\myOtherClasses). Set CLASSPATH to include the directory containing the .class files.

The interpreter looks for classes in the directory sequence as they are found in the CLASSPATH variable. If the interpreter cannot find the named class in the first directory, then it searches the second and all the others in the list.

If you want the CLASSPATH to point to class files that belong to a package, then you must specify a path name that includes the path to the directory one level above the directory that has the name of your package.

You can override the CLASSPATH setting in the javac and java commands, by using the classpath option.
__________________
Чат форума (требуется аккаунт на github или twitter)

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

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

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

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

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



Practice 3: Overview

Note: If you close a DOS window or change the location of the .class files, then you must modify the CLASSPATH variable.

The practices in lessons 3, 4, and 5 are written to help you better understand the syntax and structure of the Java language. Their sole purpose is to instruct and is not intended to reflect any set of application development best practices.

The purpose of the practices from lesson 6 to the end of the course, is different. Starting in lesson 6, you use JDeveloper to build an application employing techniques you will use during real-world development. The practices continue to support the technical material presented in the lesson, while incorporating some best practices that you will use while developing a Java application.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 12:48.
Ответить с цитированием
  #26  
Старый 04.03.2010, 12:51
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Practice 3-1: Introducing the Java and Oracle Platforms

Practice 3-1: Introducing the Java and Oracle Platforms

Goal

The goal of this practice is to use the Java Development Kit and examine the development environment. You write, compile, and run a simple Java application.

Note: If you close a DOS window or change the location of the .class files, then you must set the CLASSPATH variable again.

The practices in lessons 3, 4, and 5 are written to help you better understand the syntax and structure of the Java language. Their sole purpose is to instruct and is not intended to reflect any set of application development best practices.


Edit and Run a Simple Java Application

1. Open a DOS window and navigate to the E:\labs\temp directory and create a file called HelloWorld.java by using Notepad with the following commands:

E:
cd \labs\temp
notepad HelloWorld.java


2. In Notepad, enter the following code, placing your name in the comments (after the
double slashes). Also, make sure that the case of the code text after the
comments is preserved, because Java is case sensitive:

// File:   HelloWorld.java
// Author: <Enter Your Name>
public class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}


3. Save the file to the E:\labs\temp directory, using the File > Save menu option, but keep Notepad running, in case compilation errors occur requiring you to edit the source to make corrections.
4. Compile the HelloWorld.java file (file name capitalization is important)
a. In the DOS window, ensure that the current directory is E:\labs\temp.
b. Check whether the Java source file is saved to disk.
(Hint: Type the command dir Hello*. )
c. Compile the file by using the command: javac HelloWorld.java
d. Name the file that is created if you successfully compiled the code.
(Hint: Type the command dir Hello*. )


5. Run the HelloWorld application (again capitalization is important).
a. Run the file by using the command: java HelloWorld
b. What was displayed in the DOS window?

6. Modify the CLASSPATH session variable to use the directory where the .class file is stored. In the DOS window, use the set CLASSPATH=E:\labs\temp command to set the variable. The variable will be set for the duration of the DOS session. If you open another DOS window, you must set the CLASSPATH variable, again.

7. Again, run the HelloWorld application (capitalization is important).
a. Run the file by using the command: java HelloWorld
b. What was displayed in the DOS window?

8. Close Notepad, but do not exit the DOS window, because you continue to work with this environment for some time.
__________________
Чат форума (требуется аккаунт на github или twitter)
Ответить с цитированием
  #27  
Старый 04.03.2010, 12:57
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Practice 3-2: Basic Java Syntax and Coding Conventions

Practice 3-2: Basic Java Syntax and Coding Conventions

Goal

The goal of this practice is to create, examine, and understand Java code. You create a class representing a command-line application for the Order Entry system that contains the application entry point in the form of a main() method.

You use the UML model from the lesson titled Defining Object-Oriented Principles as a guide to creating additional class files for your application. You run some simple Java applications, fixing any errors that occur.

Creating Order Entry Class Files (Examining the Customer Class)

Using the UML model from the lesson titled Defining Object-Oriented Principles, create class files to be used in the application.
1. Copy the Customer.java file from the e:\labs directory to your E:\labs\OrderEntry\src\oe directory.

2. In the DOS window, change your current working directory to:
E:\labs\OrderEntry\src\oe

3. Using Notepad, review the Customer class and answer these questions:
a. Name all the instance variables in Customer.
b. How many instance methods are there in Customer?
c. What is the return type of the method that sets the customers name?
d. What is the access modifier for the class?

4. Close the file, and at the DOS prompt compile the Customer.java file by using the following command as a guide:
javac -d E:\labs\OrderEntry\classes Customer.java
Where is the compiled .class file created?
(Hint: Type cd ..\..\classes\oe, and then type dir.)

Incorporate the Order.java into Your Application Files

5. Add the Order.java file to your application structure, review the code and compile it.
a. In Notepad, open the \labs\Order.java file and save it to the directory for your OE package source code (E:\labs\OrderEntry\src\oe).
b. The attributes are different from those in the UML model. The customer and item information will be incorporated later.
c. Notice two additional attributes (getters and setters) have been added.
shipmode (String): Used to calculate shipping costs
status (String): Used to determine the orders place in the order fulfillment process
d. Ensure that you are in the E:\labs\OrderEntry\src\oe directory. Use the following command to compile the Order.java file which will place the .class file in the directory with the compiled version of the Customer class:
javac d E:\labs\OrderEntry\classes Order.java

6. Create a file called OrderEntry.java containing the main method, as shown below. Place the source file in the same source directory as all the other java files (E:\labs\OrderEntry\src\oe). This file is a skeleton that will be used for launching the course application.

package oe;
public class OrderEntry {
public static void main(String[] args)
{
System.out.println("Order Entry Application");
}
}


7. Save and compile OrderEntry.java with the following command line:
javac -d E:\labs\OrderEntry\classes OrderEntry.java

8. Run the OrderEntry application.
a. Open a DOS window and use the cd command to change the directory to: E:\labs\OrderEntry\classes
b. Run the file by using the command: java oe.OrderEntry
__________________
Чат форума (требуется аккаунт на github или twitter)

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

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

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

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


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


Powered by vBulletin®