A Method Without Body???

Hi everyone I Have an example in some book about operative systems from Dr. A. Tanenbaum, the code looks like this:
public class ProductoConsumidor{
   static final int N = 100;
   static productor p = new productor();
   static consumidor c = new consumidor();
   static nuestro_monitor mon = new nuestro_monitor();
   public static void main(String args[]){
      p.start();
      c.start();
   static class productor extends Thread{
      public void run(){
         int elemento;
         while(true){
            elemento = producir_elemento();
            mon.insertar(elemento);
      private int producir_elemento(){...}
   static class consumidor extends Thread{
      public void run(){
         int elemento;
         while(true){
            elemento = mon.eliminar();
            consumir_elemento(elemento);
      private void consumir_elemento(int elemento){...}
   static class nuestro_monitor{
      private int bufer[] = new int[N];
      private int cuenta = 0, inf = 0, sup = 0;
      public synchronized void insertar(int val){
         if(cuenta == N) ir_a_estado_inactivo();
         bufer[sup] = val;
         sup = (sup+1)%N;
         cuenta = cuenta+1;
         if(cuenta == 1) notify();
      public synchronized int eliminar(){
         int val;
         if(cuenta == 0) ir_a_estado_inactivo();
         val=bufer[inf];
         inf = (inf+1)%N;
         cuenta = cuenta-1;
         if(cuenta==N-1) notify();
         return val;
      private void ir_a_estado_inactivo(){
         try{
            wait();
         }catch(InterruptedException exc){
}But I tried to compile the File and the following error appears: illegal start of expression
*private void consumir_elemento(int elemento){...}*
*^*
What does this fragment of code does, why does it have three dots in the body of the method?? private int producir_elemento(){...}It is supposed to simulte a monitor for 2 process Productor and Consumidor, hope anyone can help xD

B-Rabbit wrote:
What does this fragment of code does, why does it have three dots in the body of the method?? private int producir_elemento(){...}
The code is not complete (and that is why it does not compile).
You are supposed to add your own code in the "body" of that method - ie to replace the three dots. It might be as simple as some output:
private void consumir_elemento(int elemento){
    System.out.printf("%s has been removed from the array and processed%n", elemento);
}

Similar Messages

  • How to call a instance method without creating the instance of a class

    class ...EXCH_PRD_VERT_NN_MODEL definition
    public section.
      methods CONSTRUCTOR
        importing
          value(I_ALV_RECORDS) type ..../EXCH_VBEL_TT_ALV
          value(I_HEADER) type EDIDC .
      methods QUERY
        importing
          I_IDEX type FLAG
          i_..........
        returning
          value(R_RESULTS) type .../EXCH_VBEL_TT_ALV .
    Both methods are instance methods.
    But in my program i cannot created instance of the class unless i get the results from Query.
    I proposed that Query must be static, and once we get results we can create object of the class by pasing the result table which we get from method query.
    But i must not change the method Query to a static method.
    Is there any way out other than making method Query as static ?
    Regards.

    You can't execute any instance method without creating instance of the class.
    In your scenario, if you don't want to process your method of your class, you can check the instance has been created or not.
    Like:
    IF IT_QUERY IS NOT INITIAL.
      CRATE OBJECT O_QUERY EXPORTING......
    ENDIF.
    IF O_QUERY IS NOT INITIAL.
    CALL METHOD O_QUERY->QUERY EXPORTING....
    ENDIF.
    Regards,
    Naimesh Patel

  • Can we call a static method without mentioning the class name

    public class Stuff {
         public static final int MY_CONSTANT = 5;
         public static int doStuff(int x){ return (x++)*x;}
    import xcom.Stuff.*;
    import java.lang.System.out;
    class User {
       public static void main(String[] args){
       new User().go();
       void go(){out.println(doStuff(MY_CONSTANT));}
    }Will the above code compile?
    can be call a static method without mentioning the class name?

    Yes, why do it simply?
    pksingh79 wrote:
    call a static method without mentioning the class name?For a given value of   "without mentioning the class name".
        public static Object invokeStaticMethod(String className, String methodName, Object[] args) throws Exception {
            Class<?>[] types = new Class<?>[args.length];
            for(int i=0;i<args.length;++i) types[i] = args==null?Object.class:args[i].getClass();
    return Class.forName(className).getDeclaredMethod(methodName,types).invoke(null,args);

  • How to raise exception in bor method without showing runtime error

    I want to raise custom exception in the bor method like below. However, it will show runtime error when executing codes below. Any knows how to raise custom exception in the bor method without runtime error?
    raise 9021.

    Hi Nick
    You need to define the exception 9021 for the method and then you use the macro EXIT_RETURN as below
    exit_return 9021 sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    Regards
    Ravi

  • Want to set mailto for google apps;tried editing the gecko...mailto.2.uritemplate as per instructions found on web; set 3 related config values to "true" as per instructions; does not work; tried javascript method without success

    I want to set the mailto app for google apps gmail.
    I tried editing the gecko...mailto.2.uritemplate as per instructions found on web (https://mail.google.com/a/MYDOMAIN/mail/?extsrc=mailto&url=%s.
    Set 3 related config values to "true" as per instructions (network.protocol-handler.expose.mailto ; network.protocol-handler.warn-external.mailto ; AND, third, gecko.handlerService.allowRegisterFromDifferentHost.
    Does not work, no Google Apps in the mailto app spot.
    Tried javascript method in address bar without success:
    javascript:window.navigator.registerProtocolHandler("mailto","https://mail.google.com/a/MYDOMAIN/mail/?extsrc=mailto&url=%s","Google Apps GMail")
    Any light anyone can shed will be appreciated. Cheers, jlf

    Great howto Steve! This further increased my understanding of the MVC patterns used by BC4J.
    Some remarks:
    [*]Select New Business Components...
    This should be 'New Business Components Package', or you won't be able to add business components.
    ename as "Name",
    sal as "Salary"
    from emp
    where empno = ?That should be deptno.
    [*]Select the EditEmpsInDepartment view objectThat should be EmpsInDepartment.
    Greetings,
    Ivo

  • How call native method without code modification

    "How to access third party's C API from Java Using JNI without modifying the C code"

    Unfortunately, the only way I know of doing this is to use a pass-through DLL that you write. Logically it
    looks like this:
    Java App (written by you)
    |
    v
    Java native methods (written by you)
    |
    v
    JNI DLL (written by you)
    |
    v
    3rd party DLL
    It adds a little bit of overhead, but it's not too big of a deal. Check out the JNI tutorial on how to write this.
    Bryan

  • Results Analysis - Cost based POC method without margin

    Hello Experts,
    I would like to use the standard method - 03 , Cost based POC method but without margin. That means,
    1. System will calculate POC based on the actual costs and planned costs.
    2. Calulated revenue is created by multiplying the POC and the planned revenue.
    Here, Till the actual revenue is more than the planned costs, calculated revenue should be made equal to the actual costs.
    I have created standard method -03 and in the expert mode i have changed the profit indicator to " E - Profit Realization if actual revenue greater than planned costs"
    This works for first period when there is no actual revenue. After the actual revenue which is less than the planned cost,
    this does not work.
    Please let me know if you have any suggestion
    Thanks
    Regards
    Srinivasan Desingh

    in our projects I used to sit with CO consultant and do a lot of RA testing by changing different fields and finally reach the required result. Hit and Trial method (so it is hard to remember exactly what happen while changing a single field as there are many fields in expert mode). May be you can also try the same.

  • Payment methods without Credit card account

    Apple do not take Singapore market seriously? In Singapore Gift card or any other method of payment are not possible? Must have US account?
    Paypal also need to have Credit card account. Our problems here are how to make purchase in App store without a credit card account?
    Gift card are not avialable in Singapore? How to purchase? where to buy?
    How to use a US gift card account for Singapore app store?  If within Singapore is not available to have gift card, Apple should offer a very special location where using US gift card in Singapore should consider as same as US app store account.
    Else, please make Gift card avialable in Singapore for user who do not have Credit card account, still able to purchase a gift card from any store and make payment in App store with the gift card.

    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card

  • Newbie Q'n -- Calling class methods without instantiation

    Hello All,
    I would like to know how is it possible to call methods within a class without instatiating the class.
    For instance consider the following statement:
    String x = Integer.toString(10);
    Here there we are calling the toString() function of "Integer" class without instantiating it. How is it possible?? How does the JVM call the toString() function when there is no Integer object defined in my program?? Can the same functionality achieved for user created classes ??
    Can anyone explain ??
    If this appears as a trivial question, please forgive me.
    Thanks in advance,
    Arun

    String x = Integer.toString(10);
    Here there we are calling the toString() function of
    "Integer" class without instantiating it. How is it
    possible?? How does the JVM call the toString()
    function when there is no Integer object defined in my
    program?? Can the same functionality achieved for user
    created classes ?? It isn't possible, and its not happening in your example either:
    toString() is an instance method. toString(int) and toString(int, int) are class (static) methods.
    You might see documentation referring to a toString (notice no "()" at the end) method. When you do, it should usually be clear from the context which particular method is being referred to.
    Such confusion might well have been avoided if the original API designers had thought to call the methods something different (perhaps format?), but they didn't (in fact, toString(int) seems rather pointless).

  • Email reply- Choice of sending with or without body of message

    Want to start out with...great phone....have had it for 4 months and never had an issue....
    Just want to know how to reply to an email and have the choice of whether to send it with the body of the message or not...when i was just using for personal email it did not matter, but now i have added my work email and i would like to have the choice.
    Thanks

    Hello BacknBlack,
    Welcome to the BlackBerry Support Community.
    Thank you for your question on replying to email with or without the body of the email message on your BlackBerry Z10 smartphone.
    Currently the message body will always be included when replying to email. Any content from the original listed thread would need to be manually deleted.
    Cheers,
    -FB
    Come follow your BlackBerry Technical Team on Twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.
    Click "Accept as a Solution" for posts that have solved your issue(s)!

  • Constructing actionPerformed method without using if statements

    Hi,
    I'm currently writing a basic swing program, and have used 'if' statements within the actionPerformed methods. I wondered if there was a better, neater way of doing this without using the 'if' statements.
    My code so far is as follows,
    method 1:
    static private class IncrementDecrementAction implements ActionListener {
            boolean oddNumberClick = true;
            public void actionPerformed(ActionEvent e) {
                if (oddNumberClick= !oddNumberClick)
                    SimpleSwing.label.setText(labelPrefix + "Decrement");
                else
                    SimpleSwing.label.setText(labelPrefix + "Increment");
        }method 2:
    static private class ClickAction implements ActionListener {
            public int numClicks = 0;
            public void actionPerformed(ActionEvent e) {
                if (SimpleSwing.label.getText().equals(labelPrefix + "Increment"))
                    numClicks++;
                else
                    numClicks--;
                SimpleSwing.label2.setText(labelPrefix2 + numClicks);
        }Any ideas or advice appreciated.
    Thanks

    I think there's a way, but it is very similar to your code:
    public void actionPerformed(ActionEvent e) {
         numClicks = SimpleSwing.label.getText().equals(labelPrefix + "Increment")?numClicks + 1: numClicks - 1;
         SimpleSwing.label2.setText(labelPrefix2 + numClicks);
    }But keep in mind this: each time a button is pressed it will always call actionPerformed of all its listeners, so there is no way to call different methods (unless you use different listeners like Mouse listeners...).

  • How to write a method without knowing how many parameters passed in?

    hi there,
    i m writing a method which is to find out the max value of a set of values, e.g.
       int max(var1, var2, var3, var4) {
          here is the code to find the max value, and return it;
    ......in these case, there are 4 parameters, but what i m trying to do is to write a general method can handle any number of parameters. for some reason, i can't pass in an Array, or a Collection, is there any way i can achieve it?
    thank you!
    best regards

    for some reason, i can't
    pass in an Array, or a CollectionWhy you can't pass a Collection in? I think passing a
    Collection is preferred to the alternative suggestion.and I disagree. Having to build a collection first seems very clumsy. For example, using the following definition of max()
        public static int max(int a, int... b)
            for (int x : b)
                if (x > a)
                    a = x;
            return a;
        }means that I can quite simple get the max of 5 values using
    int max = max(4, a, b,d,21);
    Now you try the same using a collection.
        public static int max(List<Integer> list)
            int max = Integer.MIN_VALUE;
            for (int x : list)
                if (max < x)
                    max = x;
            return max;
    List<Integer> list = new ArrayList();
    list.add(4);
    list.add(a);
    list.add(b);
    list.add(d);
    list.add(21);
    int max = max(list);I know which I prefer.

  • How to output HTML code in methods without out.print

    Hi,
    I am trying to create a larger web-site with jsp. At first I tried to structure the page using include files. Since there is a limit for the length of if/else blocks, I now switched to using methods instead.
    The Problem I have is that there a larger HTML blocks I dont want to print with out.print because that would make the source unreadable.
    Unfortunately the <%= tag doesnt work in methods.
    Here a code sample:
    <%!
    public void processOrder()
    for(int i=1; i<10; i++)
    out.print("<table>");
    out.print("<tr>");
    out.print("<td>Your Order:<td>");
    %>
    Isnt there a way to use a tag like <%= ?
    Or are there other constructs then methods which can handle <%= ?
    With PHP it would be no problem. So I wonder why there should be no way to do it with jsp.

    I generally put dynamic output in a separate class file; you can then either instantiate the class in a scriptlet and call the appropriate method (which can either return a string or do all of your out.prints) or use a jsp:useBean tag.
    Given the following class:
    public class myHTML {
       public myHTML(){}
       public String renderTable(){
          String s = "";
          s += "<TABLE>\n";
          s += "<TR><TD>some content</TD></TR>\n";
          s += "</TABLE>\n";
          return s;
    }You can then do either of the following in your JSP page:
    1.<%
       myHTML mh = new myHTML;
       out.print(mh.renderTable());
    %>2.<jsp:useBean id="somename" class="somepkg.myHTML" scope="request">
    <%=somename.renderTable()%>
    </jsp:useBean>Either will work, and all of the redundant out.print or String concat lines are moved out of the JSP.

  • How to code the ejbCreate() method without initailizing primary key?

    Hi all,
    I've just started learning about EJBs, and now am at the stage of learning how to create, deploy and test a CMP Entity Bean.
    Ran into a problem which I'm hoping someone can help out with.
    I'm using SQL Server 2000 as my backend database, and have created a simple table called TEST with 2 fields, id and name. id is set as the primary key, and as an identity conlumn. What this means is that when we do inserts, we don't need to specify a value for the id column. SQL Servers automatically generates that value.
    Here's my ejbCreate method in my bean class:
    public Integer ejbCreate(String name) throws CreateException {
        this.setName(name);
    }When I tried to run the create method from a web client, I got this error:
    javax.ejb.CreateException: [EJB:010148]In EJB 'SampleEJB', the primary key field 'id' was not set during ejbCreate. All primary key fields must be initialized during ejbCreate. at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:186) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244) at everbright.ejb.SampleEJB_uzc4wg_HomeImpl_813_WLStub.create(Unknown Source) at jsp_servlet.__index._jspService(__index.java:152) at weblogic.servlet.jsp.JspBase.service(JspBase.java:33) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
    So it seems like I can't leave the id field uninitialized in the ejbCreate method. However I don't know what to initialize it with either, because in order to know what value I need to initialize it to, I'll need to run a db query to retrieve the next primary key value for the id field. This doesn't sound very efficient to me.
    I tried to initailize it to null, but that gave me a NullPointerException.
    Why do we need to initialize the primary key field in ejbCreate? Should the container do the insert and then get it from the table accordingly?
    Is there any other way I can get this set-up working?
    Thanks!

    Hi Fusion777,
    Ya, I've been searching around forums for an answer also. Apparently this is indeed a problem that has no general solution. It depends on 2 factors:
    1) Whether or not the database supports autogenerate key (which most does) and how (Oracle does it by sequences while SQL Server by identities)
    2) Whether or not the application server supports 1).
    In my case, I'm using SQL Server and Weblogic Server 8.1 and most fortunately, Weblogic does support identities and sequences. Just define the <auto-key-generation> stanza in your weblogic-cmp-rdbms-jar.xml deployment descriptor, as follows:
    <automatic-key-generation>
         <generator-type>ORACLE</generator-type>
         <generator-name>test_sequence</generator-name>
         <key-cache-size>10</key-cache-size>
    </automatic-key-generation>
    <automatic-key-generation>
         <generator-type>SQL-SERVER</generator-type>
    </automatic-key-generation>
    <automatic-key-generation>
         <generator-type>NAMED_SEQUENCE_TABLE</generator-type>
         <generator-name>MY_SEQUENCE_TABLE_NAME</generator-name>
         <key-cache-size>100</key-cache-size>
    </automatic-key-generation>I've tried that and it works :-)
    I gather from your reply that those who are using JBoss are equally fortunate :-)
    So I thought I'll share this in case some other poor fellow is facing the same problem as we are. At least worse come to worse, he'll have the option of switching to either JBoss or Weblogic and know that it works in both :-)
    Some other users seem to be against the idea of using auto-generated keys for precisely the reason that it is not a standard across database and application servers. See this thread:
    http://forum.java.sun.com/thread.jspa?forumID=13&threadID=329896
    I've in fact stopped working on EJB 2.0 and am exploring something called Hibernate, which seems to have a more generic way of dealing with the auto-generated key issue. In fact, I've heard news that EJB 3.0, which is the upcoming standard for EJB, will be heavily inspired by Hibernate as far as CMP Entity Beans are concerned.
    You can check out Hibernate at http://www.hibernate.org.

  • Payment Method without Check

    Hi Experts,
    Is there any possibilities to clear vendor invoices using F-58 without giving check lot?
    I mean by using bank transaction (E-Banking)
    Please advice.
    Regards
    Sam

    Try transaction F-53 instead.
    Regards,
    Shannon

Maybe you are looking for

  • How do I move my iTune library from a pc to my mac book pro?

    I'm getting my son a MacBook Pro.  How can I get his iTune library from a pc to his new Book?

  • My HP B210e will not print in color.

     My HP B210e will not print in color. It does not copy in color either. I have added all new cartridges and the levels read good. Any help with this will be much appreciated.

  • Hi, my MacBook Pro crashes several times a day. What can I do?

    What to do? I receive the following error message: Anonymous UUID:   4D909251-3556-2874-9254-030A6EF7A9BA Tue Apr  1 10:32:26 2014 panic(cpu 1 caller 0xffffff7f8bfe7fb0): "GPU Panic: [<None>] 3 3 7f 0 0 0 0 3 : NVRM[0/1:0:0]: Read Error 0x00000100: C

  • Error while validating

    hi, after compile my java files on command like then i opend weblogic builder. 1.i connected to server. 2.file open then descriptors sucessfuly created. 3.but while validating and deployement through weblogic builder i am getting error look like this

  • Iweb publishing?? Two sites causing headaches!!!

    ok someone may have figured this out I am new to Apple but love it!!!! The issue and question I have is I have two going to have 4 sites in Iweb which they say is fine!! Now the issue is!! how can you publish just one of the sites!!! I do not want to