Showing posts with label Languages. Show all posts
Showing posts with label Languages. Show all posts

Friday, June 15, 2012

J2EE Tutorial-15(Running the Web Client)

To run the Web client, point your browser at the following URL. Replace <host> with the name of the host running the J2EE server. If your browser is running on the same host as the J2EE server, you may replace <host>with localhost.

http://<host>:8000/converter


You should see the screen shown in Figure 2-2 after entering 100 in the input field and clicking Submit.



Figure 2-2 Converter Web Client

J2EE Tutorial-10(Creating the J2EE Application Client)

A J2EE application client is a program written in the Java programming language. At runtime, the client program executes in a different virtual machine than the J2EE server.

The J2EE application client in this example requires two different JAR files. The first JAR file is for the J2EE component of the client. This JAR file contains the client's deployment descriptor and its class files. When you run the New Application Client wizard, the deploytool utility automatically creates the JAR file and stores it in the application's EAR file. Defined by the J2EE Specification, the JAR file is portable across all compliant J2EE servers.

The second JAR file contains stub classes that are required by the client program at runtime. These stub classes enable the client to access the enterprise beans that are running in the J2EE server. Because this second JAR file is not covered by the J2EE Specification, it is implementation specific, intended only for the J2EE SDK.

The J2EE application client source code is in j2eetutorial/examples/src/ejb/converter/ConverterClient.java. You already compiled this code along with the enterprise bean code in the section Compiling the Source Files.

Coding the J2EE Application Client


The ConverterClient.java source code illustrates the basic tasks performed by the client of an enterprise bean:

  • Locating the home interface

  • Creating an enterprise bean instance

  • Invoking a business method


Locating the Home Interface


The ConverterHome interface defines life-cycle methods such as create. Before the ConverterClient can invoke the create method, it must locate and instantiate an object whose type is ConverterHome. This is a four-step process.

  1. Create an initial naming context.

        Context initial = new InitialContext();


    The Context interface is part of the Java Naming and Directory Interface (JNDI). A naming context is a set of name-to-object bindings. A name that is bound within a context is the JNDI name of the object.
    An InitialContext object, which implements the Context interface, provides the starting point for the resolution of names. All naming operations are relative to a context.

  2. Obtain the environment naming context of the application client.

       Context myEnv = (Context)initial.lookup("java:comp/env");


    The java:comp/env name is bound to the environment naming context of the ConverterClient component.

  3. Retrieve the object bound to the name ejb/SimpleConverter.

       Object objref = myEnv.lookup("ejb/SimpleConverter");


    The ejb/SimpleConverter name is bound to an enterprise bean reference, a logical name for the home of an enterprise bean. In this case, the ejb/SimpleConverter name refers to the ConverterHomeobject. The names of enterprise beans should reside in the java:com/env/ejb subcontext.

  4. Narrow the reference to a ConverterHome object.

       ConverterHome home =
    (ConverterHome) PortableRemoteObject.narrow(objref,
    ConverterHome.class);




Creating an Enterprise Bean Instance


To create the bean instance, the client invokes the create method on the ConverterHome object. The create method returns an object whose type is Converter. The remote Converter interface defines the business methods of the bean that the client may call. When the client invokes the create method, the EJB container instantiates the bean and then invokes the ConverterBean.ejbCreate method. The client invokes the createmethod as follows:

Converter currencyConverter = home.create();


Invoking a Business Method


Calling a business method is easy--you simply invoke the method on the Converter object. The EJB container will invoke the corresponding method on the ConverterEJB instance that is running on the server. The client invokes the dollarToYen business method in the following lines of code.

BigDecimal param = new BigDecimal ("100.00");
BigDecimal amount = currencyConverter.dollarToYen(param);


ConverterClient Source Code


The full source code for the ConverterClient program follows.

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.math.BigDecimal;

public class ConverterClient {

public static void main(String[] args) {

try {
Context initial = new InitialContext();
Object objref = initial.lookup
("java:comp/env/ejb/SimpleConverter");

ConverterHome home =
(ConverterHome)PortableRemoteObject.narrow(objref,
ConverterHome.class);

Converter currencyConverter = home.create();

BigDecimal param = new BigDecimal ("100.00");
BigDecimal amount =
currencyConverter.dollarToYen(param);
System.out.println(amount);
amount = currencyConverter.yenToEuro(param);
System.out.println(amount);

System.exit(0); } catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}


Compiling the Application Client


The application client files are compiled at the same time as the enterprise bean files, as described in Compiling the Source Files.

Packaging the J2EE Application Client


To package an application client component, you run the New Application Client wizard of the deploytool. During this process the wizard performs the following tasks.

  • Creates the application client's deployment descriptor

  • Puts the deployment descriptor and client files into a JAR file

