Showing posts with label software. Show all posts
Showing posts with label software. Show all posts

Tuesday, June 19, 2012

Java Interview questions

1. How could Java classes direct program messages to the system console, but error messages, say to a file?
The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:

Stream st =
new Stream (new
FileOutputStream (“techinterviews_com.txt”));
System.setErr(st);
System.setOut(st);

2. What’s the difference between an interface and an abstract class?
An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

3. Why would you use a synchronized block vs. synchronized method?
Synchronized blocks place locks for shorter periods than synchronized methods.

4. Explain the usage of the keyword transient?
This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

5. How can you force garbage collection?
You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

6. How do you know if an explicit object casting is needed?
If you assign a superclass object to a variable of a subclass’s data type, you need to do explicit casting. For example:

Object a;Customer b; b = (Customer) a;

When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.

7. What’s the difference between the methods sleep() and wait()
The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

8. Can you write a Java class that could be used both as an applet as well as an application?
Yes. Add a main() method to the applet.

9. What’s the difference between constructors and other methods?
Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

10. Can you call one constructor from another if a class has multiple constructors
Yes. Use this() syntax.

11. Explain the usage of Java packages.
This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.

12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?
You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let’s say a class Employee belongs to a package com.xyz.hr; and is located in the file c:/dev/com.xyz.hr.Employee.java. In this case, you’d need to add c:/dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:
c:>java com.xyz.hr.Employee

13. What’s the difference between J2SDK 1.5 and J2SDK 5.0?
There’s no difference, Sun Microsystems just re-branded this version.

14. What would you use to compare two String variables – the operator == or the method equals()?
I’d use the method equals() to compare the values of the Strings and the = = to check if two variables point at the same instance of a String object.

15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?
A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception’s subclasses have to be caught first.

16. Can an inner class declared inside of a method access local variables of this method?
It’s possible if these variables are final.

17. What can go wrong if you replace && with & in the following code:
String a=null;
if (a!=null && a.length()>10)
{…}

A single ampersand here would lead to a NullPointerException.

18. What’s the main difference between a Vector and an ArrayList
Java Vector class is internally synchronized and ArrayList is not.

19. When should the method invokeLater()be used?
This method is used to ensure that Swing components are updated through the event-dispatching thread.

20. How can a subclass call a method or a constructor defined in a superclass?
Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass’s constructor.

21. What’s the difference between a queue and a stack?
Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule.

22. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?
Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.

23. What comes to mind when you hear about a young generation in Java?
Garbage collection.

24. What comes to mind when someone mentions a shallow copy in Java?
Object cloning.

25. If you’re overriding the method equals() of an object, which other method you might also consider?
hashCode()

26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList?
ArrayList

27. How would you make a copy of an entire Java object with its state?
Have this class implement Cloneable interface and call its method clone().

28. How can you minimize the need of garbage collection and make the memory use more effective?
Use object pooling and weak object references.

29. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?
If these classes are threads I’d consider notify() or notifyAll(). For regular classes you can use the Observer interface.

30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?
You do not need to specify any access level, and Java will use a default package access level.

Saturday, June 16, 2012

Top 5 Ways to Access Blocked Websites

This post is a continuation of our recent article “Top 5 Ways to Access Blocked Websites in which we covered the most popular 5 ways using which you can unblock restricted websites at school, work or office. In this part II, we will discuss 5 more rather unconventional methods of unblocking websites, most of which are not so common and thus generally not known to most people. So here they go:

Method 1: Using Google Mobile Search


You can use Google Mobile Search to indirectly gain access to your desired website. Google Mobile Search removes the CSS & javascript elements from the web pages and breaks a large page into several small pages. Though the output will appear as if you are viewing the website on a mobile phone, this method certainly works quite well.

Method 2: Get Web Pages Via Email


Web2Mail is a great free service that sends websites you want to read directly into your inbox. Simply send an email to www@web2mail.com with the URL of the blocked website as the subject title and you will start receiving web pages from the website into your inbox.

Method 3: Using Encrypted VPN Service


The Your Freedom OpenVPM service is a sophisticated application that hides your network address from the end server. You just need to download the client application , install it and subsequently run it on your computer. Your PC will start acting as an anonymous web proxy and you can safely gain access to all blocked websites.

Similarly you can also download and use Tor , which is an advanced proxy server that uses multiple anonymous servers for a single Web request and allows you to access blocked websites while remaining anonymous.

Method 4: Using JAP


