Open Source Technical Information: Window's
Showing posts with label Window's. Show all posts
Showing posts with label Window's. Show all posts

Thursday, 1 March 2012

How to Install JDK 7 in windows

,


How to Install JDK 7

Java Development Kit (JDK) 1.7 (officially named Java SE 7), which is freely available from Sun Microsystems (now part of Oracle), is needed for writing Java programs. JDK can be downloaded from the Java mother site @ http://java.sun.com (or http://www.oracle.com/technetwork/java/index.html).

1.  How To Install JDK

JDK or JRE?
JRE (Java Runtime) is needed for running Java programs. JDK (Java Development Kit), which includes JRE plus the development tools (such as compiler and debugger), is need for writing Java programs. Since you are supposed to write Java Programs, install JDK (which includes JRE).
STEP 0: Un-install Older Version of JDK/JRE
If you have previously installed older version of JDK/JRE, un-install them. Run "Control Panel" ⇒ "Program and Features" ⇒ Un-install programs such as "Java SE Development Kit" and "Java SE Runtime". (If you are not sure whether you have older versions of JDK, check!)
STEP 1: Download JDK
  1. Goto Java SE download site @ http://www.oracle.com/technetwork/java/javase/downloads/index.html.
  2. Click the "Download" button under "JDK" of "Java SE 7".
  3. Choose your operating platform, e.g., Windows x86 (for 32-bit Windows OS - "jdk-7u2-windows-i586.exe" 84MB); or Windows x64 (for 64-bit Windows OS).
(For Mac Users Only) Download JDK from http://developer.apple.com/java/download/ and follow the instructions to install (or google "how to install JDK on Mac").
STEP 2: Install JDK/JRE
Run the downloaded installer, which installs both the JDK (Java Development Kit) and JRE (Java Runtime). By default, the JDK and JRE will be installed into directories "C:\Program Files\java\jdk1.7.0" and "C:\Program Files\java\jre7", respectively. For novices, accept the defaults.
I shall refer to the JDK installed directory as <JAVA_HOME>, hereafter, in this article.
(For Advanced Users Only)
  • The default JDK/JRE directories work but I recommend avoiding "Program Files" directory because of that blank character in the directory name. You may change the installed directories for JDK and JRE during installation. I personally installed JDK and all my programming tools in "d:\bin" (instead of "C:\Program Files") for ease of maintenance.
  • It is always cleaner to un-install all the out-dated JDK/JRE before installing a new version.
