Showing posts with label servlets. Show all posts
Showing posts with label servlets. Show all posts

April 14, 2017

J2EE Technologies Details explanation with examples


JDBC
Platform and vendor transparent access to SQL databases.
RMI-IIOP
J2SE RMI implementation over OMG's IIOP.
Java IDL
CORBA interoperability. Includes a lightweight ORB that supports IIOP.
Servlet
Server-side Web development. The "controller" layer. Middle tier flow-of-control logic.
JSP
Dynamic Web pages. The "view" layer. Middle tier presentation code.
JNDI
Unified enterprise naming API. A location-transparent repository for hierarchical data and relationships.
EJB
Component model for building "overhead free" business objects. The "model" layer. Middle tier business logic.
JMS
Asynchronous messaging that supports: queuing, publish-subscribe, and various aspects of push/pull technologies.
JTA
Distributed transaction demarcation API. Specifies a Java mapping to the X/Open XA transaction protocol.
JTS
Specifies the implementation of a Transaction Manager which supports the Java Transaction API (JTA) spec. Implements a Java mapping of the OMG Object Transaction Service (OTS).
Connector    
Legacy integration. The J2EE Connector architecture defines a standard architecture for connecting the J2EE platform to heterogeneous Enterprise Information Systems (e.g. mainframe transaction processing, database systems, ERP, and legacy applications not written in the Java programming language)
JavaMail
Platform and protocol-independent framework for building Java-based mail and messaging applications.


More Examples of J2EE Technologies
Read more ...

February 19, 2013

Which of the following snippets of the deployment descriptor can be used to return the value "mySecret" when the following API is called: getServletConfig ().getInitParameter ("sharedSecret")?

The getServletConfig () API returns a ServletConfig class. When the Container initializes a servlet, the container
creates a unique ServletConfig for the servlet. In fact, each servlet in a web app has its own ServletConfig. The
container retrieves the servlet initialization parameters from the Deployment Descriptor, and makes them available
as part of the ServletConfig. Servlet init parameters are similar to context init parameters, except servlet
parameters are only available to a particular servlet while context parameters are available to the entire web
application.
To configure servlet init parameters that are accessible from the ServletConfig, one needs to use the
element. The element is used to configure servlet init parameters that are specific
for particular servlet, and hence, should be contained within the element.
Hence, the answer is:

.....

MyServlet</servlet-name>
MyServlet</servlet-class>

sharedSecret mySecret
.....
Read more ...

October 10, 2012

Responce once commited, any subsequent redirect operations will throw an IllegalStateException?

public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter out = response.getWriter();
String dbValue = getValueFromDB ();
if (dbValue == null) response.sendError (HttpServletResponse.SC_NOT_FOUND, "DB Lookup Failed");
response.sendRedirect ("Form.jsp");
}

Question:
Consider the following code snippet of above servlet code.
If the getValueFromDB () method returns null , which of the following statements are true?
(A) The code will work without any errors or exceptions
(B) An IllegalStateException will be thrown
(C) A NullPointerException will be thrown
(D) An IOException will be thrown

The correct answer(s):
(B) An IllegalStateException will be thrown
Explanation:
When the sendError() API is called, the response is considered committed and should not be written to
subsequently. Once the response is considered committed, any subsequent redirect operations will throw an
IllegalStateException.
In this above servlet code, the sendError() is invoked when the dbValue is null, which will cause the response to be
committed. Hence, the subsequent response.sendRedirect () method will then cause an IllegalStateException to
be thrown.
Reference: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletResponse.html
Read more ...

What will be the output of the following JSP code ?

Jsp Code:



<! int a =20>
<! int b = 30>
<%= b* a>




May be bellow answers suitable(chose any one):
(A) The code will not compile
(B) The value of b multiplied by a is 30
(C) The value of b multiplied by a is 300
(D) The value of b multiplied by a is 600
(E) The value of b multiplied by a is 0

Why The is the correct answer(s):
(C) The value of b multiplied by a is 300

Explanation:
Although the variable "a" is declared twice, the code should still compile as written. In the first declaration
 <% int a = 10; %>, the variable "a" will be declared as a local variable. In the second declaration 