  • Adds the JAR file to the application's ConverterApp.ear file


After the packaging process you can view the deployment descriptor by selecting ToolsDescriptor Viewer.

To start the New Application Client wizard, select FileNewApplication Client. The wizard displays the following dialog boxes.

  1. Introduction dialog box

    1. Read the explanatory text for an overview of the wizard's features.

    2. Click Next.



  2. JAR File Contents dialog box

    1. In the combo box, select ConverterApp.

    2. Click Edit.

    3. In the tree under Available Files, locate the j2eetutorial/examples/build/ejb/converter directory.

    4. Select the ConverterClient.class file and click Add.

    5. Click OK.

    6. Click Next.



  3. General dialog box

    1. In the Main Class combo box, select ConverterClient.

    2. Verify that the entry in the Display Name field is ConverterClient.

    3. In the Callback Handler Class combo box, select container-managed authentication.

    4. Click Next.

    5. Click Finish.




Specifying the Application Client's Enterprise Bean Reference


When it invokes the lookup method, the ConverterClient refers to the home of an enterprise bean:

Object objref = myEnv.lookup("ejb/SimpleConverter");


You specify this reference as follows.

  1. In the tree, select ConverterClient.

  2. Select the EJB Refs tab.

  3. Click Add.

  4. In the Coded Name column, enter ejb/SimpleConverter.

  5. In the Type column, select Session.

  6. In the Interfaces column, select Remote.

  7. In the Home Interface column, enter ConverterHome.

  8. In the Local/Remote Interface column, enter Converter.

Monday, June 11, 2012

JumpCut


Jumpcut is an application that provides “clipboard buffering” — that is, access to text that you’ve cut or copied, even if you’ve subsequently cut or copied something else. The goal of Jumpcut’s interface is to provide quick, natural, intuitive access to your clipboard’s history. The application is available as a Universal Binary that requires OS X 10.3.9 or later. Users running earlier versions of OS X should try Jumpcut 0.54, which should work with OS X 10.1 and later. Source code is also available. Jumpcut is open sourced under the MIT License.

Screenshot

Top 10 Internet tips and tricks

You don't need the http:// portion of a web page

When typing an Internet address you do not need to type http:// or even www. in the address. For example, if you wanted to visit Computer Hope you could just type computerhope.com and press enter. To make things even quicker, if you're visiting a .com address you can type computerhope and then press Ctrl + Enter to type out the full http://www.computerhope.com address.

Quickly move between the fields of a web page

If you're filling out an online form, e-mail, or other text field you can quickly move between each of the fields by pressing the Tab key or Shift + Tab to move back a field. For example, if you're filling out your name and the next field is your e-mail address you can press the Tab key to switch to the e-mail field.

Tip: This tip also applies to the buttons, if you press tab and the web developer has designed correctly the button should be selected and will allow you to press the space bar or enter to push the button.

Tip: If you have a drop-down box that lists every country or every state you can click that box and then press the letter of the state or country you're looking for. For example, is a drop-down box of States in the United States you could press u on the keyboard to quickly scroll to Utah.

Use Internet search engines to their full potential

Make sure to get the most out of every search result. If you're not finding what you want try surrounding the text in quotes. For example, if you were searching for 'computer help' this actually searches for pages that contain both computer and help and not necessarily pages that have computer and help next to each other. If you search for "computer help" with the quotes around the search query this will only return pages that actually have computer and help next to each other.

Tip: Many new computer users also don't realize that in every search box you can press enter instead of having to move the mouse button over to the Search button.

Protect yourself and avoid bad web sites

Know your Internet browser shortcuts

There are dozens of different shortcut keys that can be used with Internet browsers. Below are a few of our top suggested Internet browser shortcuts.

- Pressing Alt + D in any major Internet browser will move the cursor into the address bar. This is a great way to quickly enter an Internet address without having to click the mouse cursor in the address bar.
- Hold down the Ctrl key and press the + or - to increase and decrease the size of text.
- Press the backspace key or hold down the Alt key + left arrow to go back a page.
- Press F5 to refresh or reload a web page.
- Press F11 to make the Internet browser screen full screen.
- Press Ctrl + B to open your Internet bookmarks.
- Press Ctrl + F to open the find box in the browser to search for text within the web page you're looking at.

Take advantage of tabbed browsing

Take full advantage of tabbed browsing in all Internet browsers today. While reading any web page if you come across a link you may be interested in open that link in a new tab so it can be viewed later. A new tab can be opened by holding down the Ctrl key and clicking the link or if you have a mouse with a wheel click the link with the middle mouse button.

Try alternative browsers

Most computer users use the default browser that comes included with the computer, with Microsoft Windows this is Internet Explorer. There are several great alternative browsers that are all free to download and use and may have features your current browser does not include. Below are a few of our favorites, try one or try them all.

Install plugins and add-ons

Each of the above alternative browsers also have a large community of volunteers who develop add-ons and plugins that can be added into the browser. Each of these browsers have hundreds of thousands of these add-ons that can do such things as giving you live weather in your browser window, changing its color, and adding additional functionality.

Make sure your browser and its plugins are up-to-date

Each Internet browser can have several additional plugins that give it additional functionality. For example, Adobe Flash is a great way to bring movies and other animated content to the Internet. Keeping these plugins up-to-date is vital for your computer stability and also security. Using the below tool you can quickly verify if your plugins are up-to-date and get links to where to download the latest updates.

Use online services

There are hundreds of free online services that can help make using your computer easier, more productive, and more enjoyable. See our top 10 online services for a listing of our favorites.

Wednesday, May 30, 2012

J2EE Tutorial-9(Creating the Enterprise Bean)

An enterprise bean is a server-side component that contains the business logic of an application. At runtime, the application clients execute the business logic by invoking the enterprise bean's methods. The enterprise bean in our example is a stateless session bean called ConverterEJB. The source code for ConverterEJB is in thej2eetutorial/examples/src/ejb/converter directory.

Coding the Enterprise Bean


The enterprise bean in this example requires the following code:

  • Remote interface

  • Home interface

  • Enterprise bean class


Coding the Remote Interface


A remote interface defines the business methods that a client may call. The business methods are implemented in the enterprise bean code. The source code for the Converter remote interface follows.

import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;

public interface Converter extends EJBObject {
public BigDecimal dollarToYen(BigDecimal dollars)
throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen)
throws RemoteException;
}


Coding the Home Interface


home interface defines the methods that allow a client to create, find, or remove an enterprise bean. The ConverterHome interface contains a single create method, which returns an object of the remote interface type. Here is the source code for the ConverterHome interface:

import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface ConverterHome extends EJBHome {
Converter create() throws RemoteException, CreateException;
}


Coding the Enterprise Bean Class


The enterprise bean class for this example is called ConverterBean. This class implements the two business methods, dollarToYen and yenToEuro, that the Converter remote interface defines. The source code for the ConverterBean class follows.

import java.rmi.RemoteException; 
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;

public class ConverterBean implements SessionBean {

BigDecimal yenRate = new BigDecimal("121.6000");
BigDecimal euroRate = new BigDecimal("0.0077");

public BigDecimal dollarToYen(BigDecimal dollars) {
BigDecimal result = dollars.multiply(yenRate);
return result.setScale(2,BigDecimal.ROUND_UP);
} public BigDecimal yenToEuro(BigDecimal yen) {
BigDecimal result = yen.multiply(euroRate);
return result.setScale(2,BigDecimal.ROUND_UP);
} public ConverterBean() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}


Compiling the Source Files


Now you are ready to compile the remote interface (Converter.java), home interface (ConverterHome.java), and the enterprise bean class (ConverterBean.java).

  1. In a terminal window, go to the j2eetutorial/examples directory.

  2. Type the following command:

       ant converter




This command compiles the source files for the enterprise bean and the J2EE application client. It places the resulting class files in thej2eetutorial/examples/build/ejb/converter directory (not the src directory). For more information about ant, see How to Build and Run the Examples.




Note: When compiling the code, the preceding ant task includes the j2ee.jar file in the classpath. This file resides in the lib directory of your J2EE SDK installation. If you plan on using other tools to compile the source code for J2EE components, make sure that the classpath includes the j2ee.jar file.




Packaging the Enterprise Bean


To package an enterprise bean, you run the New Enterprise Bean wizard of the deploytool utility. During this process, the wizard performs the following tasks:

  • Creates the bean's deployment descriptor

  • Packages the deployment descriptor and the bean's classes in an EJB JAR file

  • Inserts the EJB JAR file into the application's ConverterApp.ear file


After the packaging process, you can view the deployment descriptor by selecting ToolsDescriptor Viewer.