STEP 3: Include JDK's "bin" directory in the PATH
Windows Operating System searches the current directory and the directories listed in the PATH environment variable for executable programs invoked from the CMD shell. JDK's programs (such as compiler javac.exe and runtime java.exe) reside in directory "<JAVA_HOME>\bin" (where <JAVA_HOME> denotes the JDK installed directory you have chosen in the previous step). You need to include the "<JAVA_HOME>\bin" directory in the PATH environment variable.
To edit the PATH environment variable in Windows 2000/XP/Vista/7:
  1. Click the "Start" button ⇒ "Control Panel" ⇒ "System" ⇒ (Vista/7 only) "Advanced system settings".
  2. Switch to "Advanced" tab ⇒ "Environment Variables..."
  3. In "System Variables" box, scroll down to select "PATH" ⇒ "Edit..."
  4. In "Variable value" field, INSERT "c:\Program Files\java\jdk1.7.0\bin" (assume that this is your JDK's binary directory) IN FRONT of all the existing directories, followed by a semi-colon (;) which separates the JDK's binary directory from the rest of the existing directories. DO NOT DELETE any existing entries; otherwise, some existing applications may not run.
    Variable name  : PATH
    Variable value : c:\Program Files\java\jdk1.7.0\bin;....exiting entries....
    
(For Advanced Users Only) I suggested that you place the JDK binary directory in front of "c:\windows\system32" and "c:\windows". This is because some Windows systems may have an out-dated copy of JDK/JRE in these directories. Do a search for "java.exe", and you will be amazed of the findings.
You could read "Java Applications and Environment Variable" for more discussions about PATH environment variable.
(For Mac and Linux Users Only) You can set the environment variables JAVA_HOME and PATH in your .profile or .bashrc or .bash_profile (under your home directory $HOME) by including the following commands:
export JAVA_HOME=path_to_JDK_directory
export PATH=$JAVA_HOME/bin:$PATH
For Mac OS X, the path_to_JDK_directory is probably /Library/Java/Home. For Linux (Ubuntu), it is probably /usr/lib/jvm/java-7-xxx.
STEP 4: Verify the JDK Installation
Launch a CMD shell (click the "Start" button ⇒ run... ⇒ enter "cmd"), and
  1. Issue a "path" command to list the content of the PATH environment variable. Check the output and make sure that <JAVA_HOME>\bin is listed in the PATH.
    prompt> path
    PATH=c:\Program Files\java\jdk1.7.0\bin;......other entries......
  2. Issue the following commands to verify that JDK is properly installed and display its version:
    prompt> java -version
    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
    prompt> javac
    Usage: javac <options> <source files>
    .........
    .........
STEP 5: Compile & Run a Java Hello-world Program
Read "Writing your First Java Program with JDK and a Programming Text Editor".
"Everything that can possibly go wrong will go wrong": Read "JDK Installation Common Errors".
STEP 6: Download JDK API Documentation
The JDK download does not include the documentation, which needs to be downloaded separately. In the past, I always insist that my students should have a local copy of JDK API Documentation. But, today, you can easily access the online copy by googling "JDK 7 Documentation".
To install JDK API documentation:
  1. From the Java SE download page (@ http://www.oracle.com/technetwork/java/javase/downloads/index.html), look for "Java SE 7 Documentation" (under "Additional Resources") ⇒ Download the zip-file (e.g., "jdk-7....zip" - about 57MB).
  2. Unzip into the <JAVA_HOME> (JDK installed directory). The documentation will be unzipped into "<$JAVA_HOME>\docs". Browse the JDK documentation by opening "<JAVA_HOME>\docs\index.html".
STEP 7: (For Advanced Users Only) JDK's Source Code
Source code for JDK is provided and kept in "<JAVA_HOME>\src.zip". I strongly recommend that you to go through some of the source files such as "String.java", "Math.java", and "Integer.java", under "java\lang".

2.  Using External JAR files and Native Libraries In JDK (For Advanced Users Only)

External Java packages (such as JOGL, JUnit) are often distributed in JAR-files together with possibly native libraries (lib, dll). To use an external package in JDK, you need to:
  1. Include ALL the JAR-files in the CLASSPATH environment variable (e.g., classpath=.;path1\a.jar;path2\b.jar).
  2. Include the native libraries's directory in the PATH environment variable. (To be precise: The native libraries are to be kept in a directory accessible via JRE's property "java.library.path", which normally but not necessarily includes all the paths from the PATH environment variable).
If you cannot compile your program, make sure that the all the JAR files are included in the CLASSPATH. (Native libraries are not involved in the compilation.)
If you get a runtime error "java.lang.UnsatisfiedLinkError: no xxx in java.library.path". This means that JRE cannot find your native library at runtime. You could print the contents of "java.library.path" via System.out.println(System.getProperty("java.library.path")) and check whether it includes your native library's path.
You could set the native library path via the command-line option -Djava.library.path=xxx.
Alternatively, you could copy the JAR-files into JDK's extension directory at "<JDK_HOME>\jre\lib\ext", instead of using CLASSPATH; and copy all the dll's and lib's into a directory included in java.library.path.



If you found any thing wrong then pleas Let me know ...Write Your tips and suggestion in comment ... Thank you...

How To Install and Get Started: NetBeans 7.0 For Java Programming

,

NetBeans 7.0 For Java Programming

How To Install and Get Started

NetBeans (@ http://netbeans.org) is an open-source Integrated Development Environment (IDE), supported by Sun Microsystems (now part of Oracle). Compared with its rival Eclipse (http://www.elicpse.org) (both are open-source, so I don't know what are they competing for?), NetBeans provides seamless support for Java AWT/Swing, Java ME mobility pack, Java EE, and bundled with an excellent profiler for performance tuning.

How to Install NetBeans


Step 0: Install JDK
To use NetBeans for Java programming, you need to first install Java Development Kit (JDK). See "JDK - How to Install".
Step 1: Download
Download "NetBeans IDE" installer from http://netbeans.org/downloads/index.html. There are many "bundles" available. For beginners, choose the "Java SE" (NetBeans-7.0.1-ml-javase-windows.exe).
Step 2: Run the Installer
Run the downloaded installer. Choose your installation directory (e.g., "d:\myproject").

Writing a Hello-world Java Program in NetBeans


Step 0: Launch NetBeans
Launch NetBeans. If the "Start Page" appears, close it by clicking the "close" button.

Step 1: Create a New Project
For each Java application, you need to create a "project" to keep all the source files, classes and relevant resources.

  1. From "File" menu ⇒ Choose "New Project...".
  2. In "Choose Project" diglog ⇒ Under "Categories", choose "Java" ⇒ Under "Projects", choose "Java Application" ⇒ "Next".
  3. "Name and Location" ⇒ In "Project Name", enter "FirstProject" ⇒ In "Project Location", select a suitable directory to save your works ⇒ Uncheck "Create Main class" ⇒ Check "Set as Main Project" ⇒ Finish.
Step 2: Write a Hello-world Java Program
  1. Right-click on "FirstProject" ⇒ "New" ⇒ "Java Class..." (OR from the "File" menu ⇒ "New File..." ⇒ Categories: "Java", File Types: "Java Class" ⇒ "Next").
  2. "Name and Location" ⇒ In "Class Name", enter "Hello" ⇒ "Finish".
  3. The source file "Hello.java" appears in the editor panel. Enter the following codes:
    public class Hello {
        public static void main(String[] args) {
            System.out.println("Hello, world");
        }
    }
Step 3: Compile & Execute
There is no need to "compile" the source code explicitly, as NetBeans performs the so-called incremental compilation (i.e., the source statement is compiled while it is entered).
To run the program, right-click anywhere in the source (or from the "Run" menu), select "Run File" (or "Run Hello.java"). Observe the output on the output console.
Notes:
  • You should create a new Java project for each of your Java application.
  • Nonetheless, NetBeans allows you to keep more than one programs in a project, which is handy for writing toy programs (such as your tutorial exercises). If you have more than one files with main() method in one project, you need to right-click the source and choose "Run File".
Step 4: Read the NetBeans Documentation

  • At a minimum, you SHOULD READ the "IDE Basics, Getting Started, Java Application", which is accessible via NetBeans's "HELP" menu ⇒ "Help Contents".
  • The "Help" ⇒ "Online Doc and Support" (@ http://netbeans.org/kb/index.html) contains many articles and tutorial on using NetBeans.
  • The NetBeans "Start Page" also provides many useful links to get you started.

Debugging Program in NetBeans

Step 0: Write a Java Program
The following program computes and prints the factorial of n (=1*2*3*...*n). The program, however, has a logical error and produce a wrong answer for n=20 ("The Factorial of 20 is -2102132736" - a negative number?!).
1
2
3
4
5
6
7
8
9
10
11
12
13
public class Factorial {
   // Print factorial of n
   public static void main(String[] args) {
      int n = 20;
      int factorial = 1;
   
      // n! = 1*2*3...*n
      for (int i = 1; i <= n; i++) {
         factorial *= i;
      }
      System.out.println("The Factorial of " + n + " is " + factorial);
   }
}
Let us use the graphic debugger to debug the program.
Step 1: Set an initial Breakpoint
A breakpoint suspends program execution for you to examine the internal states of the program. Before starting the debugger, you need to set at least one breakpoint to suspend the execution inside the program. Set a breakpoint at main() method by clicking on the left-margin of the line containing main(). A red circle or an inverted Triangle appears in the left-margin indicating a breakpoint is set at that line.

Step 2: Start Debugging
Right click anywhere on the source code ⇒ "Debug File". The program begins execution but suspends its operation at the breakpoint, i.e., the main() method.
As illustrated in the following diagram, the highlighted line (also pointed to by a green arrow) indicates the statement to be executed in the next step.

Step 3: Step-Over and Watch the Variables and Outputs
Click the "Step Over" button (or select "Step Over" in "Debug" menu) to single-step thru your program. At each of the step, examine the value of the variables (in the "Variable" panel) and the outputs produced by your program (in the "Output" Panel), if any. You can also place your cursor at any variable to inspect the content of the variable.
Single-stepping thru the program and watching the values of internal variables and the outputs produced is the ultimate mean in debugging programs - because it is exactly how the computer runs your program!
Step 4: Breakpoint, Run-To-Cursor, Continue and Finish
As mentioned, a breakpoint suspends program execution and let you examine the internal states of the program. To set a breakpoint on a particular statement, click on the left-margin of that line (or select "Toggle Breakpoint" from "Run" menu).
"Continue" resumes the program execution, up to the next breakpoint, or till the end of the program.
"Single-step" thru a loop with a large count is time-consuming. You could set a breakpoint at the statement immediately outside the loop (e.g., Line 11 of the above program), and issue "Continue" to complete the loop.
Alternatively, you can place the cursor on a particular statement, and issue "Run-To-Cursor" to resume execution up to the line.
"Finish" ends the debugging session. Always terminate your current debugging session using "Finish" or "Continue" till the end of the program.

Other Debugger's Features:

Modify the Value of a Variable
You can modify the value of a variable by entering a new value in the "Variable" panel. This is handy for temporarily modifying the behaviour of a program, without changing the source code.
Step-Into and Step-Out
To debug a method, you need to use "Step-Into" to step into the first statement of the method. You could use "Step-Out" to return back to the caller, anywhere within the method. Alternatively, you could set a breakpoint inside a method.

NetBeans - Tips & Tricks


General Usage

These are the features that I find to be most useful in NetBeans:

  1. Maximizing Window (double-click): You can double-click on the "header" of any panel to maximize that particular panel, and double-click again to restore it back. This is particularly useful for editing source code in full panel.
  2. Code Auto-Complete (or Intelli-Sense) (ctrl-space): Enter a partial statement (e.g., Sys) and press control-space to activate the auto-complete, which displays all the available choices.
  3. Javadoc (ctrl-space, alt-F1): Place the cursor on a method or class, and press ctrl-space to view the javadoc; or right-click ⇒ Show Javadoc (alt-F1) to open it on a browser.
  4. Code Shorthand (tab): For example, you can enter "sout" and press TAB for "System.out.println"; "psvm" for "public static void main(String[] args) { }" or "fori" + tab for a for-loop. To view and configure code template, choose "Tools" menu ⇒ "Options" ⇒ "Editor" ⇒ "Code Templates".
  5. Formatting Source Code (alt-shift-f): Right-click on the source (or from the "Source" menu) ⇒ Choose "Format". NetBeans will layout your source codes with the proper indents and format. To configure the formatting, choose "Tools" menu ⇒ "Options" ⇒ "Editor" ⇒ "Formatting".
    You can also select the section of codes to be formatted, instead of the entire file.
  6. Hints for Correcting Syntax Error: If there is a syntax error on a statement, a red mark will show up on the left-margin on that statement. You could click on the "light bulb" to display the error message, and also select from the available hints for correcting that syntax error.
  7. Rename (Refactor) (ctrl-r): To rename a variable, place the cursor on that variable, right-click ⇒ "Refactor" ⇒ "Rename" ⇒ Enter the new name. All the appearances of that variables in the project will be renamed.
  8. Small Programs: You can keep many small toy programs (with main()) in one Java project instead of create a new project for each small program. To run the desired program, on the "editor" panel ⇒ right-click ⇒ "Run File".
  9. Source Toggle Comment: To temporarily comment-off a block of codes, choose "Source" ⇒ "Toggle Comment".
  10. Error Message Hyperlink: Click on an error message will hyperlink to the corresponding source statement.
  11. Command-Line Arguments: To provide command-line arguments to your Java program in NetBeans, right-click on the "project" ⇒ "Set as Main Project" ⇒ "Set Configurations" ⇒ "Customize..." ⇒ "Run" ⇒ select the "Main" class ⇒ type your command-line arguments inside the "Arguments" field ⇒ choose "Run" menu ⇒ "Run Main Project".
  12. Line Numbers: To show the line numbers, right-click on the left-margin ⇒ "Show Line Numbers".
  13. Changing Font Face and Size: Tools ⇒ Options ⇒ Fonts & Colors ⇒ In "Category", select "Default" ⇒ In "Font", choose the font face and size.
  14. Resetting Window View: If you mess up the window view (e.g., you accidentally close a window and cannot find it anymore), you can reset the view via "Window" menu ⇒ "Reset Windows".
  15. Code Templates: For example, when you create a new Java class, NetBeans retrieves the initial contents from the "Java Class" code template. To configure code templates, select "Tools" menu ⇒ "Templates" ⇒ Choose the desired template ⇒ "Open in Editor". To set a value of a variable used in the all the code templates (e.g., $User), select "Tools" menu ⇒ "Templates" ⇒ "Settings".
  16. Displaying Chinese Character: Need to choose a font that support chinese character display, such as "Monospace", in Tools ⇒ Options ⇒ Fonts & Colors ⇒ Syntax ⇒ default.
  17. Let me know if you have more tips to be included here.

Java Application Development

  1. Choosing the JDK version for your program: Right-click on your project ⇒ "Properties" ⇒ "Source" node ⇒ You can select the JDK level of your project in pull-donw menu "Source/Binary Format".
  2. Enabling JDK 7 support: If JDK 7 is already installed in your system, right-click on your Project ⇒ "Properties" ⇒ "Source" node ⇒ "Source/Binary Format" ⇒ Select "JDK 7". Also check "Libraries" ⇒ Java Platform ⇒ JDK 7.
    If JDK 7 is not installed/configured, install JDK 7. Add JDK 7 support to NetBeans via "Tool" menu ⇒ "Java Platforms" ⇒ "Add Platform...".
  3. Choosing Default Charset: Right-click on your project ⇒ "Properties" ⇒ "Source" node ⇒ "Encoding" ⇒ choose your desired charset for the text-file I/O from the pull-down menu.
  4. Enabling Unicode Support for File Encoding: Right-click on your project ⇒ "Properties" ⇒ "Source" node ⇒ "Encoding" ⇒ choose your Unicode encoding (e.g., UTF-8, UTF-16, UTF-16LE, UTF-16GE) for the text-file I/O.
  5. To include Javadoc/Source: Use "Library Manager" (select the "Tools" menu ⇒ "Libraries"); or "Java Platform Manager" (select "Tools" menu ⇒ "Java Platforms")
  6. Adding External JAR files & Native Libraries (dll, lib): Many external Java packages (such as JOGL, Java3D, JAMA, etc) are available to extend the functions of JDK. These binaries are often provided in a "lib" directory with jar files and native libraries (dll and lib).
    To include an external JAR file into a project: Expand the project node ⇒ Right-click on "Libraries" ⇒ "Add JAR/Folder..." ⇒ Select the desired JAR file or the folder containing the classes.
    If the external package contains many JAR files, you could create a user library to contain all the JAR files, and add the library to all the projects that required these JAR files. From "Tools" menu ⇒ "Libraries" ⇒ "New Library..." ⇒ Enter a library name ⇒ Use "Add JAR/Folder..." to add JAR files into this library.
    Many JAR files come with native libraries in the form of dll or lib. The directory path of these libraries must be included in JRE's property "java.library.path". This can be done via right-click the project ⇒ Set Configuration ⇒ Customize... ⇒ Run ⇒ In "VM options", enter "-Djava.library.path=xxx", where xxx is path of the native libraries.
    Notes: The jar files must be included in the CLASSPATH. The native library directories must be included in JRE's property "java.library.path", which normally but not necessarily includes all the paths from the PATH environment variable.
    If you get a runtime error "java.lang.UnsatisfiedLinkError: no xxx in java.library.path", which means that JRE cannot find your native library at runtime. The easier way to debug is to print out the contents of "java.library.path" via System.out.println(System.getProperty("java.library.path")). You could set the native library path via the command-line VM option -Djava.library.path=xxx.

Writing Java GUI (AWT/Swing) Application in NetBeans


Step 0: Read
Java GUI Application Learning Trail @ http://www.netbeans.org/kb/trails/matisse.html.
Step 1: Create a New Project
  1. Launch NetBeans ⇒ File ⇒ New Project...
  2. Under "Categories", choose "Java" ⇒ Under "Projects", choose "Java Application" ⇒ Next
  3. In "Project Name", enter "FirstGUI" ⇒ Choose a suitable directory for your "Project Location" ⇒ Uncheck both the "Create Main class" and "Set as Main Project" boxes ⇒ Finish.
Step 2: Write a Java GUI Program
  1. Right-click on the project "FirstGUI" ⇒ "New" ⇒ "JFrame Form..." ⇒ In "Project Name", enter "Counter" ⇒ Finish.
  2. Create the GUI Components visually:
    1. From the "Platte" panel ⇒ "Swing Controls" ⇒ Drag and drop a "Label", "TextField", and "Button" into the design panel.
    2. Click on the "jLabel1" ⇒ In the "Properties" panel, enter "Count" in "text" (You can also double-click on the jLabel1 to change the text). Right-click on the jLable1⇒ Change Variable Name ⇒ In "New Name", enter "lblCount".
    3. Similarly, for "jTextField1" ⇒ Change the "text" to 0, and change the "Variable Name" to "tfCount" ⇒ Resize the text field if necessary.
    4. For "jButton1" ⇒ Change the "text" to "Count Up", and change the "Variable Name" to "btnCount".
  3. Write the event handler for the button by double-clicking the button and enter the following codes:
    private void btnCountActionPerformed(java.awt.event.ActionEvent evt) {
       tfCount.setText(Integer.toString(Integer.parseInt(tfCount.getText()) + 1));
    }
Step 3: Compile & Execute
Right-click the source and select "Run Counter.java".
Step 4: Study the Generated Source Code
Expand the private method initComponent() and study how the GUI builder declare, allocate and initialize the GUI Components. Note how the JButton registers an ActionEvent listener and how an inner class is used as the listener and provide the event handler actionPerformed(). Also notice that the main() method uses a Swing's worker to run the GUI on a separate thread, instead of the main thread.

Developing and Deploying Web Application in NetBeans


Read:

Web (HTTP) Servers

Configuring Web Server
You could configure the web server via "Tools" menu ⇒ "Servers".
Tomcat Server
To configure Tomcat Server, select "Tools" menu ⇒ "Servers" ⇒ click "Add Servers":
  1. Choose Server: Select the desired Tomcat version ⇒ Next.
  2. Installation and Login Details: In "Server Location", fill in the Tomcat installation directory ($CATALINA_HOME) ⇒ Enter the username/password of a tomcat user with "manager" role. You could either check the "create user if it does not exist" or define the tomcat user in "$CATALINA_HOME\conf\tomcat-users.xml" as follows:
    <tomcat-users>
       <role rolename="manager"/>
       <user username="tomcatmanager" password="xxxx" roles="manager,manager-script,admin" />
    </tomcat-users>
Running the Web Server
Choose "Services" ⇒ Expand "Servers" node ⇒ Right-click on the desired server ⇒ Start/Stop/Restart.

MySQL Database Server

You can also manage the MySQL database server directly from Tomcat. Read "NetBeans and MySQL" Section.

Writing a Hello-World Servlet/JSP Web Application

Create a New Servlet/JSP Project
  1. From "File" menu ⇒ choose "New Project...".
  2. "Choose Project" ⇒ Under "Categories", choose "Java Web" ⇒ Under "Projects", choose "Web Application" ⇒ "Next".
  3. "Name and Location" ⇒ In "Project Name", enter "HelloServletJSP" ⇒ In "Project Location", select a suitable directory to save your works ⇒ Check "Set as Main Project" ⇒ Next.
  4. "Server and settings" ⇒ Choose your server, or "add" a new server ⇒ Next.
  5. "Frameworks" ⇒ Select none for pure servlet/JSP application ⇒ Finish.
Writing a Hello-World JSP
A JSP page called "index.jsp" is automatically created, which says "Hello world!". To execute this JSP, right-click on the project ⇒ "Run". The URL is http://localhost:8080/HelloServletJSP/index.jsp.
Writing a Hello-World Servlet
  1. Right-click on the project "HelloServletJSP" ⇒ New ⇒ Servlet.
  2. "Name and Location" ⇒ In "Class Name", enter "HelloServlet" ⇒ In "Package", enter "hello" ⇒ Next.
  3. "Configure Servlet Deployment" ⇒ In "Servlet Name", enter "HelloServletExample" ⇒ In "URL Pattern", enter "sayhello" ⇒ Finish.
  4. Enter the following codes for "HelloServlet.java":
    package hello;
     
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    public class HelloServlet extends HttpServlet {
     
       @Override
       public void doGet(HttpServletRequest request, HttpServletResponse response)
               throws IOException, ServletException {
          // Set the response message's MIME type (in Content-Type response header)
          response.setContentType("text/html;charset=UTF-8");
          // Get an output Writer to write the response message over the network
          PrintWriter out = response.getWriter();
          // Write the response message (in an HTML page) to display "Hello, world!"
          try {
             out.println("<!DOCTYPE html>");
             out.println("<html>");
             out.println("<head><title>Hello Servlet</title></head>");
             out.println("<body><h1>Hello, World (from Java Servlet)!</h1></body>");
             out.println("</html>");
          } finally {
             out.close();  // Always close the output writer
          }
       }
    }
  5. To execute the servlet: Right-click on the project ⇒ run ⇒ Change the URL to http://localhost:8080/HelloServletJSP/sayhello.
Generating a WAR-file for a Web Application
A WAR (Web Archive) file is basically a zip file for distributing web application in single file. You can use WinZip or WinRAR to inspect or unzip the war file.
To distribute the project as a war-file, right-click project ⇒ "Clean and Build". The war file is created in the "dist" directory. You can deploy the web application by dropping the war-file into Tomcat's "webapps" directory. Tomcat will automatically unzip the war-file and deploy the application upon startup.
Debugging Web Application
The most important reason for using IDE is to use the graphic debugger for debugging the program. You can set a breakpoint in your server-side Java codes, and "Debug" a web application, similar to a standalone application.

Writing a Hello-world JSF 2.0 Web Application

Create a New JSF 2.0 Project
  1. From "File" menu ⇒ choose "New Project...".
  2. "Choose Project" ⇒ Under "Categories", choose "Java Web" ⇒ Under "Projects", choose "Web Application" ⇒ "Next".
  3. "Name and Location" ⇒ In "Project Name", enter "HelloJSF20" ⇒ In "Project Location", select a suitable directory to save your works ⇒ Check "Set as Main Project" ⇒ Next.
  4. "Server and settings" ⇒ Choose your server, or "add" a new server ⇒ Next.
  5. "Frameworks" ⇒ Check "JavaServer Faces" ⇒ In "Libraries", "Registered Libraries", select "JSF 2.0" ⇒ Finish.
  6. An "index.xhtml" JSF page is generated, as follows:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>Facelet Title</title>
        </h:head>
        <h:body>
            Hello from Facelets
        </h:body>
    </html>
    To run this facelet, right-click on the project ⇒ Run.
Create a new JSF 2.0 Facelet
  1. Right-click on the project ⇒ New ⇒ "Other..."
  2. "Choose File Type" ⇒ Under "Category", select "JavaServer Faces" ⇒ Under "File Type", select "JSF Page" ⇒ Next.
  3. "Name and Location" ⇒ In "File Name", enter "HelloJSF20" ⇒ In "Options", check "Facelets" ⇒ Finish.
  4. In "HelloJSF20.xhtml", enter the following codes:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>Hello JSF 2.0</title>
        </h:head>
        <h:body>
           <h1>Hello from Facelets</h1>
        </h:body>
    </html>
  5. To execute the JSF page, right-click on the project ⇒ Run ⇒ Change the URL to http://localhost:8080/HelloJSF20/HelloJSF20.xhtml.

Writing a Hello-world JSF 1.2 Web Application

Create a New JSF 1.2 Project
  1. From "File" menu ⇒ choose "New Project...".
  2. "Choose Project" ⇒ In "Categories", choose "Java Web" ⇒ In "Projects", choose "Web Application" ⇒ "Next".
  3. "Name and Location" ⇒ In "Project Name", enter "HelloJSF12" ⇒ In "Project Location", select a suitable directory to save your works ⇒ Check "Set as Main Project" ⇒ Next.
  4. "Server and settings" ⇒ choose your server, or "add" a new server ⇒ Next.
  5. "Frameworks" ⇒ Check "JavaServer Faces" ⇒ In "Libraries", "Registered Libraries", select "JSF 1.2" ⇒ Finish.
  6. A "WelcomeJSF.jsp" page is generated, as follows:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE html>
    <%--
        This file is an entry point for JavaServer Faces application.
    --%>
    <f:view>
      <html>
        <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
          <title>JSP Page</title>
        </head>
        <body>
          <h1><h:outputText value="JavaServer Faces"/></h1>
        </body>
      </html>
    </f:view>
    To run this page, right-click on the project ⇒ Run.
Create a new JSF 1.2 Page
  1. Right-click on the project ⇒ New ⇒ "Other..."
  2. "Choose File Type" ⇒ In "Category", select "JavaServer Faces" ⇒ In "File Type", select "JSF Page" ⇒ Next.
  3. "Name and Location" ⇒ In "File Name", enter "HelloJSF12" ⇒ In "Options", check "JSP File (Standard Syntax)" ⇒ Finish.
  4. In "HelloJSF12.jsp", enter the following codes:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE html>
     
    <f:view>
      <html>
        <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
          <title>Hello JSF 1.2</title>
        </head>
        <body>
          <h1><h:outputText value="Hello World!"/></h1>
        </body>
      </html>
    </f:view>
  5. To execute the JSF page, right-click on the project ⇒ Run ⇒ Change the URL to http://localhost:8080/HelloJSF12/faces/HelloJSF12.jsp.

Debugging Web Applications in NetBeans

You can debug a webapp just like standalone application. For example, you can set breakpoints, single-step through the programs, etc.

REFERENCES & RESOURCES

 

If you found any thing wrong then pleas Let me know ...Write Your tips and suggestion in comment ... Thank you...

Friday, 10 February 2012

Part 2- How to install mysql-connector-c++ in Windows | Mac | SunOS | RHEL-Red Hat/Fedora Linux?

,

Source Installation

The MySQL Connector/C++ is based on the MySQL client libary (MySQL C API). Connector C/C++ is linked against the MySQL client library. You need to have the MySQL client library installed in order to compile the Connector/C++.
You also need to have the cross-platform build tool CMake 2.6.2 or newer. Check the README file for platform specific notes on Windows and SunOS.
Typically the MySQL client library gets installed by installing the MySQL Server. However, check your operating system documentation for other installation options. Please note also, that MySQL provides downloads for certain platforms which contain no more than the required client library. It is a common mistake, in particular on Windows, to mix header files and binaries from different MySQL client libraries. Of course, this will cause issues.

[edit] Building on Unix, Solaris and Mac

1. Run CMake to build a Makefile

me@host:/path/to/mysql-connector-cpp> cmake .
-- Check for working C compiler: /usr/local/bin/gcc
-- Check for working C compiler: /usr/local/bin/gcc -- works
[...]
-- Generating done
-- Build files have been written to: /path/to/mysql-connector-cpp/

  Read on at point 3.) in case of configure problems.

2. Use make to build the libraries

me@host:/path/to/mysql-connector-cpp> make clean
me@host:/path/to/mysql-connector-cpp> make
[  1%] Building CXX object driver/CMakeFiles/mysqlcppconn.dir/mysql_connection.o
[  3%] Building CXX object driver/CMakeFiles/mysqlcppconn.dir/mysql_constructed_resultset.o
[...]
[100%] Building CXX object examples/CMakeFiles/statement.dir/statement.o
Linking CXX executable statement

If all goes well, you will find the Connector/C++ library in /path/to/cppconn/libmysqlcppconn.so . In case of problems read on below before you ask for assistance. 

3. CMake options: MySQL installation path, debug version and more
In case of configure and/or compile problems check the list of CMake options:

me@host:/path/to/mysql-connector-cpp> cmake -L
[...]
CMAKE_BACKWARDS_COMPATIBILITY:STRING=2.4
CMAKE_BUILD_TYPE:STRING=
CMAKE_INSTALL_PREFIX:PATH=/usr/local
EXECUTABLE_OUTPUT_PATH:PATH=
LIBRARY_OUTPUT_PATH:PATH=
MYSQLCPPCONN_GCOV_ENABLE:BOOL=0
MYSQLCPPCONN_TRACE_ENABLE:BOOL=0
MYSQL_CONFIG_EXECUTABLE:FILEPATH=/usr/bin/mysql_config

For example, if your MySQL Server installation path is not /usr/local/mysql and you want to build a debug version of the MySQL Connector/C++ use:

me@host:/path/to/mysql-connector-cpp> cmake -D CMAKE_BUILD_TYPE:STRING=Debug -D MYSQL_CONFIG_EXECUTABLE=/path/to/my/mysql/server/bin/mysql_config .

Verify your settings with cmake -L:

me@host:/path/to/mysql-connector-cpp> cmake -L
[...]
CMAKE_BACKWARDS_COMPATIBILITY:STRING=2.4
CMAKE_BUILD_TYPE:STRING=
CMAKE_INSTALL_PREFIX:PATH=/usr/local
EXECUTABLE_OUTPUT_PATH:PATH=
LIBRARY_OUTPUT_PATH:PATH=
MYSQLCPPCONN_GCOV_ENABLE:BOOL=0
MYSQLCPPCONN_TRACE_ENABLE:BOOL=0
MYSQL_CONFIG_EXECUTABLE=/path/to/my/mysql/server/bin/mysql_config

Procees with make clean; make as described at point 2.)

[edit] Building on Windows

The basic steps for building the driver on Windows are the same as on Unix: use CMake 2.6.2 or newer to generate build files for your compiler and compile the driver using your compiler.
We are sorry but we cannot formally support other compilers than Microsoft Visual Studio 2003 and above.
Thanks to CMake it is easy for you to try out other compilers. However, you may experience compile warnings, compile errors or linking issues not detected by Visual Studio. We appreciate your patches to fix any of them.
Consult the CMake manual or check cmake --help to find out which build systems are supported by your CMake version.

C:\>cmake --help
cmake version 2.6-patch 2
Usage
[...]
Generators

The following generators are available on this platform:
  Borland Makefiles           = Generates Borland makefiles.
  MSYS Makefiles              = Generates MSYS makefiles.
  MinGW Makefiles             = Generates a make file for use with
                                mingw32-make.
  NMake Makefiles             = Generates NMake makefiles.
  Unix Makefiles              = Generates standard UNIX makefiles.
  Visual Studio 6             = Generates Visual Studio 6 project files.
  Visual Studio 7             = Generates Visual Studio .NET 2002 project
                                files.
  Visual Studio 7 .NET 2003   = Generates Visual Studio .NET 2003 project
                                files.
  Visual Studio 8 2005        = Generates Visual Studio .NET 2005 project
                                files.
  Visual Studio 8 2005 Win64  = Generates Visual Studio .NET 2005 Win64
                                project files.
  Visual Studio 9 2008        = Generates Visual Studio 9 2008 project fil
  Visual Studio 9 2008 Win64  = Generates Visual Studio 9 2008 Win64 proje
                                files.
[...]

It is likely that your cmake binary will support more compilers ("generators") than supported by MySQL Connector/C++. We have built the driver using the following generators:
  • Microsoft Visual Studio 8 (Visual Studio 2005)
  • Microsoft Visual Studio 9 (Visual Studio 2008, Visual Studio 2008 Express)
  • NMake
Please see the above Installation instructions for Unix, Solaris and Mac for troubleshooting and configuration hints.
Experimental support for additional generators is discussed outside this wiki:
1. Run CMake to generate build files for your "generator"
1.1 Visual Studio

C:\path_to_mysql_cpp>cmake -G "Visual Studio 9 2008"
-- Check for working C compiler: cl
-- Check for working C compiler: cl -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: cl
-- Check for working CXX compiler: cl -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- ENV{MYSQL_DIR} =
-- MySQL Include dir: C:/Programme/MySQL/MySQL Server 5.1/include
-- MySQL Library    : C:/Progams/MySQL/MySQL Server 5.1/lib/opt/mysqlclient.lib
-- MySQL Library dir: C:/Progams/MySQL/MySQL Server 5.1/lib/opt
-- MySQL CFLAGS:
-- MySQL Link flags:
-- MySQL Include dir: C:/Progams/MySQL/MySQL Server 5.1/include
-- MySQL Library dir: C:/Progams/MySQL/MySQL Server 5.1/lib/opt
-- MySQL CFLAGS:
-- MySQL Link flags:
-- Configuring cppconn
-- Configuring test cases
-- Looking for isinf
-- Looking for isinf - not found
-- Looking for isinf
-- Looking for isinf - not found.
-- Looking for finite
-- Looking for finite - not found.
-- Configuring C/J junit tests port
-- Configuring examples
-- Configuring done
-- Generating done
-- Build files have been written to: C:\path_to_mysql_cpp
C:\path_to_mysql_cpp>dir *.sln *.vcproj
[...]
19.11.2008  12:16            23.332 MYSQLCPPCONN.sln
[...]
19.11.2008  12:16            27.564 ALL_BUILD.vcproj
19.11.2008  12:16            27.869 INSTALL.vcproj
19.11.2008  12:16            28.073 PACKAGE.vcproj
19.11.2008  12:16            27.495 ZERO_CHECK.vcproj

1.2 NMake

C:\path_to_mysql_cpp>cmake -G "NMake Makefiles"
-- The C compiler identification is MSVC
-- The CXX compiler identification is MSVC
[...]
-- Build files have been written to: C:\path_to_mysql_cpp


2. Use your compiler to build the MySQL Conenctor/C++
2.1 Visual Studio - GUI
Open the newly generated project files in the Visual Studio GUI or use a Visual Studio command line to build the driver. The project files contain a variety of different configurations. Among them debug and non-debug versions.
2.2 Visual Studio - NMake

C:\path_to_mysql_cpp>nmake
 
Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.
 
Scanning dependencies of target mysqlcppconn
[  2%] Building CXX object driver/CMakeFiles/mysqlcppconn.dir/mysql_connection.obj
mysql_connection.cpp
[...]
Linking CXX executable statement.exe
[100%] Built target statement


[edit] Platform Notes on Building

All distributions contain a README file. At the end of the README file contained in a binary distribution you will find the settings used to build the binaries.
If you experience build issues on a platform, it may help to check the settings we use on the platform to build the binary by downloading the binary package.
We have summarized further details at the wiki page Connector C++ Binary Builds.

[edit] Getting Started: Usage Examples

The download package contains usage examples in the directory examples/. The examples explain the basic usage of the following classes:
  • Connection
  • DatabaseMetaData
  • Driver
  • PreparedStatement
  • ResultSet
  • ResultSetMetaData
  • Statement
The examples cover:
  • Using the Driver class to connect to MySQL
  • Creating tables, inserting rows, fetching rows using (simple) statements
  • Creating tables, inserting rows, fetching rows using prepared statements
  • Hints for working around prepared statement limitations
  • Accessing result set meta data
  • Accessing database meta data
The examples on this wiki page are only code snippets. The code snippets provide a brief overview on the API. They are not complete programs. Please check the examples/ directory for complete programs.
The examples will be compiled as part of a normal build (e.g. during make). 

Part1- How to install mysql-connector-c++ in Windows | Mac | SunOS | RHEL-Red Hat/Fedora Linux?

,

Introduction

MySQL Connector/C++ is a MySQL database connector for C++.
The MySQL Connector/C++ is licensed under the terms of the GPL, like most MySQL Connectors. There are special exceptions to the terms and conditions of the GPL as it is applied to this software, see FLOSS License Exception. If you need a non-GPL license for commercial distribution please contact us

The MySQL Driver for C++ mimics the JDBC 4.0 API. However, Connector/C++ does not implement all of the JDBC 4.0 API. The Connector/C++ 1,0.5 GA release features the following classes:
  • Connection
  • DatabaseMetaData
  • Driver
  • PreparedStatement
  • ResultSet
  • ResultSetMetaData
  • Savepoint
  • Statement
The MySQL Connector/C++ implements a significant subset of JDBC 4.0. The JDBC API defines some 450 methods for the above mentioned classes. About 375 (= 80%) of them are implemented and available with the alpha release.
In total you will find about 570 being declared in Connector/C++ and approximately 460 of them being implemented, please check the simplified implementation statistics (1.0.3alpha, 1.0.2alpha for details. Please note, we remove method stubs from releases and you will find only fully implemented methods in a release.
The Driver for C++ can be used to connect to MySQL 5.1 or later. Note - its full functionality is not available when connecting to MySQL 5.0. You cannot connect to MySQL 4.1 or earlier.

 Download

You can download the MySQL Connector/C++ at http://dev.mysql.com/downloads/connector/cpp/1.0.html
As of 1.0.4beta we offer both binary and source packages. Available binary packages:
  • Windows
    • Without Installer (zip)
    • MSI Installer
  • Other
    • Compressed GNU TAR archive (tar.gz)
Available source packages:
  • All Platforms
    • Compressed GNU TAR archive (tar.gz)


Source repository

The latest development version is also available through Launchpad at https://launchpad.net/mysql-connector-cpp .
Bazaar is used for the MySQL Connector/C++ code repository. You can check out the source using the bzr command line tool (current development branch):

bzr branch lp:~mysql/mysql-connector-cpp/trunk



Supported Platforms

The beta release has been successfully compiled and tested on the following platforms:
  • AIX
    • 5.3 (PPC32, PPC64)o
  • FreeBSD
    • 6.0 (x86, x86_64)!
    • 7.0 (x86, x86_64)o
  • HPUX
    • 11.11 (PA-RISC 32bit, PA-RISC 64bit)*
    • 11.23 (iA64)o
    • 11.31 (PA-RISC 32bit, PA-RISC 64bit)*
    • 11.31 (iA64)o
  • IBM i5/OS
    • i5/OS (POWER, 32-bit, POWER, 64-bit)!
  • Linux
    • FC4 (x86)
    • RHEL 3 (ia64, x86, x86_64)!
    • RHEL 4 (ia64, x86, x86_64)o
    • RHEL 5 (ia64*, x86, x86_64)o
    • SLES 9 (ia64, x86, x86_64)o
    • SLES 10 (ia64, x86_64)o
    • SuSE 11.0, (x86_64)
    • Ubuntu 8.04 (x86)
    • Ubuntu 8.10 (x86_64)
  • Mac
    • MacOSX 10.4 (PPC32*, PPC64*, x86)
    • MacOSX 10.5 (PPC32*, PPC64*, x86, x86_64)
    • MacOSX 10.6 (x86, x86_64)
  • SunOS
    • Solaris 8 (SPARC32, SPARC64, x86)
    • Solaris 9 (SPARC32, SPARC64, x86)
    • Solaris 10 (SPARC32, SPARC64, x86, x86_64)
    • Solaris 11 (x86, x86_64)*
    • OpenSolaris 2008.11 (x86)
  • Windows
    • XP Professional (32bit)
    • 2003 (64bit)
An asterix after the platform means that the latest version of the MySQL Enterprise Server may no longer or not yet be supported on that platform but we know, however, that one can build Connector/C++ on that platform.
Future versions aim to support as many of the platforms for which commercial support is available for the latest GA version of the MySQL Server as possible. Please check the support policies at http://www.mysql.com/support/supportedplatforms/enterprise.html for details.
For sales related questions, for example on support or commercial licenses, please write to <sales@mysql.com>.

Advantages

Using MySQL Connector/C++ instead of the MySQL C API (MySQL Client Library) offers the following advantages for C++ users:
  • Convenience of pure C++ - no C function calls
  • Support of a well designed API - JDBC 4.0
  • Support of a commonly known and well documented API - JDBC 4.0
  • Support of the object oriented programming paradigma
  • Shorter development times

Status

MySQL Connector/C++ is available as production version. We kindly ask users and developers to try it out and provide us with feedback.
MySQL Workbench is using a pre-alpha code snapshot for its internal development version. The same is true for the MySQL Connector/OpenOffice.org.

[edit] Binary Installation

Unpack the archive into an appropriate directory.
If you plan to use a dynamically linked version of MySQL Connector/C++, make sure that your system can find the MySQL client library. Consult your operating system documentation on how do modify and expand the search patch for libraries. In case you cannot modify the library search path it may help to copy your application, the MySQL Connector/C++ library and the MySQL client library into the same directory. Most systems search for libraries in the current directory.
Please read also Connector C++ Binary Builds for notes on binary portability.

[edit] CAUTION: binary compatibility on Windows

The Visual Studio builds of Connector/C++ must not be used with any other CRT (C Run-Time Library, provided by Windows/Visual Studio) but the ones listed at Connector C++ Binary Builds . Using any other CRT with your C++ client application than what we used to build the Connector/C++ binary may cause issues. The Microsoft Visual Studio documentation points out the [potential errors passing CRT objects across DLL boundaries http://msdn.microsoft.com/en-us/library/ms235460.aspx]. Furthermore, your C++ client application must use the same compiler settings for /MD (dynamic linking of CRT), /MDd (dynamic linking of CRT with debug), /MT (static linking of CRT) and /MTd (static linking of CRT with debug). The settings used for building Connector/C++ binaries are documented at the wiki page Connector C++ Binary Builds.
The major version of the compiler used to build the Connector/C++ driver library must match the version of the compiler used to build your C++ client application that is using Connector/C++. For example, you must not use Visual Studio 2008 to link your C++ client application against a Connector/C++ driver library that was build with Visual Studio 2005.
For those combinations of compiler version, target CRT version and your target compiler settings (/MD, /MDd, /MT, /MTd) for which we do not provide a binary download, you have to build Connector/C++ from source.

[edit] Windows MSI Installer

Windows users can choose between two binary packages: without installer (unzip in C:\) and Windows MSI Installer (x86).
Using the MSI Installer may be more comfortable. Running the MSI Installer does not require any administrative permissions because all it does is to copy files.
Image:Conn cpp installer welcome.png
Image:Conn cpp installer installation overview.png
The "Typical" installation consists of all required header files and the Release libraries. The only available "Custom" installation option allows you to install additional Debug versions of the driver libraries. 
Image:Conn_cpp_installer_custom_setup.png 



















Click here For Part 2 | Part 3

Deal of the Day

Advertisement here

Advertisement here