<%! int a = 20; %>, the variable "a" will be declared as an instance variable, global to the translated servlet class.
Upon translation, the Container will translate the JSP code similar to the following:
public class ..._jsp
{
int a = 20;
int b = 30;
public void _jspService (....)
{
int a = 10;
out.write ("The value of b multiplied by a is ");
out.print (b * a);
}
Since the local variable "a" has precedence over the global variable "a", 
the expression (b * a) evaluates as (30 *10), which equals 300.

Reference: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro7.html
Read more ...

July 27, 2012

Servlets can use four types of scope for the variables


Local scope
Page scope
Session scope
Application or server scope.

Local scope: If a variable gets declared inside any method of the servlet or any block then it becomes local scope.

Page scope: If a variable can be available to all parts of the servlets and all users share one instance of the variable, then it becomes page scope. An instance or class variable of the servlet can be called as page scope variable. Such types of variables can be used to share common information about all users in all servlets.

Example:

user.java
//creating page variable
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class user extends HttpServlet
{
int x=0;
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
PrintWriter out=res.getWriter();
out.println("");
out.println("");
out.println(""+x+""); 
x++;
out.println("");
out.println("");
}
}



Compilation

javac -cp servlet-api.jar user.java (for tomcat 6.0)


Output

Run the tomcat then write the below line in the URL
http://localhost:8081/serv/user
Here serv is the Context path, which we mentioned in the server.xml file, which is present in (E:\Program Files\Apache Software Foundation\Tomcat 6.0\conf) directory.


Note: - When we refresh the page the number goes on increasing. Also when we open a new browser and write the above URL then also number goes on inceasing. So, here we note that for every visit of new user the number goes on increasing until the server gets restarted.

Session scope: - If a variable can be available to all servlets and for each user it becomes individual then it is called as user or session scope. Such types of variable can be used to store individual information for each user and for multiple servlet .It can be created by using cookie or session.

Application or server scope:- If a variable can be available to all servlets and all users share a common instance of the variable then it is called as application or server scope. Such type of variables can be used to store common information about all servlet and all users.

Creation and reading process of application scope variables
Create the object of javax.servlet.servletContext by using getServletContext() method of generic servlet.The object of servlet context represent all the servlets present in the servlet container.

Use setAttribute() of servlet context to create application scope variable. It accepts two parameters as the name of the variable and value of the variable.

Use getAttribute() of servlet context to find value of application scope variable. If the specified variable does not exits then it returns null.
Example

welcome.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class welcome extends HttpServlet 
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{

ServletContext sc=getServletContext();
Integer x=(Integer)sc.getAttribute("hit");
PrintWriter out=res.getWriter();
out.println("");
if(x ==null)
x=1;
else
x++;
sc.setAttribute("hit",x);
out.println("
Welcome

");
out.println("
Hit count

");
out.println("");
}
}

user1.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class user1 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
ServletContext sc=getServletContext();
Integer x=(Integer)sc.getAttribute("hit");
PrintWriter out=res.getWriter();
out.println("");
out.println("
Users visited "+x+"

");
out.println("");
}
}

Web.xml settings



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">


welcome
welcome


user1
user1


welcome
/welcome


user1
/user1


Compilation

javac -cp servlet-api.jar welcome.java (for tomcat 6.0)
javac -cp servlet-api.jar user1.java (for tomcat 6.0)



Output

Run the tomcat then write the below line in the URL
Here serv is the Context path, which we mentioned in the server.xml file, which is present in (E:\Program Files\Apache Software Foundation\Tomcat 6.0\conf) directory.
http://localhost:8081/serv/welcome

Note: - In welcome. Java file the value is stored in hit variable and it is retrieved in user1.java file. So, here we note that for every visit of new user the number goes on increasing until the server gets restarted.
Read more ...

What does the 'load-on-startup' element mean in Deployment Descriptor (web.xml)?

The load-on-startup element indicates that this servlet should be loaded
(instantiated and have its init() called) on the startup of the web
application. The optional contents of these element must be an integer
indicating the order in which the servlet should be loaded. If the value is
a negative integer, or the element is not present, the container is free to
load the servlet whenever it chooses. If the value is a positive 128
integer or 0, the container must load and initialize the servlet as the
application is deployed. The container must guarantee that servlets marked
with lower integers are loaded before servlets marked with higher integers.
The container may choose the order of loading of servlets with the same
load-on-start-up value.