JAP or JonDo is a popular client that acts as a local proxy between the browser and the internet, allowing you to browse the blocked websites while remaining anonymous the whole time. As JAP uses a single static address which is shared by many JAP users, the end server won’t get to know your real IP address. All you need to do is to download the JAP client and install it. Then you need tochange your LAN settings in whatever browser you are using (throughTools->Internet Options) and check “Use a Proxy server for your LAN” option (or “Manual Proxy configuration” in Firefox). Enter “127.0.0.1″ in the server column and “4001″ in the port column. Then run the JAP client and check the “On” option under Anonymity tab. Now simply open your browser and browse the blocked websites freely.





Method 5: Using Wayback Machine


Wayback Machine is an internet service that keeps a copy of almost all websites on the internet right from the date they were started. Cached pages of each website are available, using which you can indirectly gain access to the blocked websites. However the only downside is that there is a 6 month time lag before the pages appear in the Wayback Machine.

Let’s see an example. My ISP has blocked IsoHunt, which is a major bit-torrent website. However by entering the URL of IsoHunt on Wayback Machine, I was able to access it without any problems. I then searched “America” on IsoHunt. Here’s the screenshot (Click on the image to enlarge it).



Do you know of any other ways to access blocked websites? Do share them with us.

Also, stay tuned for the next article in this series – “How to Open Facebook at School & Office”.

Start all your programs with a single click using batch file

Everyone has some standard list of programs, which he starts when logs on to his computer. It’s a waste of time to start each program individually; today we are going to learn how to start all your favorite programs with a single click using batch files. Those of you who don’t know what batch files are may check this post to find out what they are.

Batch Programming Basics



I usually use Dreamweaver, Mozilla Firefox, and pidgin immediately after I login to my comp. So let us see how to create a batch file to start the above three programs with a single click.
First open note pad and type the following lines

CD “C:\Program Files\Adobe\Adobe Dreamweaver CS3\”

start Dreamweaver.exe




cd “C:\Program Files\Pidgin\”

start Pidgin.exe

cd “C:\Program Files\Mozilla Firefox\”

start firefox.exe

Here cd switches the control to the directory following it and start command is used to start the program in that directory. You can add any number of programs to this list.
Once you have added all your favorite programs to this list, save it a startup.bat or any other name of your choice and double click on that batch file you created just now to start all your favorite programs.
If you have any problems in creating the batch files feel free to drop in a comment here

How to unlock folders locked by the folder lock software without any password

Now, you don’t have to worry about the password of your locked folder. You can easily access or unlock your folder, without any password, or without knowing password of that locked folder.

Why should we lock a folder?


Just like any person needs security guard for his or her security, or any PC needs password for security, some important folders also need to be locked for security.And if we lock our folder we will have following benefits:-

  • Unknown persons can’t be able to open that holder, and use the files inside it.

  • Only you and the persons who know the password can use the files inside it.


How to lock a folder using folder lock software


Requirements:-


To lock a folder by using folder lock software you need:-

  • A folder which will be locked.

  • A, folder locking software should be installed on your PC, like Folder Access.



You can download Folder Access from below mentioned link.

http://www.topdownloads.net/software/view.php?id=156290

How to lock


When you start the folder access for the first time you will be asked the password to set. This password will be used to gain access to software and for locking and unlocking folders.

To lock a folder after installation, you just right-click on folder and select lock folder.




And to unlock folder, you just right-click on folder and select unlock folder.


While locking and unlocking folder, you will asked for the password. Please enter the password you had set when first time you started Folder Access.

How to unlock the locked folder, without password?


It happens that sometimes you may forget the password of your locked folder. Or you may want to open that folder and use the files and data inside it, but you don’t know the password. You can’t uninstall that software, because in this process also, it will ask for password.

But now you don’t have to worry much about this, because now you can open or unlock that folder without knowing any password. You have to follow simple steps.

Requirements:-


To unlock or open any locked folder you need:-

  • A pen-drive or memory card (with card reader and mobile).

  • A PC in which folder access (or the software by which the folder is locked) isnot installed.

  • You can use a mobile phone instead of PC .


How to unlock


To unlock any folder, you have to follow these simple steps:-

  1. Plug in the pen-drive or memory card (with card reader) into the PC (in which locked folder stored).

  2. Copy the locked folder, and paste it into the pen-drive or memory card.

  3. Unplug the pen-drive or memory card.

  4. Plug in the pen-drive into another PC (in which folder lock software is not installed).
    OR (for memory card) plug-in the memory card into mobile phone.

  5. Open the pen-drive or memory card.

  6. Right click on folder and select Rename.                                                              OR (for memory card) select options of that folder and select Rename.

  7. Change the coding name of the folder.

  8. Unplug pen-drive from PC, OR unplug memory card from mobile.                And plug-in into 1st PC (in which folder lock software is installed).

  9. Open the pen-drive OR memory card and see your locked folder will be unlocked.


