Please Help Me on Class.newInsatnce

dear Sir what is the use of Class.newInsatnce. When do we use this.
Thanks

Hi,
You use it when you dynamically want to create a new instance. Lets say you have an applictaion that is >> modular, and which can be configured to load plugins when it starts. The name of a plugin would be >> written as the name of the class file that implements the plugin, and the appliction would instantiate >> plugins when it has started.Just to add a little more to what /Kaj has already mentioned. You get the instance of Class by doing the following -
private Object getNewInstance(String strClassName) throws Exception {
  // the forName method returns the instance of Class
  Class pluginClass = Class.forName(strClassName);
  // the newInstance method would return the new instance created in the form of Object
  return pluginClass.newInstance();
}This way you do not have to instantiate the class with the new expression like -
SomePlugin pluginObj = new SomePlugin();Instead you could just pass the name of the class to the getNewInstance method -
Object plugIn = getNewInstance("SomePlugin");  Its always nice to look into the API Docs - http://java.sun.com/j2se/1.4.2/docs/api/index.html
Rasmeet.

Similar Messages

  • My 2008 macbook will not turn on. the light on the corner is on. not flashing but on. its fully charged and has lion on it. please help! my classes start Monday and i need it before then!!

    my 2008 macbook will not turn on. the light on the corner is on. not flashing but on. its fully charged and has lion on it. please help! my classes start Monday and i need it before then!! It will turn on for a coupe seconds, and then turn off.

    Take it into an Apple store for evaluation.

  • Please help with simple Classes understanding

    Working further to understand Class formation, and basics.
    At the Java Threads Tutorial site:
    http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
    Goal:
    1)To take the following code, and make it into 2 seperate files.
    Reminder.java
    RemindTask.java
    2)Error Free
    Here is the original, functioning code:
    import java.util.Timer;
    import java.util.TimerTask;
    * Simple demo that uses java.util.Timer to schedule a task
    * to execute once 5 seconds have passed.
    * http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
    public class Reminder {
        Timer timer;
        public Reminder(int seconds) {
            timer = new Timer();
            timer.schedule(new RemindTask(), seconds*1000);
        class RemindTask extends TimerTask {
            public void run() {
                System.out.println("Time's up!");
                timer.cancel(); //Terminate the timer thread
        public static void main(String args[]) {
            new Reminder(5);
            System.out.println("Task scheduled.");
    }Here is what I tried to 2 so far, seperate into 2 seperate files:
    Reminder.java
    package threadspack;    //added this
    import java.util.Timer;
    import java.util.TimerTask;
    * Simple demo that uses java.util.Timer to schedule a task
    * to execute once 5 seconds have passed.
    * http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
    public class Reminder {
        Timer timer;
        public Reminder(int seconds) {
            timer = new Timer();
            timer.schedule(new RemindTask(), seconds*1000);
        public static void main(String args[]) {
            new Reminder(5);
            System.out.println("Task scheduled.");
    }and into
    RemindTask.java
    package threadspack;  //added this
    import java.util.Timer;
    import java.util.TimerTask;
    import threadspack.Reminder; //added this
    * http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
    public class RemindTask extends TimerTask
    Timer timer; /**here, I added this, because got a
    "cannot resolve symbol" error if try to compile w/out it
    but I thought using packages would have negated the need to do this....?*/
         public void run() {
                System.out.println("Time's up!");
                timer.cancel(); //Terminate the timer thread
    }After executing Reminder, the program does perform, even does the timing, however, a NullPointerException error is thrown in the RemindTask class because of this line:
    timer.cancel(); //Terminate the timer thread
    I am not sure of:
    If I have packages/import statements setup correctly
    If I have the "Timer" variable setup incorrectly/wrong spot.
    ...how to fix the problem(s)
    Thank you!

    Hi there!
    I understand that somehow the original "Timer" must
    be referenced.
    This is a major point of confusion for me....I
    thought that when importing
    Classes from the same package/other packages, you
    would have directly
    access to the variables within the imported Classes.I think you have one of the basic points of confussion. You are mixing up the concept of a "Class" with the concept of an "Object".
    Now, first of all, you do not need packages at all for what you are trying to do, so my advice is you completely forget about packages for the moment, they will only mess you up more. Simply place both .class files (compiled .java files) in the same directory. Your program is executing fine, so that indicates that the directory in which you have your main class file is being included in your classpath, so the JVM will find any class file you place there.
    As for Classes/Objects, think of the Class as the map in which the structure of a building is designed, and think of the Object as the building itself. Using the same technical map the architect defines, you could build as many buildings as you wanted. They could each have different colors, different types of doors, different window decorations, etc... but they would all have the same basic structure: the one defined in the technical map. So, the technical map is the Class, and each of the buildings is an object. In Java terminology, you would say that each of the buildings is an "Instance" of the Class.
    Lets take a simpler example with a class representing icecreams. Imagine you code the following class:
    public class Icecream{
         String flavor;
         boolean hasChocoChips;
    }Ok, with this code, what you're doing is defining the "structure" of an icecream. You can see that we have two variables in our class: a String variable with the description of the icecream's flavor, and a boolean variable indicating whether or not the icecream has chocolate chips. However, with that code you are not actually CREATING those variables (that is, allocating memory space for that data). All you are doing is saying that EACH icecream which is created will have those two variables. As I mentioned before, in Java terminology, creating an icecream would be instantiating an Icrecream object from the Icecream class.
    Ok, so lets make icrecream!!!
    Ummm... Why would we want to make several icecreams? Well, lets assume we have an icecream store:
    public class IcecreamStore{
    }Now, we want to sell icecreams, so lets put icecreams in our icecream store:
    public class IcecreamStore{
         Icecream strawberryIcecream = new Icecream(); //This is an object, it's an instance of Class Icecream
         Icecream lemonIcecream = new Icecream(); //This is another object, it's an instance of Class Icecream
    }By creating the two Icecream objects you have actually created (allocated memory space) the String and boolean variable for EACH of those icecreams. So you have actually created two String variables and two boolean variables.
    And how do we reference variables, objects, etc...?
    Well, we're selling icecreams, so lets create an icecream salesman:
    public class IcecreamSalesMan{
    }Our icecream salesman wants to sell icecreams, so lets give him a store. Lets say that each icecream store can only hold 3 icecreams. We could then define the IcecreamStore class as follows:
    public class IcecreamStore{
         Icecream icecream1;
         Icecream icecream2;
         Icecream icecream3;
    }Now lets modify our IcecreamSalesMan class to give the guy an icecream store:
    public class IcecreamSalesMan{
         IcecreamStore store = new IcecreamStore();
    }Ok, so now we have within our IcecreamSalesMan class a variable, called "store" which is itself an object (an instance) of the calss IcecreamStore.
    Now, as defined above, our IcecreamStore class will have three Icecream objects. Indirectly, our icecream salesman has now three icecreams, since he has an IcecreamStore object which in turn holds three Icecream objects.
    On the other hand, our good old salesman wants the three icecreams in his store to be chocolate, strawberry, and orange flavored. And he wants the two first icecreams to have chocolate chips, but not the third one. Well, here's the whole thing in java language:
    public class Icecream{ //define the Icecream class
         String flavor;
         boolean hasChocoChips;
    public class IcecreamStore{ //define the IcecreamStore class
         //Each icecream store will have three icecreams
         Icecream icecream1 = new Icecream(); //Create an Icecream object
         Icecream icecream2 = new Icecream(); //Create another Icecream object
         Icecream icecream3 = new Icecream(); //Create another Icecream object
    public class IcecreamSalesMan{ //this is our main (executable) class
         IcecreamStore store; //Our class has a variable which is an IcecreamStore object
         public void main(String args[]){
              store = new IcecreamStore(); //Create the store object (which itself will have 3 Icecream objects)
              /*Put the flavors and chocolate chips:*/
              store.icecream1.flavor = "Chocolate"; //Variable "flavor" of variable "icecream1" of variable "store"
              store.icecream2.flavor = "Strawberry"; //Variable "flavor" of variable "icecream2" of variable "store"
              store.icecream3.flavor = "Orange";
              store.icecream1.hasChocoChips = true;
              store.icecream2.hasChocoChips = true;
              store.icecream3.hasChocoChips = false;
    }And, retaking your original question, each of these three classes (Icecream, IcecreamStore, and IcecreamSalesMan) could be in a different .java file, and the program would work just fine. No need for packages!
    I'm sorry if you already knew all this and I just gave you a stupid lecture, but from your post I got the impression that you didn't have these concepts very clear. Otherwise, if you got the point, I'll let your extrapolate it to your own code. Should be a pice of cake!

  • Urgent !  Exception problem ... Please Help!

    Question: What is the value of the variable output for foo(1)?
    I've got different numbers from the answer ... Please help!
    public class Test1{
         public static String output = "";
         public static void foo(int i){
              try{
                   if(i == 1){
                        throw new Exception();
                   output +="1";
              catch(Exception e){
                   output += "2";
                   return;               
              finally{
                   output += "3";
              output += "4";
              public static void main(String args[]){
                   foo(0);
                   foo(1);     
         }

    It is what it is. If running this code gives you a different answer than what the book says, then either the book is wrong, or you're not running the same code as what's in the book.
    You can confirm or eliminate the latter quite easily, just by reading carefully.

  • Error in creating a process using runtime class - please help

    Hi,
    I am experimenting with the following piece of code. I tried to run it in one windows machine and it works fine. But i tried to run it in a different windows machine i get error in creating a process. The error is attached below the code. I don't understand why i couldn't create a process with the 'exec' command in the second machine. Can anyone please help?
    CODE:
    import java.io.*;
    class test{
    public static void main(String[] args){
    try{
    Runtime r = Runtime.getRuntime();
         Process p = null;
         p= r.exec("dir");
         BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
         System.out.println(br.readLine());
    catch(Exception e){e.printStackTrace();}
    ERROR (when run in the dos prompt):
    java.io.IOException: CreateProcess: dir error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:63)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:550)
    at java.lang.Runtime.exec(Runtime.java:416)
    at java.lang.Runtime.exec(Runtime.java:358)
    at java.lang.Runtime.exec(Runtime.java:322)
    at test.main(test.java:16)
    thanks,
    Divya

    As much as I understand from the readings in the forums, Runtime.exec can only run commands that are in files, not native commands.
    Hmm how do I explain that again?
    Here:
    Assuming a command is an executable program
    Under the Windows operating system, many new programmers stumble upon Runtime.exec() when trying to use it for nonexecutable commands like dir and copy. Subsequently, they run into Runtime.exec()'s third pitfall. Listing 4.4 demonstrates exactly that:
    Listing 4.4 BadExecWinDir.java
    import java.util.*;
    import java.io.*;
    public class BadExecWinDir
    public static void main(String args[])
    try
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("dir");
    InputStream stdin = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stdin);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    System.out.println("<OUTPUT>");
    while ( (line = br.readLine()) != null)
    System.out.println(line);
    System.out.println("</OUTPUT>");
    int exitVal = proc.waitFor();
    System.out.println("Process exitValue: " + exitVal);
    } catch (Throwable t)
    t.printStackTrace();
    A run of BadExecWinDir produces:
    E:\classes\com\javaworld\jpitfalls\article2>java BadExecWinDir
    java.io.IOException: CreateProcess: dir error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at BadExecWinDir.main(BadExecWinDir.java:12)
    As stated earlier, the error value of 2 means "file not found," which, in this case, means that the executable named dir.exe could not be found. That's because the directory command is part of the Windows command interpreter and not a separate executable. To run the Windows command interpreter, execute either command.com or cmd.exe, depending on the Windows operating system you use. Listing 4.5 runs a copy of the Windows command interpreter and then executes the user-supplied command (e.g., dir).
    Taken from:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Please help with my helper class

    Hi,
    plz I need some assistance with this:
    I have a big table which consist of 200 columns. This table gets fields from different tables. It has records of orders which may have several items and each item can have up to 8 taxes. So i have fields reaping for other order order records. I need to display an order then have a navigation to list items in details, with all its taxes, one by one.
    Here is how I have decided to do it in a nutshell. I have decided to get all taxes of a particular item and put in a map with tax_codes as values and tax details arraylist as values. I then add this to an item with its other details. then I add items to a particular order. I have separated orders,items and taxes in their separate beans. Im trying to first the implimentation for each order, item and taxes by displaying them on a JSP. However am currently getting the following error with taxdetails:
    java.lang.ClassCastException: OrderItems.ItemTax cannot be cast to java.lang.String
    at OrderItems.OrderDetails.getItemTaxDetails(OrderDetails.java:166)
    at OrderItems.Controller.processRequest(Controller.java:57)
    at OrderItems.Controller.doGet(Controller.java:72)
    I have a list of all itemTaxCodes am iterating and am casting to string...am not casting ItemTax object.Here is my code below:
    OrderDetails.java
    package orderitems;
    import java.sql.*;
    import java.util.*;
    public class OrderDetails {
        private LineOder lineOrder;
        private Map lineItems;
        //returns an item number, key_item, from its unique keys
        public int getItemNumber(int key_item, String key_year,
                String key_office,String key_client,String key_company){
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            int itmNum = 0;
             * key_item a unique number for an item.
             * key_year,key_office,key_client,key_company unique keys
             * for each order where this key_item is taken
             * from.
            String select = "SELECT key_item FROM "+
                    Constants.WEB_TABLE +" WHERE key_item = " + key_item +
                    " AND key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company +"'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                if(rst.next()){
                    itmNum = Integer.parseInt(rst.getString("key_item"));
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itmNum;
        //get a list of item number(item codes)
        public List getAllItemNumbers(String key_year,
                String key_office,String key_client,String key_company){
            List itemNumbers = new ArrayList();
            LineItem itemNumber = null;
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            String select = "SELECT key_item FROM "+ Constants.WEB_TABLE +
                    " WHERE key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company + "'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    itemNumber = new LineItem();
                    itemNumber.setKey_item(Integer.parseInt(rst.getString("key_item")));
                    itemNumbers.add(itemNumber);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itemNumbers;
        //get a list of tax codes
        public List getAllTaxCodes(int key_item, String key_year,
                String key_office,String key_client,String key_company){
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            ItemTax taxCode;
            List taxCodes = new ArrayList();
            int itemNum = getItemNumber(key_item, key_year,
                    key_office,key_client,key_company);
            String select = "SELECT key_tax_code FROM "+
                    Constants.WEB_TABLE +" WHERE key_item = " + itemNum +
                    " AND key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company +"'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    taxCode = new ItemTax();
                    taxCode.setKey_tax_code(rst.getString("key_tax_code"));
                    taxCodes.add(taxCode);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return taxCodes;
        //use tax code to get tax details
        public Map getItemTaxDetails(String key_year,String key_office,
                String key_client,String key_company,int key_item){
            ItemTax taxDetail = null;
            List taxDetails = new ArrayList();
            List itemTaxCodes = new ArrayList();
            Map itemTaxdetails = new HashMap();
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            //get a list of all tax codes of an item with a
            //given item number
            itemTaxCodes = getAllTaxCodes(key_item,key_year,///a list of tax codes
                    key_office,key_client,key_company);
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                for(Iterator taxCodeIter= itemTaxCodes.iterator(); taxCodeIter.hasNext();){
                    String taxCode = (String)taxCodeIter.next();/////casting taxtCode to string***exception occurs from here
                    String select = "SELECT tax_type,tax_value," +
                            "tax_limit_val FROM "+ Constants.WEB_TABLE +
                            " WHERE key_item = "+ key_item +
                            " AND key_year = '" + key_year + "'" +
                            " AND key_office = '" + key_office + "'" +
                            " AND key_client = '" + key_client + "'" +
                            " AND key_company = '" + key_company +"'" +
                            " AND key_tax_code = '" + taxCode + "'";///tax code string
                    rst = stat.executeQuery(select);
                    while(rst.next()){
                        taxDetail = new ItemTax();
                        //records to be displayed only
                        taxDetail.setKey_item(Integer.parseInt(rst.getString("key_item")));
                        taxDetail.setTax_value(rst.getString("tax_value"));
                        taxDetail.setTax_limit_val(Float.parseFloat(rst.getString("tax_limit_val")));
                        //////other details records ommited//////////////////////////
                        taxDetails.add(taxDetail);
                //a HashMap of all tax code as keys and list of details as values 4 each key
                for(int i = 0;i<itemTaxCodes.size(); i++){
                    itemTaxdetails.put(itemTaxCodes.get(i),taxDetails.get(i));
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itemTaxdetails;
        //details of an item with all its taxes
        public List getAllItemDetails(String key_year,
                String key_office,String key_client,String key_company){
            List lineItems = new ArrayList();
            List itemNumbers = new ArrayList();
            Map taxDetails = new HashMap();
            LineItem item = null;
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            //A list of all item numbers in the declaration
            itemNumbers = getAllItemNumbers(key_year,
                    key_office,key_client,key_company);
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                for(Iterator itemIter= itemNumbers.iterator(); itemIter.hasNext();){
                    int itemNumber = ((Integer)itemIter.next()).intValue();
                    String select = "SELECT item_description,item_mass," +
                            "item_cost" +
                            " FROM " + Constants.WEB_TABLE +
                            " WHERE key_year = '"+key_year+"'" +
                            " AND key_office = '"+key_office+ "'"+
                            " AND key_client = '"+key_client+ "'"+
                            " AND key_company = '"+key_company+ "'"+
                            " AND key_item = " + itemNumber;
                    rst = stat.executeQuery(select);
                    while(rst.next()){
                        item = new LineItem();
                        item.setItem_description(rst.getString("item_description"));
                        item.setItem_mass(Float.parseFloat(rst.getString("item_mass")));
                        item.setKey_item(Integer.parseInt(rst.getString("item_cost")));
                        //////other details records ommited//////////////////////////
                        //A HashMap of all itemTaxeCodes as its keys and an ArrayList of itemTaxedetails as its values
                        taxDetails = getItemTaxDetails(item.getKey_year(),item.getKey_office(),
                                item.getKey_client(),item.getKey_company(),item.getKey_item());
                        //item tax details
                        item.setItmTaxes(taxDetails);
                        //list of items with tax details
                        lineItems.add(item);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return lineItems;
        public Set getDeclarations(String key_year,String key_cuo,
                String key_dec,String key_nber){
            List lineItems = new ArrayList();
            Set lineOrders = new HashSet();
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            LineOder lineOrder = null;
            String select = "SELECT * FROM " + Constants.WEB_TABLE +
                    " WHERE key_year = '" + key_year + "'" +
                    " AND key_cuo = '" + key_cuo + "'" +
                    " AND key_dec = '" + key_dec + "'" +
                    " AND key_nber = '" + key_nber + "'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    lineOrder = new LineOder();
                    lineOrder.setKey_year(rst.getString("key_year"));
                    lineOrder.setKey_office(rst.getString("key_cuo"));
                    lineOrder.setKey_client(rst.getString("key_dec"));
                    lineOrder.setKey_company(rst.getString("key_nber"));
                    ////list of items with all their details
                    lineItems = getAllItemDetails(lineOrder.getKey_year(),lineOrder.getKey_office(),
                            lineOrder.getKey_client(),lineOrder.getKey_company());
                    //setting item details
                    lineOrder.setItems(lineItems);
                    //a list of order with all details
                    lineOrders.add(lineOrder);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return lineOrders;
    } and my testing servlet controller
    Controller.java
    package orderitems;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Controller extends HttpServlet {
        private Map taxDetails = new HashMap();
        //private List itemDetails = new ArrayList();
        //private Set orderDetails = new HashSet();
        private OrderDetails orderDetails = null;
        protected void processRequest(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            String key_year = "2007";
            String key_office = "VZX00";
            String key_company = "DG20";
            String key_client =  "ZI001";
            int key_item = 1;
            String nextView = "/taxdetails_list.jsp";
            //String nextView = "/order_list.jsp";
            //String nextView = "/items_list.jsp";
            orderDetails = new OrderDetails();
            taxDetails = orderDetails.getItemTaxDetails(key_year,key_office,
                    key_company,key_client,key_item);
            //Store the collection objects into HTTP Request
            request.setAttribute("taxDetails", taxDetails);
            RequestDispatcher reqstDisp =
                    getServletContext().getRequestDispatcher(nextView);
            reqstDisp.forward(request,response);
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            processRequest(request, response);
        protected void doPost(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            processRequest(request, response);
    }I have not included code for beans to reduce on bulk.please help and with suggestions...
    Thanx in advance.
    Edited by: aiEx on Oct 3, 2007 8:13 AM

    aiEx wrote:
    sometimes a tap on the head is needed to really learn and understand :-)You're casting them to the String type while they are of the ItemTax type and you've confirmed it yourself. Likely you misunderstood the concepts behind "casting" and you was expecting some magic that they are automatically converted somehow from the ItemTax type to the String type while the ItemTax class isn't a subclass of the String class :)

  • Please help me for Calendar class

    Now i am working in SAP.Now we are doing Internal project for Company Timesheet of the employee,they are using Java,javascript,html,jsp,mysql.
    Please give Support for developing this task
    I am trying to do employee's timesheet( i.e. daily working hours).Here i attach my documents.here in that screen i am selecting fig1 calendar date for 19th july 2006 now we can see it in fig2 there we will see 15th july 2006 to 21st july 2006 is visible. The scnario is when ever we select the any of the day of the week we need to display whole week sun,mon to sat.
    when i am selecting (select week days by using javascript) total weekly working hours should come.please guide me and give me sample code.
    I think you understand what i am asking. using javascript calendar i am selecting the date.and from database i have to get the daily working hours of the perticular employee. I am not so familiar in java,that's why only i am asking .Please help me
    Advance thanks for You
    code i am pasting here
    thanks&Regards
    Vijaya
    ********** Java code******************
    import java.util.Calendar;
    import java.util.Date;
    class FirstAndLastDay4
    public static void main(String[] args)
    //int i=1;
    try{
    Calendar date=Calendar.getInstance();
    int day = date.get(Calendar.DAY_OF_WEEK);
    switch(day){
    case(1):
    { System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK));
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    break;
    case(2):
    { System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    break;
    case(3):
    { System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-2);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    break;
    case(4):
    { System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-3);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    break;
    case(5):
    { System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-4);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    /*for(int i=0,j=1;i<7;i++)
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+i);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    break;
    case(6):
    { System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-5);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    break;
    case(7):
    { System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-6);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+1);
    System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
    break;
    }catch(Exception e){
    e.printStackTrace();
    }

    Hi All,
    I am trying to do employee's timesheet( i.e. daily working hours).Here i attach my documents.here in that screen i am selecting fig1 calendar date for 19th july 2006 now we can see it in fig2 there we will see 15th july 2006 to 21st july 2006 is visible. The scnario is when ever we select the any of the day of the week we need to display whole week sun,mon to sat.
    when i am selecting (select week days by using javascript) total weekly working hours should come.please guide me and give me sample code.
    Thanks in advance
    thanks & regards
    <code>
    import java.util.Calendar;
    import java.util.Date;
    class FirstAndLastDay
         public static void main(String[] args)
              try{
                   Calendar date=Calendar.getInstance();
                   int day = date.get(Calendar.DAY_OF_WEEK);
                   switch(day){
                        case(1):
                        {     System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK));
                             System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);                         
                             System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             break;
                        case(2):
                        {     System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-1);
                             System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);                         
                             System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             break;
                        case(3):
                        {     System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-2);
                             System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);                         
                             System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             break;
                        case(4):
                        {     System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-3);
                             System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);                         
                             System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             break;
                        case(5):
                        {     System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-4);
                             System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);                         
                             System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             break;
                        case(6):
                        {     System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-5);
                             System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);                         
                             System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             break;
                        case(7):
                        {     System.out.println("\n Input date [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)-6);
                             System.out.println("First day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             date.set(Calendar.DAY_OF_WEEK, date.get(Calendar.DAY_OF_WEEK)+6);                         
                             System.out.println("Last day [" + new java.util.Date(date.getTimeInMillis()) + "]");
                             break;
              }catch(Exception e){
                   e.printStackTrace();
    </code>

  • I'm in a java programming class and i'm stuck.. so please help me guys...

    Please help me, i really need help.
    Thanks a lot guys...
    this is my error:
    C:\Temp>java Lab2
    Welcome!
    This program computes the average, the
    exams
    The lowest acceptable score is 0 and th
    Please enter the minimum allowable scor
    Please enter the maximum allowable scor
    Was Exam1taken?
    Please Enter Y N or Q
    y
    Enter the Score for Exam1:
    65
    Was Exam2taken?
    Please Enter Y N or Q
    y
    Enter the Score for Exam2:
    32
    Was Exam3taken?
    Please Enter Y N or Q
    y
    Enter the Score for Exam3:
    65
    Was Exam4taken?
    Please Enter Y N or Q
    y
    Enter the Score for Exam4:
    32
    Was Exam5taken?
    Please Enter Y N or Q
    y
    Enter the Score for Exam5:
    32
    Score for Exam1 is:65
    Score for Exam2 is:32
    Score for Exam3 is:32
    Score for Exam4 is:32
    Score for Exam5 is:32
    the Minimum is:0
    the Maximum is:0
    Can't compute the Average
    Can't compute the Variance
    Can't compute the Standard Deviation
    this is my code:
    // Lab2.java
    // ICS 21 Fall 2002
    // Read in scores for a student's exams, compute statistics on them, and print out
    // the scores and statistics.
    public class Lab2
         // Create a manager for this task and put it to work
         public static void main(String[] args)
              ExamsManager taskManager = new ExamsManager();
              taskManager.createResults();
    // ExamsManager.java for Lab 2
    // ICS 21 Fall 2002
    // make these classes in the Java library available to this program.
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    import java.text.NumberFormat;
    // ExamsManager creates managers and contains the tools (methods) they need to do their
    // job: obtaining exam information, computing statistics and printing out that information
    class ExamsManager
         // INVALID_INT: special integer value to indicate that a non-integer
         // was entered when an integer was requested. It's chosen so as not to
         // conflict with other flags and valid integer values
         public static final int INVALID_INT = -9999;
         // valid user response constants:
         public static final String YES = "Y";               // user responded "yes"
         public static final String NO = "N";               // user responded "no"
         public static final String EXIT_PROGRAM = "Q";     // user responded "leave the program NOW"
         // INVALID_RESPONSE: special String value to indicate that something other than
         // "Y", "N" or "X" was entered when said was required
         public static final String INVALID_RESPONSE = "!";
         // ABSOLUTE_MIN_SCORE and ABSOLUTE_MAX_SCORE represent the smallest
         // minimum score and the largest maximum score allowed by the
         // program. (The allowable minimum and maximum for one
         // execution of the program may be different than these, but
         // they must both lie within this range.)
         public static final int ABSOLUTE_MIN_SCORE = 0;
         public static final int ABSOLUTE_MAX_SCORE = 1000;
         // The manager needs a place to store this student's exams
         private OneStudentsWork thisWork;
         // ...places to store the min and max scores allowed for these exams
         private int minAllowedScore;
         private int maxAllowedScore;
         // ...and a place to hold input coming from the keyboard
         BufferedReader console;
         //                    -------------------- Constructor --------------------
         // ExamsManager() make managers that delegate the major tasks of the program
         public ExamsManager()
         //                    -------------------- Processing methods --------------------
         // createResults() is the "manager at work": it calls assistants to welcome the user,
         // initializes things so we can read info from the keyboard,
         // obtain the minimum and maximum allowed scores,
         // obtain a student's work and comute the statistics on it and
         // print out the scores and the statistics
         public void createResults()
              // *** YOUR CODE GOES HERE ***
              printWelcomeMessage();
              readyKeyboard();
              obtainMinAndMaxAllowedScores();
              obtainOneStudentsWork();
              printResults();
         //                    -------------------- User input methods --------------------
         // readyKeyboard() sets up an input stream object 'console' connected to the keyboard
         // so that what's typed can be read into the program and processed.
         // Do not modify this code!
         private void readyKeyboard()
                   console = new BufferedReader(new InputStreamReader(System.in));
         // obtainMinAndMaxAllowedScores() asks the user to enter the minimum
         // and maximum allowable scores for this execution of the program.
         // Both the minimum and maximum allowable scores must be between
         // ABSOLUTE_MIN_SCORE and ABSOLUTE_MAX_SCORE (inclusive). This
         // method should continue to ask the user for a minimum until a
         // valid one is entered (or EXIT_PROGRAM is entered), then continue
         // to ask the user for a maximum until a valid one is entered. If
         // the minimum entered is greater than the maximum entered, the
         // whole thing should be done again.
         public void obtainMinAndMaxAllowedScores()
              // *** YOUR CODE GOES HERE ***
              int response = INVALID_INT;
              if (response >= minAllowedScore && response <= maxAllowedScore)
                   System.out.print("Please enter the minimum allowable score:");
                   response = getIntOrExit();
              while (response > maxAllowedScore || response < minAllowedScore)
                   System.out.print("Please enter the minimum allowable score:");
                   response = getIntOrExit();
              if (response <= ABSOLUTE_MAX_SCORE && response >= ABSOLUTE_MIN_SCORE)
                   System.out.print("Please enter the maximum allowable score:");
                   response = getIntOrExit();
              while (response > ABSOLUTE_MAX_SCORE || response < ABSOLUTE_MIN_SCORE)
                   System.out.print("Please enter the maximum allowable score:");
                   response = getIntOrExit();
              /*int response;
              String allowedMin;
              boolean done = true;
              do
                   done = true;
                   System.out.print("Please enter the minimum allowable score:");
                   response = getIntOrExit();
                   allowedMin = getYNOrExit();
                   if(allowedMin == EXIT_PROGRAM)
                        System.exit(0);
                   else if (response >= ABSOLUTE_MIN_SCORE)
                        done = true;
                   else if (response >= ABSOLUTE_MAX_SCORE)
                        done = false;
                        System.out.println("INVALID: " + INVALID_INT);
                        System.out.print("Please enter the minimum allowable score:");
                        response = getIntOrExit();
              }while (!done);
    /*          System.out.print("Please enter the maximum allowable score:");
              response = getIntOrExit();
              if (response <= ABSOLUTE_MAX_SCORE)
              return response;
              else if (response <= ABSOLUTE_MIN_SCORE)
                   response = INVALID_INT;
              while (response == INVALID_INT)
                   System.out.print("Please enter the maximum allowable score:");
                   response = getIntOrExit();
              do
                   done = true;
                   System.out.print("Please enter the minimum allowable score:");
                   response = getIntOrExit();
                   String allowedMax;
                   if(allowedMin == EXIT_PROGRAM)
                        System.exit(0);
                   if (response <= ABSOLUTE_MAX_SCORE)
                        done = true;
                   else if (response <= ABSOLUTE_MIN_SCORE)
                        done = false;
                        System.out.println("INVALID: " + INVALID_INT);
                        System.out.print("Please enter the maximum allowable score:");
                        response = getIntOrExit();
              }while (!done);
         // The overall strategy to building up a student work object is
         // to have the student-bulding method call on the exam-building
         // method, which calls upon user input methods to get exam info.
         // Thus, user entered info is successively grouped together
         // into bigger units to build the entire student information set.
         // obtainOneStudentsWork() builds the five exams
         // and constructs the student work object from them
         private void obtainOneStudentsWork()
              // *** YOUR CODE GOES HERE ***
              int index = 1;
              Exam exam1 = buildOneExam(index);
              index = 2;
              Exam exam2 = buildOneExam(index);
              index = 3;
              Exam exam3 = buildOneExam(index);
              index = 4;
              Exam exam4 = buildOneExam(index);
              index = 5;
              Exam exam5 = buildOneExam(index);
              thisWork = new OneStudentsWork(exam1, exam2, exam3, exam4, exam5);
         // buildOneExam(thisTest) reads the exam information for one exam and returns an
         // Exam object constructed from this information. Uses obtainWasExamTaken() to
         // determine if the exam was taken and obtainOneScore() to get the exam score, if needed.
         private Exam buildOneExam(int thisTest)
              // *** YOUR CODE GOES HERE ***
              int score = 0;
              if(obtainWasExamTaken(thisTest))
                   score = obtainOneScore(thisTest);
              return new Exam(score);
              else
              return new Exam();
              System.out.println("Enter score for exam1:");
              Exam exam1 = new Exam(getIntOrExit());
              System.out.println("Enter score for exam2:");
              Exam exam2 = new Exam(getIntOrExit());
              System.out.println("Enter score for exam3:");
              Exam exam3 = new Exam(getIntOrExit());
              System.out.println("Enter score for exam4:");
              Exam exam4 = new Exam(getIntOrExit());
              System.out.println("Enter score for exam5:");
              Exam exam5 = new Exam(getIntOrExit());
         // obtainWasExamTaken(thisTest) keeps asking the user whether 'thisTest' was taken
         // (e.g., "Was exam 1 taken? Enter Y, N or Q", if thisTest equals 1)
         // until s/he provides a valid response. If Q is entered, we leave the
         // program immediately; if Y or N (yes or no), return true if yes, false if no
         private boolean obtainWasExamTaken(int thisTest)
              // *** YOUR CODE GOES HERE ***
              String response = INVALID_RESPONSE;
              System.out.println("Was Exam" + thisTest + "taken?");
              while (response.equals(INVALID_RESPONSE))
                   System.out.println("Please Enter" + " " + YES + " " + NO + " " + "or" + " " + EXIT_PROGRAM);
                   response = getYNOrExit();
              if (response.equals(YES))
              return true;
              else
              return false;
         // obtainOneScore(thisTest) keeps asking the user to enter a score for
         // 'thisTest' (e.g., "Enter the score for exam 1", is thisTest equals 1)
         // until s/he provides one within range or s/he tells us to exit the program.
         private int obtainOneScore(int thisTest)
              // *** YOUR CODE GOES HERE ***
              int response = INVALID_INT;
              if (response >= minAllowedScore && response <= maxAllowedScore);
                   System.out.println("Enter the Score for Exam" + thisTest + ":");
                   response = getIntOrExit();
              while (response > ABSOLUTE_MAX_SCORE || response < ABSOLUTE_MIN_SCORE)
                   System.out.println("INVALID: " + INVALID_INT);
                   System.out.println("Please Enter again:");
                   response = getIntOrExit();
              return response;
         // scoreIsWithinRange() returns true if the given score is inside of
         // the allowable range and false if it is out of range
         private boolean scoreIsWithinRange(int score)
              // *** YOUR CODE GOES HERE ***
              if (score >= minAllowedScore && score <= maxAllowedScore)
                   return true;
              else
                   return false;
         // getYNQ() reads a String from the console and returns it
         // if it is "Y" or "N" or exits the program if "Q" is entered;
         // the method returns INVALID_RESPONSE if the response is other
         // than"Y", "N" or "Q".
         // Do not modify this code!
         private String getYNOrExit()
              String usersInput = INVALID_RESPONSE;
              try
                   usersInput = console.readLine();
              catch (IOException e)
                   // never happens with the keyboard...
              usersInput = usersInput.toUpperCase();
              if (usersInput.equals(EXIT_PROGRAM))
                   System.out.println("Leaving...");
                   System.exit(0);
              if (usersInput.equals(YES) || usersInput.equals(NO))
                   return usersInput;
              else
                   return INVALID_RESPONSE;
         // getIntOrExit() reads an integer from the console and returns it.
         // If the user types in "Q", the program exits. If an integer is entered,
         // it is returned. If something that is not an integer (e.g. "Alex"), the
         // program returns INVALID_INT
         // Do not modify this code!
         private int getIntOrExit()
              String usersInput = "";
              int theInteger = 0;
              try
                   usersInput = console.readLine();
              catch (IOException e)
                   // never happens with the keyboard...
              // if the user wants to quit, bail out now!
              if(usersInput.toUpperCase().equals(EXIT_PROGRAM))
                   System.out.println("Program halting at your request.");
                   System.exit(0);
              // see if we have an integer
              try
                   theInteger = Integer.parseInt(usersInput);
              catch (NumberFormatException e)
                   // user's input was not an integer
                   return INVALID_INT;
              return theInteger;
         //                    -------------------- User output methods --------------------
         // printWelcomeMessage() prints a welcome message to the user explaining
         // what the program does and what it expects the user to do. In
         // particular, it needs to tell the user the absolute lowest and
         // highest acceptable exam scores
         private void printWelcomeMessage()
              // *** YOUR CODE GOES HERE ***
              System.out.println("Welcome!");
              System.out.println("This program computes the average, the variance, and the standard deviation of 5 exams");
              System.out.println("The lowest acceptable score is 0 and the highest is 1000");
         // printResults() prints all of the scores present, then prints the
         // statistics about them. The statistics that can have factional parts
         // -- average, variance and standard deviation -- should be printed with
         // exactly three digits after the decimal point. If a statistic could not be
         // computed, a message to that effect should print (NOT the "phony" value stored
         // in the statistic to tell the program that the statistic could not be computed).
         public void printResults()
              // These statements create a NumberFormat object, which is part
              // of the Java library. NumberFormat objects know how to take
              // doubles and turn them into Strings, formatted in a particular
              // way. First, you tell the NumberFormat object (nf) how you'd like
              // the doubles to be formatted (in this case, with exactly 3
              // digits after the decimal point). When printing a double you call
              // format to format it -- e.g. nf.format(the-number-to-format)
              NumberFormat nf = NumberFormat.getInstance();
              nf.setMinimumFractionDigits(3);
              nf.setMaximumFractionDigits(3);
              // *** YOUR CODE GOES HERE ***
              System.out.println("Score for Exam1 is:" + thisWork.getExam1().getScore());
              System.out.println("Score for Exam2 is:" + thisWork.getExam2().getScore());
              System.out.println("Score for Exam3 is:" + thisWork.getExam3().getScore());
              System.out.println("Score for Exam4 is:" + thisWork.getExam4().getScore());
              System.out.println("Score for Exam5 is:" + thisWork.getExam5().getScore());
              if (thisWork.getStatistics().getMinimum() == Statistics.CANT_COMPUTE_STATISTIC)
                   System.out.println("Can't compute the Minimum");
              else
                   System.out.println("the Minimum is:" + thisWork.getStatistics().getMinimum());
              if (thisWork.getStatistics().getMaximum() == Statistics.CANT_COMPUTE_STATISTIC)
                   System.out.println("Can't compute the Minimum");
              else
                   System.out.println("the Maximum is:" + thisWork.getStatistics().getMaximum());
              if (thisWork.getStatistics().getAverage() == Statistics.CANT_COMPUTE_STATISTIC)
                   System.out.println("Can't compute the Average");
              else
                   System.out.println("the Average is:" + thisWork.getStatistics().getAverage());
              if (thisWork.getStatistics().getVariance() == Statistics.CANT_COMPUTE_STATISTIC)
                   System.out.println("Can't compute the Variance");
              else
                   System.out.println("the Variance is:" + thisWork.getStatistics().getVariance());
              if (thisWork.getStatistics().getStandardDeviation() == Statistics.CANT_COMPUTE_STATISTIC)
                   System.out.println("Can't compute the Standard Deviation");
              else
                   System.out.println("the Standard Deviation is:" + thisWork.getStatistics().getStandardDeviation());
    // OneStudentsExams.java for Lab 2
    // ICS 21 Fall 2002
    // OneStudentsWork is the exams and the statistics computed from
    // them that comprise one student's work
    class OneStudentsWork
         public static final int NUMBER_OF_EXAMS = 5;
         // The student is offered five exams...
         private Exam exam1;
         private Exam exam2;
         private Exam exam3;
         private Exam exam4;
         private Exam exam5;
         // The statistics on those exams
         Statistics studentStats;
         //                    -------------------- Constructor --------------------
         // Takes five constructed exam objects and store them for this student.
         // Constructs a statistics object that holds the stats for these exams and
         // store it in studentStats.
         public OneStudentsWork(Exam test1, Exam test2, Exam test3, Exam test4, Exam test5)
              // *** YOUR CODE GOES HERE ***
              exam1 = test1;
              exam2 = test2;
              exam3 = test2;
              exam4 = test4;
              exam5 = test5;
              studentStats = new Statistics(test1, test2, test3, test4, test5);
         //                    -------------------- Accessor methods --------------------
         // getExamX() methods make available ExamX
         public Exam getExam1()
              return exam1;
         public Exam getExam2()
              return exam2;
         public Exam getExam3()
              return exam3;
         public Exam getExam4()
              return exam4;
         public Exam getExam5()
              return exam5;
         // getStatistics() makes available the Statistics object that is part of this student's work
         public Statistics getStatistics()
              return studentStats;
    // Statistics.java for Lab 2
    // ICS 21 Fall 2002
    // A Statistics object stores the statistics for a group of Exams.
    class Statistics
         // This constant denotes a statistic that cannot be
         // computed, such as an average of zero scores or a variance
         // of one score.
         public static final int CANT_COMPUTE_STATISTIC = -9999;
         // The stats
         private int minimum;
         private int maximum;
         private int numberOfExamsTaken;
         private double average;
         private double variance;
         private double standardDeviation;
         //                    -------------------- Constructor --------------------
         // Calculates (initializes) the statistics, using passed-in exams.
         // Note that the order of computing thst stats matters, as some
         // stats use others; for instance, variance must be computed before
         // standard deviation.
         public Statistics(Exam exam1, Exam exam2, Exam exam3, Exam exam4, Exam exam5)
              // *** YOUR CODE GOES HERE ***
              calculateAverage(exam1,exam2,exam3,exam4,exam5);
              calculateVariance(exam1,exam2,exam3,exam4,exam5);
              calculateStandardDeviation(exam1,exam2,exam3,exam4,exam5);
         //                    -------------------- Accessor methods --------------------
         // getNumberOfExamsTaken() makes available the number of exams this student undertook
         public int getNumberOfExamsTaken()
              return numberOfExamsTaken;
         // getMinimum() makes the minimum available
         public int getMinimum()
              return minimum;
         // getMaximum() makes the maximum available
         public int getMaximum()
              return maximum;
         // getAverage() makes the average available
         public double getAverage()
              return average;
         // getVariance() make the variance available
         public double getVariance()
              return variance;
         // getStandardDeviation() make the standard deviation available
         public double getStandardDeviation()
              return standardDeviation;
         //                    -------------------- Statistics methods --------------------
         //     ---> Note: all statistics are to be computed using the number of exams taken
         // calculateNumberOfExamsTaken() computes the number of tests the student took
         // and stores the result in 'numberOfExamsTaken'
         // (Note this statistic can always be computed.)
         private void calculateNumberOfExamsTaken(Exam exam1, Exam exam2, Exam exam3, Exam exam4, Exam exam5)
              // *** YOUR CODE GOES HERE ***
              numberOfExamsTaken = OneStudentsWork.NUMBER_OF_EXAMS;
         // calculateMinimum() sets 'minimum' to the minimum score of exams taken, or
         // to CANT_COMPUTE_STATISTIC if a minimum can't be computed.
         private void calculateMinimum(Exam exam1, Exam exam2, Exam exam3, Exam exam4, Exam exam5)
              // *** YOUR CODE GOES HERE ***
              /*min = exam1.getScore();
              if (min > exam2.getScore())
                   min = exam2.getScore();
              if (min > exam3.getScore())
                   min = exam3.getScore();
              if (min > exam4.getScore())
                   min = exam4.getScore();
              if (min > exam5.getScore())
                   min = exam5.getScore();
              if(numberOfExamsTaken == 0)
                   minimum = CANT_COMPUTE_STATISTIC;
              else if(numberOfExamsTaken == 1)
                   minimum = exam1.getScore();
              else
                   minimum = exam1.getScore();
                   if(numberOfExamsTaken >= 2 && numberOfExamsTaken <= minimum)
                        minimum = exam2.getScore();
                   if(numberOfExamsTaken >= 3 && numberOfExamsTaken <= minimum)
                        minimum = exam3.getScore();
                   if(numberOfExamsTaken >= 4 && numberOfExamsTaken <= minimum)
                        minimum = exam4.getScore();
                   if(numberOfExamsTaken >= 5 && numberOfExamsTaken <= minimum)
                        minimum = exam5.getScore();
              if (getMinimum() == ExamsManager.ABSOLUTE_MIN_SCORE)
                   minimum = exam1.getScore();
                   //exam1.getScore() = getMinimum();
              else
                   exam1.getScore() = CANT_COMPUTE_STATISTIC;
         // calculateMaximum() sets 'maximum' to the maximum score of exams taken, or
         // to CANT_COMPUTE_STATISTIC if a maximum can't be computed.
         private void calculateMaximum(Exam exam1, Exam exam2, Exam exam3, Exam exam4, Exam exam5)
              // *** YOUR CODE GOES HERE ***
              /*if (maximum == ExamsManager.ABSOLUTE_MAX_SCORE)
              return true;
              else
              return CANT_COMPUTE_STATISTIC;*/
              max = exam1.getScore();
              if (max < exam2.getScore())
                   max = exam2.getScore();
              if (max < exam3.getScore())
                   max = exam3.getScore();
              if (max < exam4.getScore())
                   max = exam4.getScore();
              if (max < exam5.getScore())
                   max = exam5.getScore();
              if(numberOfExamsTaken == 0)
                   maximum = CANT_COMPUTE_STATISTIC;
              else if(numberOfExamsTaken == 1)
                   maximum = exam1.getScore();
              else
                   maximum = exam1.getScore();
                   if(numberOfExamsTaken >= 2 && numberOfExamsTaken >= maximum)
                        maximum = exam2.getScore();
                   if(numberOfExamsTaken >= 3 && numberOfExamsTaken >= maximum)
                        maximum = exam3.getScore();
                   if(numberOfExamsTaken >= 4 && numberOfExamsTaken >= maximum)
                        maximum = exam4.getScore();
                   if(numberOfExamsTaken >= 5 && numberOfExamsTaken >= maximum)
                        maximum = exam5.getScore();
         // calculateAverage() computes the average of the scores for exams taken and
         // stores the result in 'average'. Set to CANT_COMPUTE_STATISTIC if there
         // are no tests taken.
         private void calculateAverage(Exam exam1, Exam exam2, Exam exam3, Exam exam4, Exam exam5)
              // *** YOUR CODE GOES HERE ***
              if (numberOfExamsTaken == 5)
                   average = (exam1.getScore()+exam2.getScore()+exam3.getScore()+exam4.getScore()+exam5.getScore()/OneStudentsWork.NUMBER_OF_EXAMS);
              else if (numberOfExamsTaken == 4)
                   average = (exam1.getScore()+exam2.getScore()+exam3.getScore()+exam4.getScore()/OneStudentsWork.NUMBER_OF_EXAMS);
              else if (numberOfExamsTaken == 3)
                   average = (exam1.getScore()+exam2.getScore()+exam3.getScore()/OneStudentsWork.NUMBER_OF_EXAMS);
              else if (numberOfExamsTaken == 2)
                   average = (exam1.getScore()+exam2.getScore()/OneStudentsWork.NUMBER_OF_EXAMS);
              else if (numberOfExamsTaken == 1)
                   average = (exam1.getScore()/OneStudentsWork.NUMBER_OF_EXAMS);
              else if (numberOfExamsTaken == 0)
                   average = CANT_COMPUTE_STATISTIC;
         // calculateVariance() calculates the returns the variance of the
         // scores for exams taken and stores it in 'variance'
         // For a small set of data (such as this one), the formula for calculating variance is
         // the sum of ((exam score - average) squared) for scores of exams taken
         // divided by (the number of scores - 1)
         // Set to CANT_COMPUTE_STATISTIC if there are fewer than two tests taken.
         private void calculateVariance(Exam exam1, Exam exam2, Exam exam3, Exam exam4, Exam exam5)
              // *** YOUR CODE GOES HERE ***
              if (numberOfExamsTaken == 5)
                   variance = ((exam1.getScore()-average)*(exam1.getScore()-average)+(exam2.getScore()-average)*(exam2.getScore()-average)+(exam3.getScore()-average)*(exam3.getScore()-average)+(exam4.getScore()-average)*(exam4.getScore()-average)+(exam5.getScore()-average)*(exam5.getScore()-average))/4;
              else if (numberOfExamsTaken == 4)
                   variance = ((exam1.getScore()-average)*(exam1.getScore()-average)+(exam2.getScore()-average)*(exam2.getScore()-average)+(exam3.getScore()-average)*(exam3.getScore()-average)+(exam4.getScore()-average)*(exam4.getScore()-average))/4;
              else if (numberOfExamsTaken == 3)
                   variance = ((exam1.getScore()-average)*(exam1.getScore()-average)+(exam2.getScore()-average)*(exam2.getScore()-average)+(exam3.getScore()-average)*(exam3.getScore()-average))/4;
              else if (numberOfExamsTaken == 2)
                   variance = ((exam1.getScore()-average)*(exam1.getScore()-average)+(exam2.getScore()-average)*(exam2.getScore()-average))/4;
              else if (numberOfExamsTaken < 2)
                   variance = CANT_COMPUTE_STATISTIC;
         // calculateStandardDeviation() calculates the standard
         // deviation of the scores of taken exams and stores
         // it in 'standardDeviation'
         // The formula for calculating standard deviation is just
         // the square root of the variance
         private void calculateStandardDeviation(Exam exam1, Exam exam2, Exam exam3, Exam exam4, Exam exam5)
              // *** YOUR CODE GOES HERE ***
              if (variance == CANT_COMPUTE_STATISTIC)
                   standardDeviation = CANT_COMPUTE_STATISTIC;
              else
                   standardDeviation = (Math.sqrt(variance));
    // Exam.java for Lab 2
    // ICS 21 Fall 2002
    // An Exam object stores information about one exam
    class Exam
         private boolean examTaken;     //was the exam taken? true for yes, false for no
         private int score;               //the exam's score; = 0 if test not taken
         //                    -------------------- Constructors --------------------
         // Construct a taken exam; it has score 's'
         public Exam(int s)
              score = s;
              examTaken = true;
         // Construct an exam not taken; it has a score of 0
         public Exam()
              score = 0;
              examTaken = false;
         //                    -------------------- Accessor methods --------------------
         // Make the score of an exam available
         public int getScore()
              return score;
         // Make available whether an exam was taken
         public boolean wasTaken()
              return examTaken;

    Your code is absolutely unreadable - even if someone was willing to
    help, it's simply impossible. I do give you a few tips, though: If you
    understand your code (i.e. if it really is YOUR code), you should be
    able to realize that your minimum and maximum never get set (thus they
    are both 0) and your exam 3 is set with the wrong value. SEE where
    those should get set and figure out why they're not. Chances are you
    are doing something to them that makes one 'if' fail or you just
    erroneously assign a wrong variable!

  • How can I call a ABAP proxy class from BADI? PLease help

    hi Experts,
        I have a scenario where I have to call a ABAP proxy class from a BADI. How can I do this? Does anybody has sample code for the same?
    Please help.
    Thanks
    Gopal

    Hi,
       You can call a method of a class from BADI. Here are the steps.
       1) In the BADI implementation create a object for the proxy class.
       2) Call the Execute_Synchronous method.
        You can define a BADI by using SE18 and you can implement it by using SE19.
    Sample code...
    ================================================
      METHOD ZIF_EX_VBADI~CONVERTUPPER.
      DATA: OBJ TYPE REF TO ZTESTCLASS.
      DATA: IT_DATA  TYPE ZIN_MT,
                IT_RES   TYPE ZOUT_MT,
                SEXCEPTION TYPE REF TO CX_AI_SYSTEM_FAULT.
      TRY.
          CREATE OBJECT OBJ
             EXPORTING
                 LOGICAL_PORT_NAME = 'TESTPORT'.
      CATCH CX_AI_SYSTEM_FAULT INTO SEXCEPTION.
      ENDTRY.
    ENDMETHOD.
    ================================================
    Thanks,
    Vivek LR

  • A question about class and interface? please help me!

    the following is program:
    interface A{
    public class B implements A{
    public static void main(String [] args){
    A a = new B();
    System.out.println(a.toString());
    }i want to ask a question, the method toString() is not belong to interface A, why a can call method toString()? the interface call the method that isn't belong to, why? please help me...

    because a.toString() call the method toString() of class Object because B implements A, but extends Object and in the class Object there is a method toString(). infact if you override the method toString() in class B, a.toString() call toString() in class B.
    try this:
    interface A {}
    public class B implements A
      public String toString()
        return "B";
      public static void main(String [] args)
        A a = new B();
        System.out.println(a.toString());
      }by gino

  • My keynote seems to be misbehaving. Me, a teacher was preparing a ppt on keynote.all of a sudden, the navigator column to my left goes black and nothing seems to move. Please help! Only 12 hours before I take class.

    My keynote seems to be misbehaving. Me, a teacher was preparing a ppt on keynote.all of a sudden, the navigator column to my left goes black and nothing seems to move. Please help! Only 12 hours before I take class.

    Hi KRKabutoZero,
    Welcome to Apple Discussions
    You may want to look at Knowledge Base Document #58042 on A flashing question mark appears when you start your Mac.
    Do you have access to another Mac? You may want to backing up your files via Target Disk Mode (TDM) as well as running some utilities (Knowledge Base Document #58583 on How to use FireWire target disk mode.
    You may want to invest in a utility like DiskWarrior from Alsoft. It is great for troubleshooting drive malfunctions.
    As said before, you may also want to bring your iBook to your local Apple Store/Reseller.
    Jon
    Mac Mini 1.42Ghz, iPod (All), Airport (Graphite & Express), G4 1.33Ghz iBook, G4 iMac 1Ghz, G3 500Mhz, iBook iMac 233Mhz, eMate, Power Mac 5400 LC, PowerBook 540c, Macintosh 128K, Apple //e, Apple //, and some more...  Mac OS X (10.4.5) Moto Razr, iLife '06, SmartDisk 160Gb, Apple BT Mouse, Sight..

  • Please Help ?? Tomcat 6 and JDK 6 Class Not Found Exception when deploying

    Hi,
    I am deploying this application in Tomcat 6, but I am getting ClassNotFoundException when I try to the application. I am a novice at this.
    SEVERE: Error loading WebappClassLoader
      delegate: false
      repositories:
    ----------> Parent Classloader:
    org.apache.catalina.loader.StandardClassLoader@146c1d4
    com.jbe.test.HelloWorldServlet
    java.lang.ClassNotFoundException: com.jbe.test.HelloWorldServlet
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1068)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:791)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:127)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         at java.lang.Thread.run(Thread.java:619)
    Oct 15, 2007 12:57:31 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Allocate exception for servlet asterisk
    java.lang.ClassNotFoundException: com.jbe.test.HelloWorldServlet
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1068)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:791)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:127)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         at java.lang.Thread.run(Thread.java:619)My web xml configuration
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">
         <display-name>Hello, World Application</display-name>
        <description>
         Simple Test with a servlet.
        </description>
        <servlet>
             <servlet-name>helloworld</servlet-name>
             <servlet-class>com.jbe.test.HelloWorldServlet</servlet-class>
        </servlet>
        <servlet-mapping>
             <servlet-name>helloworld</servlet-name>
             <url-pattern>/hello.htm</url-pattern>
        </servlet-mapping>
    </web-app>My JSP: <html>
         <head><title>Test Hello World</title>
         </head>
         <body>
         <form>
         <a href = "hello.htm">Hello World</a>
         </form>
         </body>
    </html>
    Please Help !!!

    Are you sure your HelloWorldServlet has doGet method?
    package com.jbe.test;
    // Import servlet packages
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class HelloWorldServlet extends HttpServlet {
         public HelloWorldServlet() {}
         public void init() throws ServletException     {}
         public void doGet(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException           {
              response.setContentType("text/html");
            // then get the writer and write the response data
            PrintWriter out = response.getWriter();
            out.println("<HEAD><TITLE> SimpleServlet Output</TITLE></HEAD><BODY>");
            out.println("<h1> SimpleServlet Output </h1>");
            out.println("<P>This is output is from SimpleServlet.");
         out.println("</BODY>");
         out.close();
         public void destroy()     {}
    }

  • Please help...Its really urgent- Which class to use for this?

    Can someone help me with this? I want to read characters from a file
    Ultimately I want to load some information from a text file which has information like this:
    0123456789
    0
    1
    4
    10
    X0123456789
    01202120212
    11202120212
    20212021202
    I want to load the information from X onwards .. all the rows and columns in a 2D array..
    I am not able to read the file at all ...
    I tried RandomAccessFile, BufferedReader..... They had problems.....what class sould I use.. any if you can give hints how I can reach X and start reading to 2d array...... It will be really very very helpful........
    Please help......

    Hi...
    See this is the partial code
    class LanguageRecognizer
         String word;
         String fileName;
         BufferedReader reader;
         char transitionTable[][];
         char letters[];
         char startState;
         char endStates[];
         int rows;
         int columns;
         public void getFileName(String fileName_)
              /********** Create File Objects to read file ******************************/
              try{
              this.fileName = fileName_;
              java.io.BufferedReader reader = new java.io.BufferedReader(new FileReader(fileName));
                   /***** Read File **************/
                   int i;
                   int X = 0;
                        /** as long as its not the EOF **/
                        while((i=reader.read()) != -1)
                             //Print all characters
                             System.out.println((char)i);
                             if (((char)i)=='X')
                                  X = i;
                                  System.out.println("X is at "+(char)i);                         
                             }//if
                        }//while          
              catch(Exception e)
                   e.printStackTrace();
              /**Call Prompt user and ask user to enter a word****************************/
                   promptUser();
         }//getFileName()When I say
    The while loop prints this file containing:
    0123456789
    0
    1
    4
    10
    X0123456789
    01202120212
    11202120212
    20212021202
    But it prints it in this format :
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    //Want to take this in the letter[]
    0 //want to take this as the startstate
    1 // This is the end state which could be more than one so in endState[]
    4 // This is the number of rows in the transition table
    1 // This is columns
    0
    //This is the transition table that I want in a 2D array......
    X // This is the X printed with the if() in the code
    X
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    0
    1
    2
    0
    2
    1
    2
    0
    2
    1
    2
    1
    1
    2
    0
    2
    1
    2
    0
    2
    1
    2
    2
    0
    2
    1
    2
    0
    2
    1
    2
    0
    2
    So I want to capture each letter typed in arrays.......But I am not able to seperate them and get them in my datatypes... atleast not using this class BufferedReader.... so can I use this class and get it or which class can I use??

  • PLEASE HELP. How do you access properties files in WEB-INF  and classes directory

    We have a war file that needs to access properties files that are in the WEB-INF directory
    of the war file. We also need to load one of the properties files from the classpath.
    However, when we deploy the application ( an ear which inlcludes an ejbjar and a
    war and the libraries both the ejbjar (with a manifest setting the classpath ) and
    war need ) the properties don't get extracted.
    In some of our servlets we are trying to access those files with the path "WEB-INF/foo.properties"
    and we get a FileNotFoundException. Then we check and see that NO properties files
    have been extracted into their appropriate places ( not even those we throw into
    the WEB-INF/classes directory ).
    PLEASE HELP,
    Christian Hargraves

    The file doesn't have to be extracted from the war. For example, you can place
    test.properties into your app WEB-INF and write a simple JSP to see how it
    works:
    <%
    InputStream in = application.getResourceAsStream("/WEB-INF/test.properties");
    %>
    It will return you a zip inputstream if you deployed your application as a .war.
    Christian Hargraves <[email protected]> wrote:
    I try this, but I get a NullPointerException. The file never actually gets extracted
    from the war. Under tomcat and resin this works great ( that's why I am having all
    of the trouble i am having ), but there are absolutely no properties files in the
    extracted directories for WebLogic deploys. only:
    WEB-INF/some_tmp_dir/WEB-INF/lib
    and then some dynamically generated jor file with all of the classes that would normally
    go in WEB-INF/classes ( all except the properties, of course, which are no where
    to be found. ).
    There has to be some kind of setting I am missing. Please don't make me seperate
    these properties files from the war/ear and then put the path to these properties
    files in the CLASSPATH, changing one step to three steps to deploy!!
    I have found a documented bug where you can't even put the properties files in a
    jar file and that bug will never be fixed for WebLogic 6.1.
    "Dimitri I. Rakitine" <[email protected]> wrote:
    To access files in WEB-INF you can use ServletContext.getResourceXXX("/WEB-INF/filename")
    Christian Hargraves <[email protected]> wrote:
    We have a war file that needs to access properties files that are in theWEB-INF directory
    of the war file. We also need to load one of the properties files fromthe classpath.
    However, when we deploy the application ( an ear which inlcludes an ejbjarand a
    war and the libraries both the ejbjar (with a manifest setting the classpath) and
    war need ) the properties don't get extracted.
    In some of our servlets we are trying to access those files with the path"WEB-INF/foo.properties"
    and we get a FileNotFoundException. Then we check and see that NO propertiesfiles
    have been extracted into their appropriate places ( not even those wethrow into
    the WEB-INF/classes directory ).
    PLEASE HELP,
    Christian Hargraves--
    Dimitri
    Dimitri

  • Please help to use my class in a JSP

    Hi
    Please could someone help me i've started a new job and need to create like a "Add to shortlist" functionality to their website.
    I have created a class to create a cookie using the offerid specific to that page which is done in the doGet() method.
    Now, the problem is that i don't know how to basically make the cookie be created when the button is pressed.
    I have thought of using <jsp:useBean> and putting my class in there but don't know how to call the doGet() method, if you know what i mean.
    Otherwise i've thought of doing the cookie creating in the JSP but then also i don't know how to make by the click of a button, it creates a cookie with that offerid.
    PLEASE help!? If you need more info pls let me know,
    Btw i am new to this so sorry if this sounds stupid, but thanks in advance for ANY help!

    There is only one thing to do in your case: hit the books and learn how to properly program servlets and JSPs - until you know at least the very basics (clicking a button and "doing something" falls in that category), it will be impossible to guide you to anything productive. I've seen it happen before many times; an answer is given, the answer is not understood and then the demand for "sample code" pops up, after which it all goes downhill fast.
    I always recommend this free online book, because it is quite good:
    [http://pdf.coreservlets.com/|http://pdf.coreservlets.com/]
    If you buckle down, you should be able to get things up and running in a few days. Good luck!

Maybe you are looking for