This element of the Deployment Descriptor (web.xml) is used to determine
the order of initializing the particular servlet when the application
server starts up. The content of this element is expected to be a positive
integer and lower the number, earlier the particular servlet will be
initialized during server start up.

If the content is not a positive integer (or if no value is specified as
the content) then the application server is free to initialize the servlet
any time it wants during the server start up.

This maybe an application server dependent thing... but, I guess it's the
same for almost all popular application servers currently being used like
WebLogic, WebSphere, Oracle Application Server 10g, etc.

load-on-startup for Servlets:

......
<servlet id="servlet1">
<servlet-name>NameOfTheServlet</servlet-name>
<display-name>DisplayNameOfTheServlet</display-name>
<servlet-class>FullyQualifiedServletClassName</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
......

load-on-startup for JSPs:

......
<servlet>
<servlet-name>NameOfTheServletGenerated</servlet-name>
<jsp-file>RelativePathOfTheJSPFile</jsp-file>
<load-on-startup>3</load-on-startup>
</servlet>
......

Zero causes loading, too. Only negative values are not garanteed: "[...]If
the value is a positive integer or 0, the container must load and
initialize the servlet as the application is deployed.[...]"

We can specify the order in which we want to initialize various Servlets.
Like first initialize Servlet1 then Servlet2 and so on.
This is accomplished by specifying a numeric value for the
<load-on-startup> tag. <load-on-startup> tag specifies that the servlet
should be loaded automatically when the web application is started.

The value is a single positive integer, which specifies the loading order.
Servlets with lower values are loaded before servlets with
higher values (ie: a servlet with a load-on-startup value of 1 or 5 is
loaded before a servlet with a value of 10 or 20).

When loaded, the init() method of the servlet is called. Therefore this tag
provides a good way to do the following:

start any daemon threads, such as a server listening on a TCP/IP port, or a
background maintenance thread perform initialisation of the application,
such as parsing a settings file which provides data to other servlets/JSPs
If no <load-on-startup> value is specified, the servlet will be loaded when
the container decides it needs to be loaded - typically on it's first
access. This is suitable for servlets that don't need to perform special
initialisation.



As per my understanding the value for the <load-on-startup> has to be a
positive integer in order for it to get loaded automatically.

Read more ...

June 29, 2012

Setting Up Eclipse with Java 1.6 on Windows


Step 1 - Download Java
Step 2 - Install Java
Step 3 - Set the PATH
Step 4 - Set the CLASSPATH
Step 5 - Test the Java installation
Step 6 - Download and install Eclipse
Step 7 - Test the Eclipse installation
Step 1     Download Java 1.6 package for Windows
Click the Download button alongside the label  JDK 6 Update 2 (or similar). On that page, accept the license agreement near the top of the page and download either the online or offline Windows Platform installation file. The offline option is a big file (c. 66MB) which includes all of the Java language and can be used to install even when an internet connection is not available. The online option is a small file (c. 0.4MB) that when run downloads Java over an internet connection as installation proceeds. It is recommended that you save the installer file to the Desktop so that it can be found easily. 



Step 2     Install the Java 1.6 package.
a. Double-click the file that you just downloaded. The name should be something similar to jdk-6u2-windows-i586-p.exe or, if you chose the online installation option,jdk-6u2-windows-i586-p-iftw.exe

b. Accept the License Agreement.

c. Accept all the default choices. In other words, just keep clicking "Next".

d. Wait for the installation to complete.