Now your folder is successfully unlocked without using any password. You can open it and use the files inside it.

Install Safari on Ubuntu

Ubuntu users lack the number of options available as compared to the PC or Mac users. Main browsers they can use are Firefox, Chromium, Google Chrome & Opera.

In this post I will be writing a tutorial on how you can install Safari on Ubuntu.So, without any further ado we will start.

  • Install Wine


Wine is a known Windows emulator for Linux. It is used to run Windows programs on Linux. We will be installing Wine first in order to install Safari on Linux. To install wine you need to open up the Ubuntu Software center and search for Wine. Or, you can simply go to this website and follow the instructions.The install will take a while. Or, you can install it via the Terminalusing the following apt syntax.
sudo apt-get install wine

After installing Wine you need to install core fonts and the flash (windows version) using winetricks. To do this input the following in the terminal.
winetricks corefonts flash


  • Install 7zip


Installing 7zip is our next step as this will be needed to run Play on Linux. Ignoring this will give you an error related to 7zip.
sudo apt-get install p7zip-full


  • Install Play On Linux


Play on Linux will help us create an environment to run Safari easily. To install Play on Linux you need to download it from this website. Choose the Ubuntu version as we are doing this for Ubuntu.

After installing Play on Linux, open it. A new window will open up which will look like the screenshot below.




play on linux

 

Now click Install. Click Internet and then click Safari. Click Install.

play on linux

Now the package will download some required packages and start installing Safari on Ubuntu. Keep following the wizard and you will have Safari installed on Ubuntu.

play on linux

So, we have successfully installed Safari on Ubuntu.

Safari browser

But lets keep in mind that if you want to experience the real internet browsing experience use the browsers that are built to run on Linux by default and not the browsers that run with Wine.

Friday, June 15, 2012

J2EE Tutorial-17(Common Problems and Their Solutions)

Cannot Start the J2EE Server


Naming and Directory Service Port Conflict


Symptom: When you start the J2EE server with the -verbose option, it displays these lines:

J2EE server listen port: 1050 RuntimeException: Could not initialize server... 


Solution: Another process is using port 1050. If the J2EE server is already running, you can stop it by typing j2ee -stop. If some other program is using the port, then you can change the default port number (1050) by editing the config/orb.properties file of your J2EE SDK installation.

For more information about default port numbers, see the Configuration Guide in the download bundle of the J2EE SDK.

Web Service Port Conflict


Symptom: When you start the J2EE server with the -verbose option, it displays these lines:

LifecycleException: HttpConnector[8000].open:
java.net.BindException: Address in use...


Solution: Another process is using port 8000. You can change the default port number (8000) by editing the config/web.properties file of your J2EE SDK installation.

Incorrect XML Parser


Symptom: When you start the J2EE server with the -verbose option, it displays these lines:

Exception in thread "main"
javax.xml.parsers.FactoryConfigurationError:
org.apache.xerces.jaxp.SAXParserFactoryImpl at ...


Solution: Remove the jre/lib/jaxp.properties file from your J2SE installation.

Compilation Errors


ant Cannot Locate the Build File


Symptom: When you type ant converter, these messages appear:

Buildfile: build.xml does not exist!
Build failed.


Solution: Before running ant, go to the j2eetutorial/examples/src directory. If you want to run ant from your current directory, you must specify the build file on the command line. For example, on Windows you would type this command on a single line:

ant -buildfile C:\j2eetutorial\examples\src\build.xml
converter


The Compiler Cannot Resolve Symbols


Symptom: When you type ant converter, the compiler reports many errors, including these:

cannot resolve symbol
...
BUILD FAILED
...
Compile failed, messages should have been provided


Solution: Make sure that you've set the J2EE_HOME environment variable correctly. See Checking the Environment Variables.

ant 1.4 Will Not Compile the Example after You Run the Client


Symptom: ant 1.4 displays this error:

The filename, directory name, or volume label syntax is 
incorrect.


Solution: Use version 1.3 of ant. The 1.4 version of the ant.bat script and the scripts of the J2EE SDK all use the JAVACMD environment variable. The SDK's runclient.bat script, for example, sets JAVACMD to a value that causes problems for ant.bat.

Deployment Errors


The Incorrect XML Parser Is in Your Classpath


Symptom: The error displayed has the following text:

...
[]java.rmi.RemoteException:Error saving/opening

Deployment Error:Bad mapping of key{0}  class{1},
not found: com.sum.enterprise.deployment.xml.ApplicationNode


Solution: Remove the jaxp.jar file from the jre/lib/ext directory of your J2SE installation. This JAR file contains XML parsing routines that are incompatible with the J2EE server. If you do not have a jaxp.jarfile, then perhaps your classpath refers to the XML routines of a Tomcat installation. In this case, you should remove that reference from your classpath.