To start the New Enterprise Bean wizard, select FileNewEnterprise Bean. The wizard displays the following dialog boxes.

  1. Introduction dialog box

    1. Read the explanatory text for an overview of the wizard's features.

    2. Click Next.



  2. EJB JAR dialog box

    1. Select the Create New JAR File In Application button.

    2. In the combo box, select ConverterApp.

    3. In the JAR Display Name field, enter ConverterJAR.

    4. Click Edit.

    5. In the tree under Available Files, locate the j2eetutorial/examples/build/ejb/converter directory. (If the converter directory is many levels down in the tree, you can simplify the tree view by entering all or part of the converter directory's path name in the Starting Directory field.)

    6. Select the following classes from the Available Files tree and click Add: Converter.classConverterBean.class, and ConverterHome.class. (You may also drag and drop these class files to the Contents text area.)

    7. Click OK.

    8. Click Next.



  3. General dialog box

    1. Under Bean Type, select the Session radio button.

    2. Select the Stateless radio button.

    3. In the Enterprise Bean Class combo box, select ConverterBean.

    4. In the Enterprise Bean Name field, enter ConverterEJB.

    5. In the Remote Home Interface combo box, select ConverterHome.

    6. In the Remote Interface combo box, select Converter.

    7. Click Next.



  4. Transaction Management dialog box

    1. Because you may skip the remaining dialog boxes, click Finish.



J2EE Tutorial-8 (Creating the J2EE Application)

The sample application contains three J2EE components: an enterprise bean, a J2EE application client, and a Web component. Before building these components, you will create a new J2EE application called ConverterApp and will store it in an EAR file named ConverterApp.ear.

  1. In deploytool, select FileNewApplication.

  2. Click Browse.

  3. In the file chooser, navigate to j2eetutorial/examples/src/ejb/converter.

  4. In the File Name field, enter ConverterApp.ear.

  5. Click New Application.

  6. Click OK.

J2EE Tutorial-7 (Setting up Environment)

Before you start developing the example application, you should follow the instructions in this section.

Getting the Example Code


The source code for the components is in j2eetutorial/examples/src/ejb/converter, a directory that is created when you unzip the tutorial bundle. If you are viewing this tutorial online, you need to download the tutorial bundle from

http://java.sun.com/j2ee/download.html#tutorial 


Getting the Build Tool (ant)


To build the example code, you'll need installations of the J2EE SDK and ant, a portable make tool. For more information, see the section How to Build and Run the Examples.

Checking the Environment Variables


The installation instructions for the J2EE SDK and ant explain how to set the required environment variables. Verify that the environment variables have been set to the values noted inTable 2-1.

 























Table 2-1 Required Environment Variables
Environment Variable
Value
JAVA_HOMEThe location of the J2SE SDK installation
J2EE_HOMEThe location of the J2EE SDK installation
ANT_HOMEThe location of the ant installation
PATHShould include the bin directories of the J2EE SDK, J2SE, and ant installations

 

Starting the J2EE Server


To launch the J2EE server, open a terminal window and type this command:

j2ee -verbose


Although not required, the verbose option is useful for debugging.

To stop the server, type the following command:

j2ee -stop


Starting the deploytool


The deploytool utility has two modes: command line and GUI. The instructions in this chapter refer to the GUI version. To start the deploytool GUI, open a terminal window and type this command:

deploytool

Tuesday, May 29, 2012

J2EE Tutorial -1 (overview)

Today, more and more developers want to write distributed transactional applications for the enterprise and leverage the speed, security, and reliability of server-side technology. If you are already working in this area, you know that in today's fast-moving and demanding world of e-commerce and information technology, enterprise applications have to be designed, built, and produced for less money, with greater speed, and with fewer resources than ever before.

To reduce costs and fast-track enterprise application design and development, the Java 2 Platform, Enterprise Edition (J2EE) technology provides a component-based approach to the design, development, assembly, and deployment of enterprise applications. The J2EE platform offers a multitiered distributed application model, the ability to reuse components, integrated Extensible Markup Language (XML)-based data interchange, a unified security model, and flexible transaction control. Not only can you deliver innovative customer solutions to market faster than ever, but your platform-independent J2EE component-based solutions are not tied to the products and application programming interfaces (APIs) of any one vendor. Vendors and customers enjoy the freedom to choose the products and components that best meet their business and technological requirements.

This tutorial takes an examples-based approach to describing the features and functionalities available in J2EE Software Development Kit (SDK) version 1.3. Whether you are a new or an experienced enterprise developer, you should find the examples and accompanying text a valuable and accessible knowledge base for creating your own enterprise solutions.

If you are new to J2EE applications development, this chapter is a good place to start. Here you will learn the J2EE architecture, become acquainted with important terms and concepts, and find out how to approach J2EE application programming, assembly, and deployment.

"Go" Language Tutorial-1

Welcome to a tour of the Go programming language.

The tour is divided into three sections. At the end of each section is a series of exercises for you to complete.

The tour is interactive. Click the Run button now (or type Shift-Enter) to compile and run the program on a remote server. The result is displayed below the code.

These example programs demonstrate different aspects of Go. The programs in the tour are meant to be starting points for your own experimentation.

Edit the program and run it again.

Whenever you're ready to move on, click the Next button or type the PageDown key.

 

Example:

package main

import "fmt"

func main() {
fmt.Println("Hello, 世界")
}

output :
Hello, 世界