Step 3     Update the PATH environment variable.
(The following is adapted from Sun's Installation Notes for JDK 1.6 Microsoft Windows)

You can run the JDK without setting the PATH variable, or you can optionally set it as a convenience. To save yourself a lot of careful typing, it is highly recommended that you set the path variable.
Set the PATH variable if you want to be able to conveniently run the JDK executables (javac.exejava.exejavadoc.exe, etc.) from any directory without having to type the full path of the command. If you don't set the PATH variable, you need to specify the full path to the executable every time you run it, such as:
   C:> "\Program Files\Java\jdk1.6.0_\bin\javac" MyClass.java

It's useful to set the PATH permanently so it will persist after rebooting.
To set the PATH permanently, add the full path of the jdk1.6.0_\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_\bin, where  is a two-digit number. Set the PATH as follows, according to whether you are on Microsoft Windows NT, XP, 98, 2000, or ME.
Microsoft Windows NT, 2000, and XP - To set the PATH permanently:
  1. Choose Start, Settings, Control Panel, and double-click System. On Microsoft Windows NT, select the Environment tab; on Microsoft Windows XP and 2000 select the Advanced tab and then Environment Variables. Look for "Path" in the User Variables and System Variables. If you're not sure where to add the path, add it to the right end of the "Path" in the User Variables. A typical value for PATH is:
       C:\Program Files\Java\jdk1.6.0_\bin 
    Where is the latest version number. For example, if you downloaded jdk1.6.0_02, then the value to add to the path is:
       C:\Program Files\Java\jdk1.6.0_02\bin 
                                                                                              Capitalization doesn't matter. Click "Set", "OK" or "Apply".The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should only have one bin directory for a JDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to jdk1.6.0_\bin.
  2. The new path takes effect in each new Command Prompt window you open after setting the PATH variable.
Microsoft Windows 98 - To set the PATH permanently, open the AUTOEXEC.BAT file and add or change the PATH statement as follows:
  1. Start the system editor. Choose "Start", "Run" and enter sysedit, then click OK. The system editor starts up with several windows showing. Go to the window that is displaying AUTOEXEC.BAT
  2. Look for the PATH statement. (If you don't have one, add one.) If you're not sure where to add the path, add it to the right end of the PATH. For example, in the following PATH statement, we have added the bin directory at the right end:
       PATH C:\WINDOWS;C:\WINDOWS\COMMAND;"C:\PROGRAM FILES\JAVA\JDK1.6.0_\BIN" 
    Capitalization doesn't matter. The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows searches for programs in the PATH directories in order, from left to right. You should only have one bin directory for a JDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to jdk1.6.0_.
  3. To make the path take effect in the current Command Prompt window, execute the following:
       C:> c:\autoexec.bat
    
        
    To find out the current value of your PATH, to see if it took effect, at the command prompt, type:
       C:> path
    
        
Microsoft Windows ME - To set the PATH permanently:
From the start menu, choose programs, accessories, system tools, and system information. This brings up a window titled "Microsoft Help and Support". From here, choose the tools menu, then select the system configuration utility. Click the environment tab, select PATH and press the edit button. Now add the JDK to your path as described in step b above. After you've added the location of the JDK to your PATH, save the changes and reboot your machine when prompted.



Step 4     Set the CLASSPATH environment variable.
The CLASSPATH variable tells Java where to look for *.class bytecode files. Bytecode is created when you compile your *.java files. Set the CLASSPATH as follows, according to whether you are on Microsoft Windows NT, XP, 98, 2000, or ME.
Microsoft Windows NT, 2000, and XP - To set the CLASSPATH:
  1. Choose Start, Settings, Control Panel, and double-click System. On Microsoft Windows NT, select the Environment tab; on Microsoft Windows 2000 or XP select the Advanced tab and then Environment Variables. Look for "classpath" in the User Variables and System Variables, then click Edit. If no classpath variable exists, create it by clicking New and adding "classpath" to the User Variables. A typical value for CLASSPATH is:
       .;..
    The '.' represents your current directory, allowing you to compile and run code in your current directory (as shown in the command line of your command window). The '..' represents the folder above the current directory. Together, the '.' and '..' cover most situations where you need to compile and run programs. The semi-colon ';' separates these entries. The CLASSPATH can contain multiple directories separated by semi-colons. 
    Click "Set", "OK" or "Apply".
  2. The new classpath takes effect in each new Command Prompt window you open after setting the CLASSPATH variable. 
Microsoft Windows 98 - To set the CLASSPATH permanently, open the AUTOEXEC.BAT file and add or change the CLASSPATH statement as follows:
  1. Start the system editor. Choose "Start", "Run" and enter sysedit, then click OK. The system editor starts up with several windows showing. Go to the window that is displaying AUTOEXEC.BAT
  2. Look for the CLASSPATH statement. (If you don't have one, add one.) The classpath should contain a '.' and a '..'. If you're not sure where to add them, put them at the right end of the CLASSPATH. For example, in the following CLASSPATH statement, we have added the '.' and '..' directories at the right end:
       CLASSPATH C:\someFolder\someClasses.jar;..;.
    The '.' represents your current directory, allowing you to compile and run code in your current directory (as shown in the command line of your command window). The '..' represents the folder above the current directory. Together, the '.' and '..' cover most situations where you need to compile and run programs. The semi-colon ';' separates these entries. The CLASSPATH can contain multiple directories separated by semi-colons.
  3. To make the classpath take effect in the current Command Prompt window, execute the following:
       C:> c:\autoexec.bat
    To find out the current value of your CLASSPATH, to see if it took effect, at the command prompt, type:
       C:> classpath
        
Microsoft Windows ME - To set the CLASSPATH permanently:
From the start menu, choose programs, accessories, system tools, and system information. This brings up a window titled "Microsoft Help and Support". From here, choose the tools menu, then select the system configuration utility. Click the environment tab, select CLASSPATH and press the edit button. Now add '.' and '..' to your path as described in step b above. Then save the changes and reboot your machine when prompted.


Step 5     Test your Java installation.

a. Open a command window and create a test directory.

    1. Go to Start >> Run... then type cmd and click OK.
    2. Type cd \ and press Enter.
    3. The bottom line should read C:\>
    4. Type mkdir test and press Enter to create a new directory for your testing.
    5. Type cd testand press Enter to enter the directory. The bottom line of the command window should read  C:\test>

      b. Open a text editor and create a small Java program.
      Open WordPad or NotePad (in XP these can be found at Start >> All Programs >> Accessories) and copy in the following simple program:
      public class MyTestApplication {
      
        public static void main(String[] args) {
      
          System.out.println("Hello World!");
        }
      }

      c. Save the program in the test directory. 

      In the text editor menu, choose File >> Save. Then in the File Name field near the bottom of the dialog box, type the following exactly -

         C:\test\MyTestApplication.java
      and click Save.


      d. Confirm the save.
      In your command window, type dir. You should see something similar to -

      C:\test>dir
       Volume in drive C has no label.
       Volume Serial Number is 3C4D-5998

       Directory of C:\test

      29/01/2006  08:20 PM   
                .
      29/01/2006  08:20 PM              ..
      29/01/2006  08:20 PM               129 MyTestApplication.java
                     1 File(s)            129 bytes
                     2 Dir(s)  59,076,812,800 bytes free

      C:\test>


      e. Compile the program.
      Type javac MyTestApplication.java and press Enter. You should see -
      C:\test>javac MyTestApplication.java
      
      C:\test>
      There are two problems that you may encounter at this step.

      Problem 1
      If instead you get the following message -
      C:\test>javac MyTestApplication.java
      'javac' is not recognized as an internal or external command,
      operable program or batch file.
      
      C:\test>
      then Java has not been correctly installed. Perform the following tests :

          1) Check that Java has been correctly downloaded and installed. In particular, look for the directory
      C:\Program Files\Java\jdk1.6.0_\bin. If you cannot find a Java folder in the Program Files folder, then go back to Step 1 now.

          2) Check that the PATH variable has been set correctly. Type echo %path%. You should see something similar to -
      C:\test>echo %path%
      C:\Perl\bin\;c:\programfiles\imagemagick;C:\texmf\miktex\bin;C:\WINDOWS\system32
      ;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI Contr
      ol Panel;C:\Program Files\SecureCRT\;C:\Program Files\Java\jdk1.6.0_02\bin
      
      C:\test>
      If you do not see an entry anywhere in your PATH similar to the one above in bold, then go back to Step 3 now.


      Problem 2
      If instead you get the following message -
      C:\test>javac MyTestApplication.java
      error: cannot read: MyTestApplication.java
      1 error
      
      C:\test>
      then either the CLASSPATH variable is not set or your file is not in the test folder. Perform the following tests:

          1) Check that the CLASSPATH variable has been set correctly. Type echo %classpath%. You should see something similar to -
      C:\test>echo %classpath%
      .;..;C:\someFolder\someClasses.jar
      
      C:\test>
      Note that the classpath may have been automatically updated to contain the location of various class files, and therefore may be longer than the example above. Just make sure that it contains a '.' with a ';' to separate it from other entries. Go back to Step 4 above to edit the classpath.

         2) Make sure you are in the test folder. If you are not, then use the cd command to navigate to the test folder. Once you are in the test folder, type dir at the command line to examine its contents. If you do not see an entry for MyTestApplication.java then Go back to Step 5b above.


      f. Confirm the compilation.
      Type  dir. You should see something similar to -
      C:\test>dir
       Volume in drive C has no label.
       Volume Serial Number is 3C4D-5998
      
       Directory of C:\test
      
      29/01/2006  08:28 PM              .
      29/01/2006  08:28 PM              ..
      29/01/2006  08:28 PM               440 MyTestApplication.class
      29/01/2006  08:20 PM               129 MyTestApplication.java
                     2 File(s)            569 bytes
                     2 Dir(s)  59,076,796,416 bytes free
      
      C:\test>
      If compilation was successful, a *.class file should be present as shown.


      g. Run the program.

      Type java MyTestApplication to run the program. You should see -
      C:\test>java MyTestApplication
      Hello World!
      
      C:\test>
      There is one common problem at this step.

      Problem
      If you get the following message -
      C:\>java MyTestApplication
      Exception in thread "main" java.lang.NoClassDefFoundError: MyTestApplication
      
      C:\>
      then either your class file is not in the test folder (type dir at the command line to make sure), or you are in the wrong directory as in this example, where the javacommand has been typed in C: rather than C:\testGo back to Step 5b above and make sure that you have performed all steps correctly.



      Step 6     
      Download and install Eclipse.
      1. Download Eclipse from the Eclipse downloads page.
      2. Click the link next to "Download now".
      3. If possible, choose a mirror close to your location (e.g. Portland, if you are in Vancouver).
      4. Wait for your download to finish. This may take some time: the installer is a large file (>100MB).
      5. Unzip the downloaded file to C:\Program Files. Again, this may take some time.
      6. In C:\Program Files\eclipse, right-click on eclipse.exe and select Create Shortcut. Rename the shortcut to eclipse and drag it to your Desktop. Then close theeclipse folder.
      7. On the Desktop, double-click on the eclipse shortcut to start the program.
      8. Workspace Launcher dialog will appear. Select "Use this as the default and do not ask again" and click OK.
      9. Eclipse will start up. Either explore the Overview, Tutorials, etc. or close the Welcome page by clicking on the white X to reveal the Java perspective, where you will do your programming.
      Now set up Eclipse to use the latest version of Java for compiling and running your Java programs. 
      (Note: you need to configure Eclipse to use Java 1.6 or it will use an older Java version by default)
      1. Set the default installed JRE to Java 1.6 (this tells Eclipse which libraries to use):
        • Open the Eclipse Preferences Pane (Window -> Preferences) and go to the Java >> Installed JREs subpane.
        • Check the JRE 1.6.0_ as the default (where is a two digit number representing the version number that you downloaded and installed)
        • Click OK to save the settings.
      2. Set the Java compiler to Java 1.6 (this tells Eclipse which compiler to use):
        • In Eclipse Preferences Pane go to Java >> Compiler >> Compliance Level
        • Select "6.0".
        • Click OK to save the settings.
      Eclipse should then be set up properly to compile and run Java 1.6 programs. 


      Step 7     Test the Eclipse installation.

      Create a new Java project with a class and run it.
      1. In the Java Perspective, right-click in Eclipse's Package Explorer window and select New >> Project....
      2. Select Java Project and Next.
      3. Name the project whatever you like (e.g. 'test'). For now the other options do not matter; just click on Finish.
      4. In the Package Explorer window, right-click on the test package and select New >> Class.
      5. Name the class MyTestApplication. For now the other options do not matter; just click on Finish.
      6. Delete everything in the editor that appears. Copy the following into the editor:
      public class MyTestApplication {
      
        public static void main(String[] args) {
      
          System.out.println("Hello World!");
        }
      }
      7.  In the Eclipse menu bar, select File >> Save. If everything is working properly this program should compile automatically without errors.
      8  Run the program by right-clicking on the MyTextApplication class in the package manager, then select Run As >> Java Application.

        "Hello World!" should appear in the console output.
        Read more ...

        My Favorite Site's List

        #update below script more than 500 posts