The Remote Home Interface Was Specified as a Local Home Interface


Symptom: An error such as the following is displayed:

LocalHomeImpl must be declared abstract. 
It does not define javax.ejb.HomeHandle getHomeHandle()
from interface javax.ejb.EJBHome.


Solution: Remove the enterprise bean from the EAR file (EditDelete) and create a new bean with the New Enterprise Bean wizard. In the General dialog box of the wizard, select values from the Remote Home Interface and Remote Interface combo boxes.

J2EE Application Client Runtime Errors


The Client Throws a NoClassDefFoundError


Symptom: The client reports this exception:

java.lang.NoClassDefFoundError:converter.ConverterHome


Solution: This error occurs if the client cannot find the classes in the ConverterAppClient.jar file. Make sure that you've correctly followed the steps outlined in Running the J2EE Application Client.

The Client Cannot Find ConverterApp.ear


Symptom: The client reports this exception:

IOException: ConverterApp.ear does not exist


Solution: Ensure that the ConverterApp.ear file exists and that you've specified it with the -client option:

runclient -client ConverterApp.ear -name ConverterClient


You created the ConverterApp.ear file in the section Creating the J2EE Application. See also the section Running the J2EE Application Client.

The Client Cannot Find the ConverterClient Component


Symptom: The client displays this line:

No application client descriptors defined for: ...


Solution: Verify that you've created the ConverterClient component and that you've specified it for the -name option of the runclient command. You created the ConverterClient component in the sectionPackaging the J2EE Application Client.

The Login Failed


Symptom: After you log in, the client displays this line:

Incorrect login and/or password


Solution: At the login prompts, enter guest as the user name and guest123 as the password.

The J2EE Application Has Not Been Deployed


Symptom: The client reports the following exception:

NameNotFoundException. Root exception is org.omg.CosNaming...


Solution: Deploy the application. For instructions, see Deploying the J2EE Application.

The JNDI Name Is Incorrect


Symptom: The client reports the following exception:

NameNotFoundException. Root exception is org.omg.CosNaming...


Solution: In the JNDI Names tabbed pane of the ConverterApp, make sure that the JNDI names for the ConverterBean and the ejb/SimpleConverter match. Edit the appropriate JNDI Name field and then redeploy the application.

Web Client Runtime Errors


The Web Context in the URL Is Incorrect


Symptom: The browser reports that the page cannot be found (HTTP 404).

Solution: Verify that the Web context (converter) in the URL matches the one you specified in the Component General Properties dialog box (see the section Packaging the Web Client). The case (upper or lower) of the Web context is significant.

The J2EE Application Has Not Been Deployed


Symptom: The browser reports that the page cannot be found (HTTP 404).

Solution: Deploy the application.

The JNDI Name Is Incorrect


Symptom: When you click Submit on the Web page, the browser reports

A Servlet Exception Has Occurred.


Solution: In the JNDI Names tabbed pane of the ConverterApp, make sure that the JNDI names for the ConverterBean and the ConverterWAR match. Edit the appropriate JNDI Name field and then redeploy the application.

Detecting Problems With the Verifier Tool


The verifier tool (verifier) can detect inconsistencies in deployment descriptors and method signatures. These inconsistencies often cause deployment or runtime errors. From deploytool, you can run the GUI version of verifier by selecting ToolsVerifier. You can also run a stand-alone GUI or command-line version of verifier. For more information, see Appendix B.

Comparing Your EAR Files with Ours


For most of the examples, the download bundle of the tutorial includes J2EE application EAR files, which are located in the j2eetutorial/examples/ears directory.

When All Else Fails


If none of these suggestions fixes the problem, you can uninstall the application and clean out the server's repository by running the cleanup script. You'll also need to shut down and restart the server:

j2ee -stop
cleanup
j2ee -verbose

J2EE Tutorial-16(Modifying the J2EE Application)

Since the J2EE SDK is intended for experimentation, it supports iterative development. Whenever you make a change to a J2EE application, you must redeploy the application.

Modifying a Class File


