Category: Code . Programming Samples . প্রোগ্রাম উদাহরন

Code . Programming Samples . প্রোগ্রাম উদাহরন

Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference

Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference. The dialog returns a Color object based on the user’s selection or null if the user entered Cancel. import java.awt.*; import java.awt.event.*; import javax.swing.*; /** Simple example illustrating the use of …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/demonstrates-the-use-of-a-jcolorchooser-which-presents-a-dialog-with-three-different-tabbed-panes-to-allow-the-user-to-select-a-color-preference/

WebClient – Client application that can talk interactively to Web servers. Requires the components listed below

import java.awt.*; // For BorderLayout, GridLayout, Font, Color. import java.awt.event.*; import java.util.*; import javax.swing.*; /** A graphical client that lets you interactively connect to  *  Web servers and send custom request lines and  *  request headers.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/webclient-client-application-that-can-talk-interactively-to-web-servers-requires-the-components-listed-below/

EchoServer.java A simple HTTP server that creates a Web page showing all data sent from the client (browser), including all HTTP request headers sent form the client. Uses the following classes

EchoServer.java  A simple HTTP server that creates a Web page showing all data sent from the client (browser), including all HTTP request headers sent form the client. Uses the following classes:   import java.net.*; import java.io.*; import java.util.StringTokenizer; /** A simple HTTP server that generates a Web page showing all  *  of the data that …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/echoserver-java-a-simple-http-server-that-creates-a-web-page-showing-all-data-sent-from-the-client-browser-including-all-http-request-headers-sent-form-the-client-uses-the-following-classes/

StoppableThread.java A template to place a thread in a RUN, WAIT, or STOP state.

/** A template to control the state of a thread through setting  *  an internal flag. public class StoppableThread extends Thread {    public static final int STOP    = 0;    public static final int RUN     = 1;    public static final int WAIT    = 2;    private int state = RUN;   /** Public …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/stoppablethread-java-a-template-to-place-a-thread-in-a-run-wait-or-stop-state/

mall example showing the basic use of a JToolBar

mall example showing the basic use of a JToolBar import java.awt.*; import javax.swing.*; import java.awt.event.*; /** Small example showing basic use of JToolBar.  *  *  */ public class JToolBarExample extends JFrame                              implements ItemListener {   private BrowserToolBar toolbar;   private JCheckBox labelBox;   public static void main(String[] args) {     new JToolBarExample();   } …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/mall-example-showing-the-basic-use-of-a-jtoolbar/

UrlRetriever2.java Illustrates how the URL class can simplify communication to an HTTP server.

UrlRetriever2.java  Illustrates how the URL class can simplify communication to an HTTP server. import java.net.*; import java.io.*; /** Read a remote file using the standard URL class  *  instead of connecting explicitly to the HTTP server.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/urlretriever2-java-illustrates-how-the-url-class-can-simplify-communication-to-an-http-server/

RMI Example – Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes

Rem.java  Establishes which methods the client can access in the remote object. import java.rmi.*; /** The RMI client will use this interface directly. The RMI  *  server will make a real remote object that implements this,  *  then register an instance of it with some URL.  *  *  Taken from Core Web Programming from  *  …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/rmi-example-message-illustrates-retrieving-a-message-from-an-object-located-on-a-remote-server-requires-the-following-classes/

Creates three common types of sliders

Creates three common types of sliders: one without tick marks, one with tick marks, and one with both tick marks and labels. import java.awt.*; import javax.swing.*; /** Simple example illustrating the use of JSliders, especially  *  the ability to specify tick marks and labels.  *  *     */ public class JSliders extends JFrame {   …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/creates-three-common-types-of-sliders/

Basic Swing Details

WindowUtilities.java Utility class that simplifies creating a window and setting the look and feel. ExitListener.java A WindowListener with support to close the window. JAppletExample.java A simple applet (JApplet) created in Swing. Illustrates setting the look and feel, adding components to the content pane, and changing the layout to FlowLayout (default is BorderLayout). See JAppletExample.html (requires …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/basic-swing-details/

UrlRetriever.java Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes

UrlRetriever.java  Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes: import java.util.*; /** This parses the input to get a host, port, and file, then  *  passes these three values to the UriRetriever class to  *  grab the …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/urlretriever-java-accepts-an-url-from-the-command-line-parses-the-host-port-and-uri-components-from-the-url-and-then-retrieves-the-document-requires-the-following-classes/

AddressVerifier.java Connects to an SMTP server and issues a expn request to display details about a mailbox on the server. Uses the following classes

import java.net.*; import java.io.*; /** Given an e-mail address of the form user@host,  *  connect to port 25 of the host and issue an  *  ‘expn’ request for the user. Print the results.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © 2001 Marty Hall …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/addressverifier-java-connects-to-an-smtp-server-and-issues-a-expn-request-to-display-details-about-a-mailbox-on-the-server-uses-the-following-classes/

Buggy Counter Applet.java Demonstrates that data shared by multiple threads is candidate for a potential race condition

import java.applet.Applet; import java.awt.*; /** Emulates the Counter and Counter2 classes, but this time  *  from an applet that invokes multiple versions of its own run  *  method. This version is likely to work correctly  *  except when  an important customer is visiting. public class BuggyCounterApplet extends Applet                                 implements Runnable{   private int totalNum …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/buggy-counter-applet-java-demonstrates-that-data-shared-by-multiple-threads-is-candidate-for-a-potential-race-condition/

SplitTest.java Illustrates parsing a string with a String.split

SplitTest.java Illustrates parsing a string with a String.split /** Prints the tokens resulting from treating the first * command-line argument as the string to be tokenized * and the second as the delimiter set. Uses * String.split instead of StringTokenizer. */ public class SplitTest { public static void main(String[] args) { if (args.length == 2) …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/splittest-java-illustrates-parsing-a-string-with-a-string-split/

TokTest.java Illustrates parsing a string with a StringTokenizer.

TokTest.java  Illustrates parsing a string with a StringTokenizer. import java.util.StringTokenizer; /** Prints the tokens resulting from treating the first  *  command-line argument as the string to be tokenized  *  and the second as the delimiter set.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/toktest-java-illustrates-parsing-a-string-with-a-stringtokenizer/

NetworkClientTest.java Makes a simple connection to the host and port specified on the command line. Uses the following classes

NetworkClientTest.java  Makes a simple connection to the host and port specified on the command line. Uses the following classes: /** Make simple connection to host and port specified.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © 2001 Marty Hall and Larry Brown;  *  may …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/networkclienttest-java-makes-a-simple-connection-to-the-host-and-port-specified-on-the-command-line-uses-the-following-classes/

ShowSession.java Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output.

ShowSession.java Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.util.*; /** Simple example of session tracking. * * Taken from Core Web Programming Java 2 Edition * …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/showsession-java-servlet-that-uses-session-tracking-to-determine-if-the-client-is-a-repeat-visitor-uses-the-servletutilities-class-to-simplify-the-doctype-and-head-output/

LongLivedCookie.java Subclass of Cookie that automatically sets the max age to one year.

LongLivedCookie.java  Subclass of Cookie that automatically sets the max age to one year. package cwp; import javax.servlet.http.*; /** Cookie that persists 1 year. Default Cookie doesn’t  *  persist past current session.  *    *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and Sun Microsystems Press,  *  .  *  May be …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/longlivedcookie-java-subclass-of-cookie-that-automatically-sets-the-max-age-to-one-year/

ShowCookies.java Servlet that displays all cookies that arrived in current request. Uses the ServletUtilities class.

ShowCookies.java Servlet that displays all cookies that arrived in current request. Uses the ServletUtilities class. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Sets six cookies: three that apply only to the current * session (regardless of how long that session lasts) * and three that persist for an hour (regardless of * whether …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/showcookies-java-servlet-that-displays-all-cookies-that-arrived-in-current-request-uses-the-servletutilities-class/

SearchEngines.java Servlet that redirects requests to various search engines. Uses the SearchSpec helper class. Accessed by means of SearchEngines.html.

SearchEngines.java  Servlet that redirects requests to various search engines. Uses the SearchSpec  helper class. Accessed by means of SearchEngines.html. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; /** Servlet that takes a search string, number of results per  *  page, and a search engine name, sending the query to  *  that search engine. …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/searchengines-java-servlet-that-redirects-requests-to-various-search-engines-uses-the-searchspec-helper-class-accessed-by-means-of-searchengines-html/

SetCookies.java Servlet that sets a few persistent and session cookies. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output.

SetCookies.java  Servlet that sets a few persistent and session cookies. Uses the ServletUtilities  class to simplify the DOCTYPE and HEAD output.   package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Sets six cookies: three that apply only to the current  *  session (regardless of how long that session lasts)  *  and three that persist …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/setcookies-java-servlet-that-sets-a-few-persistent-and-session-cookies-uses-the-servletutilities-class-to-simplify-the-doctype-and-head-output/

EncodedPage.java Servlet that shows the bandwidth benefits of gzipping pages to browsers that can handle gzip. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output.

EncodedPage.java  Servlet that shows the bandwidth benefits of gzipping pages to browsers that can handle gzip. Uses the ServletUtilities  class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.zip.*; /** Example showing benefits of gzipping pages to browsers  *  that can handle gzip.  *    *  Taken …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/encodedpage-java-servlet-that-shows-the-bandwidth-benefits-of-gzipping-pages-to-browsers-that-can-handle-gzip-uses-the-servletutilities-class-to-simplify-the-doctype-and-head-output/

PrimeNumbers.java Servlet that processes a request to generate n prime numbers, each with at least m digits. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. Uses the Primes

PrimeNumbers.java  Servlet that processes a request to generate n prime numbers, each with at least m digits. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. Uses the Primes, PrimeList, and ServletUtilities  classes.   package cwp; import java.io.*; import javax.servlet.*; import …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/primenumbers-java-servlet-that-processes-a-request-to-generate-n-prime-numbers-each-with-at-least-m-digits-if-these-results-are-not-complete-it-sends-a-refresh-header-instructing-the-browser-to-ask/

ShowRequestHeaders.java Servlet that shows all request headers sent by browser in current request.

ShowRequestHeaders.java Servlet that shows all request headers sent by browser in current request. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; /** Shows all the request headers sent on this request. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * May …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/showrequestheaders-java-servlet-that-shows-all-request-headers-sent-by-browser-in-current-request/

ServletUtilities.java Utility class that, among other things, contains the static filter method that replaces special HTML characters with their HTML character entities.

ServletUtilities.java  Utility class that, among other things, contains the static filter  method that replaces special HTML characters with their HTML character entities. package cwp; import javax.servlet.*; import javax.servlet.http.*; /** Some simple time savers. Note that most are static methods.  *    *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/servletutilities-java-utility-class-that-among-other-things-contains-the-static-filter-method-that-replaces-special-html-characters-with-their-html-character-entities/

ThreeParams.java Servlet that reads and displays three request (form) parameters. Uses the ServletUtilities class.

ThreeParams.java  Servlet that reads and displays three request (form) parameters. Uses the ServletUtilities  class. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Simple servlet that reads three parameters from the  *  form data.  *    *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and Sun Microsystems Press,  *  . …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/threeparams-java-servlet-that-reads-and-displays-three-request-form-parameters-uses-the-servletutilities-class/

ShowMessage.java Servlet that demonstrates the use of initialization parameters.

ShowMessage.java  Servlet that demonstrates the use of initialization parameters. Remember that, to use this servlet, you have to do three things:     * Put the modified web.xml file in the WEB-INF directory.     * Restart the server.     * Use the registered servlet name (i.e., the URL http://host/servlet/ShowMsg), not the raw servlet name (i.e., the …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/showmessage-java-servlet-that-demonstrates-the-use-of-initialization-parameters/

ServletUtilities.java Utility class that simplifies the output of the DOCTYPE and HEAD in servlets, among other things. Used by most remaining servlets in the chapter.

ServletUtilities.java  Utility class that simplifies the output of the DOCTYPE and HEAD  in servlets, among other things. Used by most remaining servlets in the chapter. package cwp; import javax.servlet.*; import javax.servlet.http.*; /** Some simple time savers. Note that most are static methods.  *    *  Taken from Core Web Programming Java 2 Edition  *  from …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/servletutilities-java-utility-class-that-simplifies-the-output-of-the-doctype-and-head-in-servlets-among-other-things-used-by-most-remaining-servlets-in-the-chapter/

SimplerHelloWWW.java Servlet that uses ServletUtilities to simplify the generation of the DOCTYPE and HEAD part of the servlet.

SimplerHelloWWW.java  Servlet that uses ServletUtilities  to simplify the generation of the DOCTYPE and HEAD part of the servlet. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Simple servlet that generates HTML. This variation of  *  HelloWWW uses the ServletUtilities utility class  *  to generate the DOCTYPE, HEAD, and TITLE.  *    *  Taken from …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/simplerhellowww-java-servlet-that-uses-servletutilities-to-simplify-the-generation-of-the-doctype-and-head-part-of-the-servlet/

HelloWWW.java Servlet that generates HTML. This and all remaining servlets are in the cwp package and therefore should be installed in the cwp subdirectory.

HelloWWW.java  Servlet that generates HTML. This and all remaining servlets are in the cwp package and therefore should be installed in the cwp subdirectory. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Simple servlet that generates HTML.  *    *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and Sun …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/hellowww-java-servlet-that-generates-html-this-and-all-remaining-servlets-are-in-the-cwp-package-and-therefore-should-be-installed-in-the-cwp-subdirectory/

HelloWorld.java Simple servlet that generates plain text.

HelloWorld.java  Simple servlet that generates plain text. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Very simplistic servlet that generates plain text.  *    *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and Sun Microsystems Press,  *  .  *  May be freely used or adapted.  */ public class HelloWorld extends HttpServlet …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/helloworld-java-simple-servlet-that-generates-plain-text/

ServletTemplate.java Starting point for servlets.

ServletTemplate.java Starting point for servlets. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Servlet template.  *    *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and Sun Microsystems Press,  *  .  *  May be freely used or adapted.  */ public class ServletTemplate extends HttpServlet {   public void doGet(HttpServletRequest request,                     …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/servlettemplate-java-starting-point-for-servlets/

StringBean.java Bean used to demonstrate jsp:useBean, etc. Remember to install it in the WEB-INF/classes/cwp directory.

StringBean.java  Bean used to demonstrate jsp:useBean, etc. Remember to install it in the WEB-INF/classes/cwp directory. package cwp; /** A simple bean that has a single String property  *  called message.  *  <P>  *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and Sun Microsystems Press,  *  .  *  May be freely …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/stringbean-java-bean-used-to-demonstrate-jspusebean-etc-remember-to-install-it-in-the-web-infclassescwp-directory/

PluginApplet.jsp Page that demonstrates the use of jsp:plugin.

PluginApplet.jsp  Page that demonstrates the use of jsp:plugin. Requires you to compile and install PluginApplet.java, TextPanel.java, DrawingPanel.java, and WindowUtilities.java  Since these are classes sent to the client to used by applets, the .class files should be in the same directory as the JSP page, not in the WEB-INF/classes directory where classes the server uses go. …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/pluginapplet-jsp-page-that-demonstrates-the-use-of-jspplugin/

BGColor.jsp Page that demonstrates JSP scriptlets. Uses the JSP-Styles style sheet.

BGColor.jsp  Page that demonstrates JSP scriptlets. Uses the JSP-Styles  style sheet. <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!–     Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. –> <HTML> <HEAD>   <TITLE>Color Testing</TITLE> </HEAD> <% String bgColor = request.getParameter(“bgColor”); boolean …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/bgcolor-jsp-page-that-demonstrates-jsp-scriptlets-uses-the-jsp-styles-style-sheet/

Excel.jsp Page that demonstrates the use of JSP to build Excel spreadsheets

Excel.jsp  Page that demonstrates the use of JSP to build Excel spreadsheets First    Last    Email Address Marty    Hall    hall@corewebprogramming.com Larry    Brown    brown@corewebprogramming.com Bill    Gates    gates@sun.com Larry    Ellison    ellison@microsoft.com <%@ page contentType=”application/vnd.ms-excel” %> <%– There are tabs, not spaces, between columns. –%>

Permanent link to this article: http://bangla.sitestree.com/excel-jsp-page-that-demonstrates-the-use-of-jsp-to-build-excel-spreadsheets/

Expressions.jsp Page that demonstrates JSP expressions. Uses the JSP-Styles style sheet.

Expressions.jsp  Page that demonstrates JSP expressions. Uses the JSP-Styles  style sheet. <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Example of JSP Expressions.     Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. –> <HTML> <HEAD> <TITLE>JSP Expressions</TITLE> <META NAME=”keywords”       …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/expressions-jsp-page-that-demonstrates-jsp-expressions-uses-the-jsp-styles-style-sheet-2/

ImportAttribute.jsp Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class

ImportAttribute.jsp  Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class (Check Servlet Section) <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Example of the import attribute of the page directive. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/importattribute-jsp-page-that-demonstrates-the-import-attribute-of-the-page-directive-uses-the-servletutilities-class/

QueryViewer.java: An interactive database query viewer

# QueryViewer.java  An interactive database query viewer. Connects to the specified Oracle or Sybase database, executes a query, and presents the results in a JTable. Uses the following file:     * DBResultsTableModel.java Simple class that tells a JTable how to extract relevant data from a DBResults object (which is used to store the results from …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/queryviewer-java-an-interactive-database-query-viewer/

AccessCounts.jsp Page that demonstrates JSP declarations.

AccessCounts.jsp  Page that demonstrates JSP declarations. <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!–    Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. –> <HTML> <HEAD> <TITLE>JSP Declarations</TITLE> <META NAME=”keywords”       CONTENT=”JSP,declarations,JavaServer,Pages,servlets”> <META NAME=”description”       CONTENT=”A quick example of JSP declarations.”> …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/accesscounts-jsp-page-that-demonstrates-jsp-declarations/

PreparedStatements.java An example to test the timing differences resulting from repeated raw queries vs. repeated calls

package cwp; import java.sql.*; /** An example to test the timing differences resulting  *  from repeated raw queries vs. repeated calls to  *  prepared statements. These results will vary dramatically  *  among database servers and drivers. With my setup  *  and drivers, Oracle prepared statements took only half  *  the time that raw queries required …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/preparedstatements-java-an-example-to-test-the-timing-differences-resulting-from-repeated-raw-queries-vs-repeated-calls/

EmployeeCreation.java: Make a simple “employees” table using the database utilities

package cwp; import java.sql.*; /** Make a simple “employees” table using DatabaseUtilities.  */ public class EmployeeCreation {   public static Connection createEmployees(String driver,                                            String url,                                            String username,                                            String password,                                            boolean close) {     String format =       “(id int, firstname varchar(32), lastname varchar(32), ” +       “language varchar(16), salary float)”;     …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/employeecreation-java-make-a-simple-employees-table-using-the-database-utilities/

extract relevant data from a DBResults

# QueryViewer.java  An interactive database query viewer. Connects to the specified Oracle or Sybase database, executes a query, and presents the results in a JTable. Uses the following file:     * DBResultsTableModel.java Simple class that tells a JTable how to extract relevant data from a DBResults object (which is used to store the results from …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/extract-relevant-data-from-a-dbresults/

EmployeeTest2.java: A test case for the database utilities. Prints results formatted as an HTML table.

package cwp; import java.sql.*; /** Connect to Oracle or Sybase and print “employees” table  *  as an HTML table.  *    */ public class EmployeeTest2 {   public static void main(String[] args) {     if (args.length < 5) {       printUsage();       return;     }     String vendorName = args[4];     int vendor = DriverUtilities.getVendor(vendorName); …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/employeetest2-java-a-test-case-for-the-database-utilities-prints-results-formatted-as-an-html-table/

DBResults.java: Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways

# DBResults.java  Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways:     * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows.     * This class stores results as strings, in arrays.     * This class includes DatabaseMetaData (database product …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/dbresults-java-class-to-store-completed-results-of-a-jdbc-query-differs-from-a-resultset-in-several-ways/

DatabaseUtilities.java: Several general-purpose utilities discussed and used in the chapter.

package cwp; import java.sql.*; /** Three database utilities:  *   1) getQueryResults. Connects to a database, executes  *      a query, retrieves all the rows as arrays  *      of strings, and puts them inside a DBResults  *      object. Also places the database product name,  *      database version, and the names of all the columns  *      into the …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/databaseutilities-java-several-general-purpose-utilities-discussed-and-used-in-the-chapter/

EmployeeTest.java: A test case for the database utilities. Prints results in plain text.

package cwp; import java.sql.*; /** Connect to Oracle or Sybase and print “employees” table.  *    */ public class EmployeeTest {   public static void main(String[] args) {     if (args.length < 5) {       printUsage();       return;     }     String vendorName = args[4];     int vendor = DriverUtilities.getVendor(vendorName);     if (vendor == DriverUtilities.UNKNOWN) …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/employeetest-java-a-test-case-for-the-database-utilities-prints-results-in-plain-text/

Example Java Programs

HelloWorld.java public class HelloWorld {     // method main(): ALWAYS the APPLICATION entry point     public static void main (String[] args) {     System.out.println (“Hello World!”);     } } // Print Today’s Date import java.util.*; public class HelloDate {     public static void main (String[] args) {     System.out.println (“Hello, it’s: “);     System.out.println(new Date()); …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/example-java-programs/

FruitCreation.java: Creates a simple table named fruits in either an Oracle or a Sybase database.

FruitCreation.java Creates a simple table named fruits in either an Oracle or a Sybase database. package cwp; import java.sql.*; /** Creates a simple table named “fruits” in either  *  an Oracle or a Sybase database.  *    */ public class FruitCreation {   public static void main(String[] args) {     if (args.length < 5) { …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/fruitcreation-java-creates-a-simple-table-named-fruits-in-either-an-oracle-or-a-sybase-database/

Example illustrating inheritance and abstract classes

illustrating inheritance এবং abstract classes এর উদাহরণ Shape.java সব, বদ্ধ খোলা, বাঁকা, এবং সোজা পার্শ্বে ধারবিশিষ্ট আকার এর জন্য প্যারেন্ট ক্লাস (সারাংশ)। Curve.java একটি (সারাংশ) বাঁকা আকার (খোলা বা বন্ধ)। StraightEdgedShape.java সরাসরি ধার সম্বলিত একটি আকৃতি (খোলা বা বন্ধ)। Measurable.java পরিমাপযোগ্য এলাকায় ইন্টারফেস ডিফাইনিং ক্লাস। Circle.java একটি বৃত্ত যা আকার প্রসারিত করে এবং পরিমাপ প্রয়োগ …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/example-illustrating-inheritance-and-abstract-classes/

Some simple utilities for building Oracle and Sybase JDBC connections

এই সাধারণ উদ্দেশ্যে তৈরিকৃত কোড নয় – এটা আমাদের লোকাল সেটআপ এর ক্ষেত্রে প্রযোজ্য।     package cwp; /** Some simple utilities for building Oracle and Sybase  *  JDBC connections. This is not general-purpose  *  code — it is specific to my local setup.  */ public class DriverUtilities {   public static final int ORACLE = …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/some-simple-utilities-for-building-oracle-and-sybase-jdbc-connections/

FruitTest.java: A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the “fruits” table.

# FruitTest.java  A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the “fruits” table. package cwp; import java.sql.*; /** A JDBC example that connects to either an Oracle or  *  a Sybase database and prints out the values of  *  predetermined columns in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/fruittest-java-a-class-that-connects-to-either-an-oracle-or-a-sybase-database-and-prints-out-the-values-of-predetermined-columns-in-the-fruits-table/

ContactSection.jsp A snippet of a JSP page. It defines a field (accessCount), so pages that include it and want to directly utilize that field must use the include directive, not jsp:include.

ContactSection.jsp হচ্ছে JSP পৃষ্ঠার একটি অংশ।এটি একটি ফিল্ডকে সঙ্গায়িত করে (accessCount), সুতরাং যে পৃষ্ঠায় এটি অন্তর্ভুক্ত থাকে এবং সরাসরি উক্ত ফিল্ড ব্যবহার করাতে চায় তাকে আবশ্যই include directive ব্যবহার করতে হবে, jsp:include নয়।. <%@ page import=”java.util.Date” %> <%– The following become fields in each servlet that      results from a JSP page that includes this file. –%> <%! …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/contactsection-jsp-a-snippet-of-a-jsp-page-it-defines-a-field-accesscount-so-pages-that-include-it-and-want-to-directly-utilize-that-field-must-use-the-include-directive-not-jspinclude/

J2SE : LinkedList and Iterators in Java

/*  * LinkedList.java  *  * Created on January 10, 2008, 8:51 PM  *  * To change this template, choose Tools | Template Manager  * and open the template in the editor.  */ package linkedlist; import java.util.List; import java.util.LinkedList; import java.util.Iterator; import java.util.ListIterator; import java.util.Collections; import java.util.Random; /**  *  * @author Sayed  */ public class LinkedListTest …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/j2se-linkedlist-and-iterators-in-java/

Use sorting criterion in sort function

/* The following code example is taken from the book  * “The C++ Standard Library – A Tutorial and Reference”  * by Nicolai M. Josuttis, Addison-Wesley, 1999  *  * (C) Copyright Nicolai M. Josuttis 1999.  * Permission to copy, use, modify, sell and distribute this software  * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/use-sorting-criterion-in-sort-function/

Sort objects stored in deque

/* The following code example is taken from the book  * “The C++ Standard Library – A Tutorial and Reference”  * by Nicolai M. Josuttis, Addison-Wesley, 1999  *  * (C) Copyright Nicolai M. Josuttis 1999.  * Permission to copy, use, modify, sell and distribute this software  * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/sort-objects-stored-in-deque/

Expressions.jsp Page that demonstrates JSP expressions. Uses the JSP-Styles style sheet.

Expressions.jsp  Page that demonstrates JSP expressions. Uses the JSP-Styles  style sheet. <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Example of JSP Expressions.     Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. –> <HTML> <HEAD> <TITLE>JSP Expressions</TITLE> <META NAME=”keywords”       …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/expressions-jsp-page-that-demonstrates-jsp-expressions-uses-the-jsp-styles-style-sheet/

A simple C++ Program code

#include <iostream> #include <fstream> using namespace std; int main() {   ifstream in(“test”, ios::in | ios::binary);   if(!in) {     cout << “Cannot open input file.\n”;     return 1;   }   double num;   char str[80];   in.read((char *) &num, sizeof(double));   in.read(str, 14);   str[14] = ‘\0’; // null terminate str   cout …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/a-simple-c-program-code/

valarray with double value inside

/* The following code example is taken from the book  * “The C++ Standard Library – A Tutorial and Reference”  * by Nicolai M. Josuttis, Addison-Wesley, 1999  *  * (C) Copyright Nicolai M. Josuttis 1999.  * Permission to copy, use, modify, sell and distribute this software  * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/valarray-with-double-value-inside/

Print minimum, maximum, and sum of the valarray

/* The following code example is taken from the book * “The C++ Standard Library – A Tutorial and Reference” * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/print-minimum-maximum-and-sum-of-the-valarray/

valarray slice

/* The following code example is taken from the book * “The C++ Standard Library – A Tutorial and Reference” * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/valarray-slice/

Call member function for each element in vector

/* The following code example is taken from the book * “The C++ Standard Library – A Tutorial and Reference” * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/%e0%a6%ad%e0%a7%87%e0%a6%95%e0%a7%8d%e0%a6%9f%e0%a6%b0-%e0%a6%8f%e0%a6%b2%e0%a6%bf%e0%a6%ae%e0%a7%87%e0%a6%a8%e0%a7%8d%e0%a6%9f-%e0%a6%8f%e0%a6%b0-%e0%a6%b8%e0%a7%87%e0%a6%b2-%e0%a6%a8%e0%a6%be/

Use bitset with enum together

/* The following code example is taken from the book  * “The C++ Standard Library – A Tutorial and Reference”  * by Nicolai M. Josuttis, Addison-Wesley, 1999  *  * (C) Copyright Nicolai M. Josuttis 1999.  * Permission to copy, use, modify, sell and distribute this software  * is granted provided this copyright notice appears in all copies.  * This software is provided “as is” without express or implied  * warranty, and with no claim as to its suitability for any purpose.  */ #include <bitset> #include <iostream> using namespace std; int main() {     /* enumeration type for the bits      * – each bit represents a color      */     enum Color { red, yellow, green, blue, white, black, //…,                  numColors };     // create bitset for all bits/colors     bitset<numColors> usedColors;     // set bits for two colors     usedColors.set(red);     usedColors.set(blue);     // print some bitset data     cout << “bitfield of used colors:   ” << usedColors          << endl;     cout << “number   of used colors:   ” << usedColors.count()          << endl;     cout << “bitfield of unused colors: ” << ~usedColors          << endl;     // if any color is used     if (usedColors.any()) {         // loop over all colors         for (int c = 0; c < numColors; ++c) {             // if the actual color is used             if (usedColors[(Color)c]) {                 //…             }         }     } } /*  bitfield of used colors:   001001 number   of used colors:   2 bitfield of unused colors: 110110  */

Permanent link to this article: http://bangla.sitestree.com/use-bitset-with-enum-together/

Transform binary representation into integral number using bitset

/* The following code example is taken from the book  * “The C++ Standard Library – A Tutorial and Reference”  * by Nicolai M. Josuttis, Addison-Wesley, 1999  *  * (C) Copyright Nicolai M. Josuttis 1999.  * Permission to copy, use, modify, sell and distribute this software  * is granted provided this copyright notice appears in all copies.  * This software is provided “as is” without express or implied  * warranty, and with no claim as to its suitability for any purpose.  */ #include <bitset> #include <iostream> #include <string> #include <limits> using namespace std; int main() {     /* print some numbers in binary representation      */     cout << “267 as binary short:     ”          << bitset<numeric_limits<unsigned short>::digits>(267)          << endl;     cout << “267 as binary long:      ”          << bitset<numeric_limits<unsigned long>::digits>(267)          << endl;     cout << “10,000,000 with 24 bits: ”          << bitset<24>(1e7) << endl;     /* transform binary representation into integral number      */     cout << “\”1000101011\” as number:  ”          << bitset<100>(string(“1000101011″)).to_ulong() << endl; }  /*  267 as binary short:     0000000100001011 267 as binary long:      00000000000000000000000100001011 10,000,000 with 24 bits: 100110001001011010000000 1000101011” as number:  555  */           // create a bitset that is 8 bits long bitset<8> bs; // display that bitset for( …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/transform-binary-representation-into-integral-number-using-bitset/

A simple applet that uses the ClickListener class

ClickReporter.java A simple applet that uses the ClickListener class to handle mouse events. *************** import java.applet.Applet; import java.awt.*; /** Prints a message saying where the user clicks.  *  Uses an external listener.  *    ****** public class ClickReporter extends Applet {   public void init() {     setBackground(Color.yellow);     addMouseListener(new ClickListener());   } }

Permanent link to this article: http://bangla.sitestree.com/a-simple-applet-that-uses-the-clicklistener-class/

Load more