To modify a class file in an enterprise bean, you change the source code, recompile it, and redeploy the application. For example, if you want to change the exchange rate in the dollarToYen business method of theConverterBean class, you would follow these steps.

  1. Edit ConverterBean.java.

  2. Recompile ConverterBean.java by typing ant converter.

  3. In deploytool, select ToolsUpdate Files.

  4. The Update Files dialog box appears. If the modified files are listed at the top of the dialog, click OK and go to step 6. If the files are listed at the bottom, they have not been found. Select one of those files and click Edit Search Paths.

  5. In the Edit Search Paths dialog, specify the directories where the Update Files dialog will search for modified files.

    1. In the Search Root field, enter the fully-qualified name of the directory from which the search will start.

    2. In the Path Directory list, add a row for each directory that you want searched. Unless fully-qualified, these directory names are relative to the Search Root field.

    3. Click OK.



  6. Select ToolsDeploy. Make sure the checkbox labeled Save Object Before Deploying is checked. If you do not want to deploy at this time, select ToolsSave to save the search paths specified in step 5.


As a shortcut, you can select ToolsUpdate And Redeploy. With this shortcut, the Update Files dialog box does not appear unless the files are not found.

To modify the contents of a WAR file you follow the preceding steps. The Update Files operation checks to see if any files have changed, including HTML files and JSP pages. If you change the index.jsp file ofConverterApp, be sure to type ant converter. The converter task copies the index.jsp file from the src to the build directory.

Adding a File


To add a file to the EJB JAR or WAR of the application, perform these steps.

  1. In deploytool, select the JAR or WAR in the tree.

  2. Select the General tab.

  3. Click Edit.

  4. In the tree of the Available Files field, locate the file and click Add.

  5. Click OK.

  6. From the main toolbar, select ToolsUpdate And Redeploy.


Modifying a Deployment Setting


To modify a deployment setting of ConverterApp, you edit the appropriate field in a tabbed pane and redeploy the application. For example, to change the JNDI name of the ConverterBean from ATypo toMyConverter, you would follow these steps.

  1. In deploytool, select ConverterApp in the tree.

  2. Select the JNDI Names tab.

  3. In the JNDI Name field, enter MyConverter.

  4. From the main toolbar, select FileSave.

  5. Select ToolsUpdate And Redeploy.

J2EE Tutorial-14(Running the J2EE Application Client)

To run the J2EE application client, perform the following steps.

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

  2. Verify that this directory contains the ConverterApp.ear and ConverterAppClient.jar files.

  3. Set the APPCPATH environment variable to ConverterAppClient.jar.

  4. Type the following command (on a single line):

       runclient -client ConverterApp.ear -name ConverterClient 
    -textauth



  5. The client container prompts you to log in. Enter guest for the user name and guest123 for the password.

  6. In the terminal window, the client displays these lines:

       Binding name:'java:comp/env/ejb/SimpleConverter'
    12160.00
    0.77
    Unbinding name:'java:comp/env/ejb/SimpleConverter'



J2EE Tutorial-13(Deploying the J2EE Application)

Now that the J2EE application contains the components, it is ready for deployment.

  1. Select the ConverterApp application.

  2. Select ToolsDeploy.

  3. In the Introduction dialog box, confirm that ConverterApp is shown for the Object To Deploy and that localhost is shown for the Target Server.

  4. Select the checkbox labeled Return Client Jar.

  5. In the text field that appears, enter the full path name for the file ConverterAppClient.jar so that it will reside in the j2eetutorial/examples/src/ejb/converter subdirectory. TheConverterAppClient.jar file contains the stub classes that enable remote access to ConverterEJB.

  6. Click Next.

  7. In the JNDI Names dialog box, verify the names you entered in the previous section.

  8. Click Next.

  9. In the WAR Context Root dialog box, enter converter in the Context Root field. When you run the Web client, the converter context root will be part of the URL.

  10. Click Next.

  11. In the Review dialog box, click Finish.

  12. In the Deployment Progress dialog box, click OK when the deployment completes.

J2EE Tutorial-11(Creating the Web Client)

The Web client is contained in the JSP page j2eetutorial/examples/src/ejb/converter/index.jsp. A JSP page is a text-based document that contains static template data, which can be expressed in any text-based format such as HTML, WML, and XML; and JSP elements, which construct dynamic content.

Coding the Web Client


The statements (in bold in the following code) for locating the home interface, creating an enterprise bean instance, and invoking a business method are nearly identical to those of the J2EE application client. The parameter of the lookup method is the only difference; the motivation for using a different name is discussed in Specifying the JNDI Names.

The classes needed by the client are declared with a JSP page directive (enclosed within the <%@ %> characters). Because locating the home interface and creating the enterprise bean are performed only once, this code appears in a JSP declaration (enclosed within the <%! %> characters) that contains the initialization method, jspInit, of the JSP page. The declaration is followed by standard HTML markup for creating a form with an input field. A scriptlet (enclosed within the <% %> characters) retrieves a parameter from the request and converts it to a BigDecimal object. Finally, JSP expressions (enclosed within <%= %> characters) invoke the enterprise bean's business methods and insert the result into the stream of data returned to the client.

<%@ page import="Converter,ConverterHome,javax.ejb.*,
javax.naming.*, javax.rmi.PortableRemoteObject,
java.rmi.RemoteException" %>
<%!
private Converter converter = null;
public void jspInit() {
try {
InitialContext ic = new InitialContext(); Object objRef = ic.lookup(" java:comp/env/ejb/TheConverter"); ConverterHome home = (ConverterHome)PortableRemoteObject.narrow( objRef, ConverterHome.class); converter = home.create(); } catch (RemoteException ex) {
...
}
}
...
%>
<html>
<head>
<title>Converter</title>
</head>

<body bgcolor="white">
<h1><center>Converter</center></h1>
<hr>
<p>Enter an amount to convert:</p>
<form method="get">
<input type="text" name="amount" size="25">
<br>
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
<%
String amount = request.getParameter("amount");
if ( amount != null && amount.length() > 0 ) {
BigDecimal d = new BigDecimal (amount);
%>
<p><%= amount %> dollars are
<%= converter.dollarToYen(d) %> Yen.
<p><%= amount %> Yen are
<%= converter.yenToEuro(d) %> Euro.
<%
}
%>
</body>
</html>


Compiling the Web Client


The J2EE server automatically compiles Web clients that are JSP pages. If the Web client were a servlet, you would have to compile it.

Packaging the Web Client


To package a Web client, you run the New Web Component wizard of the deploytool utility. During this process the wizard performs the following tasks.

  • Creates the Web application deployment descriptor

  • Adds the component files to a WAR file

  • Adds the WAR 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 Web Component wizard, select FileNewWeb Component. 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. WAR File dialog box

    1. Select Create New WAR File In Application.

    2. In the combo box, select ConverterApp.

    3. In the WAR Display Name field, enter ConverterWAR.

    4. Click Edit.

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

    6. Select index.jsp and click Add.

    7. Click OK.

    8. Click Next.



  3. Choose Component Type dialog box

    1. Select the JSP radio button.

    2. Click Next.



  4. Component General Properties dialog box

    1. In the JSP Filename combo box, select index.jsp.

    2. Click Finish.




Specifying the Web Client's Enterprise Bean Reference


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

Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");


You specify this reference as follows:

  1. In the tree, select ConverterWAR.

  2. Select the EJB Refs tab.

  3. Click Add.

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

  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.

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.

Govt to remove multi-level TDS on software from July

Image In a big relief to the software industry, the government today said it will do away with the complex multi-level system of Tax Deduction at Source (TDS) for the sector from July 1.

"... no deduction of tax shall be made on... payment by a person (transferee) for acquisition of software from another person (transferor), being a resident," the Finance Ministry said in a notification.

The provisions will come into force from July 1, 2012, it said.

Under the current structure, TDS of 10 per cent is levied at every level of software distribution chain -- right from master distributor to retailer and then to the final consumer.

Responding to the long-standing demand of the software sector, Finance Minister Pranab Mukherjee had last week said that Section 194J of the Income Tax Act, 1961, would be amended so as to avoid multi-level TDS on information technology sector.

Section 194(J) of the IT Act deals with fees for professional and technical services and covers royalty and non-compete fees.

The exemption from multi-level TDS would be applicable in case where the software is acquired in a subsequent transfer, without any modification.

Besides, the exemption will also be provided in cases where tax has been deducted under 194J on payment for any previous transfer of such software or under Section 195 on payment for any previous transfer of such software from a non-resident.

Further, it will also apply in those cases wherever the transferor had paid the taxes.

Software industry body Nasscom had been demanding removal of the multi-level TDS on software arguing that such a decision would improve finances of the IT sector.

The TDS model, it had argued, "was leading to an unsustainable model for software distributorswho operate on very low margins."

Tuesday, June 12, 2012

A software that converts grayscale images into coloured

Image Researchers have developed a new software that can easily transformgrayscale images into stunning yet realisticcolours, utilising the vast amount of imagery available on the internet.

Existing methods require the user's input, either by using a scribbling tool to colour the image manually or by using a colour transfer. Both options can result in poor colourisation quality limited by the user's degree of skill or the range of reference images available.

"We have developed a method that takes advantage of the plentiful supply of internet data to colourise gray photos," said Alex Yong-Sang Chia of the Singapore-based A*STAR's Institute for Infocomm Research, who along with colleagues developed the computer program.

The software searches hundreds of thousands of online colour images, cross-referencing their key features and objects in the foreground with those of grayscale pictures, according to anA*STAR statement.

"The user segments the image into separate major foreground objects and adds semantic labels naming these objects in the gray photo. Our program then scans the internet using these inputs for suitable object colour matches," said Chia.

Given the vast amount of visual data available online, not all of the chosen images are useful. Once the initial colour images have been found, the program then filters them to find the most realistic and suitable matches for the grayscale object inputs.

"Our coloured images were classed as 'real' up to 65 per cent of the time," says Chia. "Overall the colourisation results are visually pleasing and perceptually meaningful to users."

How Windows 8 Throws Computer Users Under the Bus

Image

Whatever you think of Windows 8’s Metro interface on smartphones and tablets, Microsoft’s decision to force computer users to deal with Metro will needlessly alienate and confuse many of the company's most loyal customers. It’s as if Apple suddenly required Mac users to rely on iOS instead of OS X.


The Metro interface fills the screen with “active” tiles designed to give users quick access to a device’s various applications and functions. On small smartphone screens, it’s an effective and attractive visual metaphor, making better use of scarce real estate than the icon-based alternatives in Apple’s iOS and Google’s Android.

It also still holds up pretty well on small-ish tablet touchscreens where the relatively large tiles make it easy to select what you want. (It's not a surprise that almost all of the screenshots you see of Metro are of a few tiles filling a small tablet screen.)



So far, so good.

Metro Fails the Big-Screen Test


But as many reviewers have noted, when you stick Metro on a full-sized computer screen, it becomes a bit ridiculous. A sea of tiles swimming on a 27-inch monitor doesn’t make any sense - and how does it look on two big-screen displays?

Despite features that let you organize the tiles, the bigger the screen, the more that Metro turns into a jumbled, confusing mess.



Of course, you don’t have to actually do your work in Metro - and most people won’t. It’s easy enough to move through Metro to get to a more traditional Windows-style desktop. But Microsoft has made the curious decision not to let PC-based users choose to avoid the Metro screen altogether. Unless you come up with some hack or third-party add-on (which most computer users will never do), you’ll still have to navigate through Metro every time you turn on your computer.

That simply doesn’t make any sense from an end-user perspective. Microsoft seems so infatuated with the tablets and smartphones that it’s throwing those boring old computer users under the bus. Sure, Windows 8 includes plenty of cool new features for PC users, but that’s not the point. The company is clearly betting the farm on trying to catch up in the mobile space.

Apple Knows that Size Matters


Apple, meanwhile, is treading much more carefully in this regard. While the latest versions of the Mac’s OS X continue to incorporate features and interfaces from the iOS used on iPhones and iPads, the two operating systems remain clearly distinct, with interfaces optimized for their particular platforms. Perhaps because it makes its own hardware, Apple has a better understanding of the different interface challenges of a 3.5-inch iPhone screen and a 27-inch iMac monitor.

Microsoft is risking a huge backlash here. And it doesn’t have to. All it would take to solve this problem is a simple switch to let PC users avoid Metro if they choose. C'mon, Mr. Ballmer - you want to keep PC users happy, don’t you? So why are you making them pretend they’re using a tablet?

Monday, June 11, 2012

11 Free Linux Apps Your Business Needs Now

The good news is that there are free and open-source alternatives for virtually every package a small business might need, and most of them are excellent. Whether or not you've already made the switch to Linux -- there are, after all, myriad security and other reasons for doing so -- these free apps can be just what any small business needs to succeed.

1. Office Productivity: OpenOffice

OpenOffice.org 3 (also known as OO.o) is a fantastic open-source alternative to Microsoft Office. With components for word processing, spreadsheets, presentations, graphics, databases and more, it is available in many languages and works on all common operating systems, including Linux, Mac and Windows. All data gets stored in an international open standard format, and the software can read and write files from Office as well. Perhaps best of all, the interface is so familiar and intuitive that you might not even realize you're using anything new. You can download and use OpenOffice free of charge.

2. Accounting: GnuCash

GnuCash is a personal and small-business financial-accounting software package that's also available for Linux, Mac OS X, and Windows. Both powerful and flexible, GnuCash lets you track bank accounts, stocks, income and expenses. As quick and intuitive to use as a checkbook register, it is based on professional accounting principles to ensure balanced books and accurate reports. Among GnuCash's key features are double-entry accounting, small-business accounting, invoicing and more. Data can be imported from programs such as Microsoft Money and Quicken, while it can be exported to spreadsheets such as Microsoft Excel. Once again, thisfree software's interface is so intuitive and familiar that if you've used other accounting programs before, this one will be no problem.

3. Desktop publishing: Scribus

Scribus is a free program that offers professional page-layout capabilities for Linux, Mac OSX and Windows desktops. Scribus supports professional publishing features including CMYK color separations for both press-ready output and PDF creation. I've found the software can do just about anything the paid packages can, and it's comparable to InDesign or Publisher, for instance.

4. E-mail: Zimbra

Zimbra Desktop is free e-mail and calendar software that runs on any Linux, Mac or Windows computer. The tool offers e-mail, contacts, calendar and document capabilities all in one application, and it lets users read e-mail from any POP or IMAP e-mail account, including Gmail, Hotmail or business e-mail. Owned by VMware, Zimbra works both online and off, and there's no limit to the size of your e-mail storage. As an added bonus, it's also available in 20 languages.

5. Web page editing: KompoZer

Much like Microsoft's old FrontPage, KompoZer is a tool for anyone who ever works with a Web page. Downloadable for free and compatible with Linux as well as the usual other alternatives,KompoZer is a WYSIWYG (What You See Is What You Get) editor, meaning that you can edit Web pages visually as well as by working with the raw HTML code. The free software is extremely easy to use, making it ideal for nontechnical computer users who want to create an attractive, professional-looking Web site without necessarily needing to know HTML.

6. Graphics: GIMP

GIMP, which stands for "GNU Image Manipulation Program," is a free and open source alternative to Adobe's pricey PhotoShop product. With an interface very similar to PhotoShop's,GIMP offers capabilities including photo retouching, image composition and image authoring. I believe GIMP will satisfy all but the highest-end professional graphic designers. It's perfect for making Web graphics, retouching product photos and creating marketing materials, and any images created can be saved in an array of common formats, including PSD Photoshop.

7. Backup: Amanda

Amanda is a backup and recovery solution that lets you set up a single master backup server to back up multiple hosts to a single large-capacity tape or disk drive. The software can back up a large number of workstations running multiple versions of Linux, Mac OS or Windows. Currently, it's used to protect more than half a million servers and desktops around the world. A sister service to Amanda, meanwhile, is Zmanda, which provides paid backup in the cloud.

8. HR management: OrangeHRM

OrangeHRM is a free package for human resources management. With modules for personnel information management, benefits, recruitment, employee self-service, leave, and time and attendance‚ the software also offers optional paid services including training, support and customization.

9. E-mail campaigns: phpList

If your business runs e-mail campaigns, phpList can be a great tool. The software is free to download, install and use, and it's easy to integrate with any Website. Ideal for newsletters, publicity lists, notifications and many other uses, phpList is designed to manage mailing lists with up to hundreds of thousands of subscribers. A Web interface lets you write and send messages and manage phpList over the internet.

10. Project management: OpenProj

OpenProj is a free project-management package that substitutes nicely for Microsoft Project but works with Linux and Mac as well as Windows. With more than a million users, OpenProj's installed base is second only to that of Microsoft Project itself--which, of course, costs a heck of a lot more. Gantt charts, PERT charts and all the other capabilities offered by Microsoft's software are in OpenProj as well, and existing Project files can be easily imported.

11. Antivirus: ClamAV

Even if you're running Linux, it's still a good idea to use some kind of antivirus software. Originally designed for Unix, ClamAV is a nice package that's now available for Linux as well as for Windows and a number of other platforms. The tool offers built-in support for almost all mail file formats as well as popular document formats including Microsoft Office, HTML, RTF and PDF. With a virus database that's updated multiple times per day, ClamAV is, of course, also free.

MAMP


MAMP installs a local server environment in a matter of seconds on your Mac OS X computer, be it PowerBook or iMac. MAMP will not compromise any existing Apache installation already running with your OS X. You can install Apache, PHP and MySQL without starting a script or having to change any configuration files.

Screenshot

Gmail Notifr


Gmail Notifr sends you notifications about the received e-mails and other events in your Google account. It supports multiple accounts, checks mail at a specified interval, has Growl and sound notifications and has no background daemon processes installed as Google’s official notifier. Requirements: Mac OS X 10.5+ (Leopard).

Screenshot

TextWrangler


TextWrangler is the powerful general purpose text editor, and Unix and server administrator’s tool. Essentially, it is a free version of BBEdit (see below). It offers a broad range of support for different programming languages, and fantastic find and replace functionality. A reliable and powerful tool, especially considering its freeware status. (via appstorm.net). Requires: Mac OS X 10.4 or later. Alternatives: eMacsSmultron, TextEdit (native Mac-app).

Screenshot

CyberDuck


Cyberduck is an open source FTP, SFTP-client and also a WebDAV, Mosso Cloud Files and Amazon S3 browser for the Mac. It features an easy to use interface with quickly accessible bookmarks. The outline view of the browser allows to browse large folder structures efficiently and you can quickly preview files with Quick Look. To edit files, a seamless integration with several external editors makes it easy to change content quickly. An alternative: Filezilla.

Screenshot

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