Methods to do increasing in java coding

may i know how to do a selective code to do increasing in java code?
like :
i got numbers 20, 30, 20 ,20
IT IS BEFORE I ENTERED ANY NUMBERS IN !!
uniqueNumber 0
numberOfuniqueNumbers 0
occurrences 0
IF i enter 20 into the system
THEN
uniqueNumber will become 1
numberOfuniqueNumbers will become 1
occurences will become 1
when i enter 20 again
uniqueNumber will become 1
numberOfuniqueNumbers will become 1
BUT
occurrences will become 2
and i dont know how to use if/else method to do the increment of occurences.
is it like this?
IF uniqueNumber ++
occurences +1
or is there any way out for it?

ok, let's pretend that a user can only enter numbers from 1 to 5. And he's decided to input 5 numbers. We declare an integer input array of size 5 and an integer counter array of size 6.
Input array = [1,3,4,1,3]
Counter array = [0,0,0,0,0,0]
uniqueNumbers = 0
Loop through input array:
     1st input array value = 1
     set counter[1]++     
     now counter array = [0,1,0,0,0,0]
     2nd input array value = 3
     set counter[3]++
     now counter array = [0,1,0,1,0,0]
     3rd input array value = 4
     set counter[4]++
     now counter array = [0,1,0,1,1,0]
     4th input array value=1
     set counter[1]++
     now counter array = [0,2,0,1,1,0]
     5th input array value = 3
     set counter[3]++
     now counter array = [0,2,0,2,1,0]
Loop through counter array
     1st counter array value (index 0) = 0, do nothing
     2nd counter array value (index 1) = 2,
          print "1 has 2 occurances"
          uniqueNumbers++ (now it equals 1)
     3rd counter array value (index 2) = 0, do nothing
     4th counter array value (index 3) = 2,
          print "3 has 2 occurances"
          uniqueNumbers++ (now it equals 2)
     5th counter array value (index 4) = 1,
          print "4 has 1 occurances"
          uniqueNumbers++ (now it equals 3)
     6th counter array value (index 5) = 0, do nothing
Print out unique numbers (which equals 3)Now your turn. You can do it! :)

Similar Messages

  • How to increase the Java Heap Space for a main method

    Hello all,
    after a given number of calculations inside a class with main-method, I get an OutOfMemoryError (Java Heap Size).
    So I'm just trying to increase the Heap Size Creator uses, but it won't work.
    After reading a lot of posts and online-articles, I tried the following:
    1) I changed the -Xms and -Xmx options (to 512m) both in
    $CREATOR/SunAppServer8/domains/creator/config/domain.xml and
    $CREATOR/etc/creator.conf (this file also points to the Creator built-in JDK)
    2) additionally I tried to start Creator from the console with the respective option:
    ./creator -J-Xmx512m
    The memory toolbar shows the right value, but when I use
    System.out.println("JVM maximum memory:\t"+Runtime.getRuntime().maxMemory()/1024+" KB\n");it always says 64 MB, no matter which option I chose in the config-files.
    So how can I increase this value?
    Regards,
    Felix
    Message was edited by:
    Felice
    Message was edited by:
    Felice

    Thank you very much,
    this was an important hint. Additionally I had to create a new "Java Class Library" project with a copy of the needed files (those that are not dependent on the Application Server). Then I could use the option you mentioned.
    Unfortunately, when I try to run the file with
    java -jar FILENAME.jarit won't work, because the archive is not complete: MANIFEST.MF lacks the main-class and all involved libraries.
    I managed to add the main-class attribute manually, but adding all library references seems to be very error-prone.
    So does anyone know if I did something wrong or if this is a bug of Creator?
    Regards,
    Felix

  • What's up with the Sun Java coding convention

    I thought Sun leading the Java development should also be a better example on the Java coding convention.
    They do publish a coding convention guide, I believe. But looking at Java core library's source code, so long, coding convention! :(
    Just looked at ArrayList.java source for the version 1.4.2. There are method names like RangeCheck(). Shouldn't a method start with lowercase? Shouldn't a method be verb first like checkRange() instead?
    And there are statements like this all over the place:
    if (foo)
    bar();
    shouldn't that be:
    if (foo) {
    bar();
    man, I thought this golden version of the Java Foundation Library code should be almost perfect by this time now. :(
    --

    if (foo)
    bar();
    // I think the most important part of the if statement
    is the condition for executing the following
    statement(s).
    // Using this style the condition is separated from
    the code by white space which I find easier to read
    // It's also easier to maintain as you don't have to
    remember to add {} if you need to add additional
    statements.I follow camickr's example. I think it's more readable. Whitespace is a good thing, IMO, and not used enough. Putting the brace on the next line down not only makes it easier to associate opening and closing braces visually but it sets the block of code off visually from the rest. Personally, I get a gestalt effect from that.
    I don't worry about a byte here or there. It might sound like heresy, but Moore's Law makes memory and disk space cheaper and more plentiful all the time. I think maintainability and readability trumps being miserly about bytes in my thinking these days. ;)
    Spare me the "inefficiency" lectures. I know - performance matters. The 80/20 rule says that byte won't be killer.
    It's too bad that Sun doesn't follow their own conventions. Don't they do code review there?
    Joshua Bloch didn't follow the standard? Too bad - he did a great job on the collections design. Maybe he delegated it to a younger coder and missed that during the code review. Yeah, that's it! ;)

  • Java Coding Conventions -  Debugging

    I am developing a Coding Convention document for a group of folks that are doing some remote development for me and while I have reviewed the Java coding conventions provided by Sun, I haven't seen anything that talks specifically about debugging. I have been asked to include some recommendation concerning where (and when) to put debuggin messages within the code (i.e. when you enter a method, etc.) Are there any conventions around this? I have my own practices but I am looking to find a commonly used industry approach. Thanks

    By debugging messages you mean comments? This is all I found in the doc:
    "Use XXX in a comment to flag something that is bogus but works. Use FIXME to flag something that is bogus and broken."
    I doubt that helps :P As far as an industry standard, not much out there that I could find.

  • Where could I find java coding specification

    Where could I find java coding specification.
    I don't know what it really names for, I think it gives a principle for how to coding java program.
    For example, it will tell us which one is better between "final static" and "static final"

    For example, it will tell us which one is better
    between "final static" and "static final"neither of these, it's
    static public final
    Rules:
    first static as theses are class
    variables/methods that don't need instantiation. Then
    the non-static fields/methods. Therefore, "static"
    should be the first keyword for clean grouping.
    Then the visibility like public, protected,
    private (in this order) should be used. (see
    [url=http://java.sun.com/docs/codeconv/html/CodeConven
    tions.doc2.html#1852]Instance variables).Afterwards use final which should be the last
    keyword before the variable type / method return type
    / method parameter type, e.g.
    static public final doThis(final String key) {
    }If these are the "rules", then why is the convention for the main function
    public static void main(String[] args)?

  • Creating a New Folder in Windows Registry by java coding

    Good morning,
    hi to all,
    how can I create a New folder in Window Registry using Java coding. Can anybody help me out pls.
    I begin waiting for ur reply.
    Thanx

    Why do you feel you need to write to the Windows registry directly? Take a look at the Preferences class.
    {color:#0000ff}http://java.sun.com/javase/6/docs/api/java/util/prefs/Preferences.html{color}
    luck, db

  • How to activate a specific profile of the Firefox using java coding?

    Hi Folks,
    I have some query regarding activating the Profiles of the Firefox. Whenever i open the Firefox, the profile manager will be prompting for the profile to be activated. I want to perform such similar operation through java coding. Let us assume, I have three profiles named default, office and personal. I need to invoke the Firefox with a specific profile, office. How to proceed further? Your suggestion will be highly appreciated...
    Thanks in Advance,
    RealStuff, Mike

    String s = "Less than 20";
    while(s.length() < 20) {
         s += " ";
    System.out.println(s + " " + s.length());Mark

  • Mapping using Java Coding

    I've got a big trouble. First, I'm trying to do mapping using Java Coding based on the TopLink Developer's Guide.
    I'm using a Employee's Table as usual, but here is the problem, I can not do inserting on the database after I do mapping. As a note, there is no error compile and also I can do the session login already.
    Employee.java
    public class Employee extends oracle.toplink.sessions.Project{
         private Long id;
         private String fnama;
         private String lnama;
    public Employee() {
    setName("ObjectTab");
    applyLogin();
    addDescriptor(empDesc());
    conformAllDescriptors();
    public String getFnama() {
         return this.fnama;
    public String getLnama() {
         return this.lnama;
    public void setFnama(String fnama) {
         this.fnama = fnama;
    public void setLnama(String lnama) {
         this.lnama = lnama;
    public void applyLogin() {
    DatabaseLogin login = new DatabaseLogin();
    // use platform appropriate for underlying database
    login.usePlatform(
    new oracle.toplink.platform.database.oracle.Oracle9Platform());
    login.setDriverClassName("oracle.jdbc.OracleDriver");
    login.setConnectionString("jdbc:oracle:thin:localhost:1521:pusat");
    login.setUserName("tryo");
    login.setEncryptedPassword("a, ENCRYPTED");
    // Configuration Properties
    setDatasourceLogin(login);
    public ClassDescriptor empDesc() {
    ObjectRelationalDescriptor descriptor = new ObjectRelationalDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setTableName("EMPLOYEES");
    descriptor.setStructureName("EMPLOYEE_T");
    descriptor.setPrimaryKeyFieldName("ID");
    descriptor.addFieldOrdering("ID");
    descriptor.addFieldOrdering("F_NAME");
    descriptor.addFieldOrdering("L_NAME");
    descriptor.addDirectMapping("id", "OBJECT_ID");
    descriptor.addDirectMapping("fnama", "F_NAME");
    descriptor.addDirectMapping("lnama", "L_NAME");
    return descriptor;
    Main Class:
    protected String getSessionsXmlPath() {
    return "sessions.xml";
    protected String getSessionName() {
    return "Session";
    protected void createSession() {
    XMLSessionConfigLoader loader = new XMLSessionConfigLoader(getSessionsXmlPath());
    SessionManager mgr = SessionManager.getManager();
    session = (DatabaseSession)mgr.getSession(loader, getSessionName(), Thread.currentThread().getContextClassLoader(), true, true);
    public static void closeSession(){
    SessionManager.getManager().destroyAllSessions();
    session = null;
    private void jButton1_actionPerformed(ActionEvent e) {
    Employee myEmp = new Employee();
    createSession();
    private void jButton2_actionPerformed(ActionEvent e) {
    Employee theEmp = new Employee();
    UnitOfWork uow = session.acquireUnitOfWork();
    try{
    theEmp.setFnama("A");
    theEmp.setLnama("B");
    uow.commit();
    }finally{
    uow.release();
    For everybody who already knows the solution, please reply as soon as possible. Because I really need this solution to finish my last final project.
    Thanks

    When you create a new instance you must register it with the UnitOfWork in order to have the new entity persisted.
    Employee theEmp = new Employee();
    UnitOfWork uow = session.acquireUnitOfWork();
    theEmp.setFnama("A");
    theEmp.setLnama("B");
    uow.registerObject(theEmp);
    uow.commit();
    Doug

  • Java coding in combo box

    how to call the set of java coding by using combo box................

    Siva,
    Try avoiding opening different threads for the same questions...
    Combox Box date format
    You can use the option Edit/Reply to update your thread..
    -Anil

  • Java coding in CAF

    hi  experts,
    i went through lot of blogs and docs on SDN regarding how to compose services and consume services, export RFC etc.,. In some of the scenarios we needed to write some code in java. I am pretty much new to java even though i know basic java. what is the best way to learn what kind of java code i need to write when i create some CAF. is there any how-to-doc explaining most used java code in CAFs?
    thanks
    sankar

    Hi Sankar!
    I am not sure, what you are searching for. However, I will try to explain the CAF a little bit.
    Basically, a composite application consists of business objects and (entity and application) services.
    A business object represents a logical data structure your application is aiming at (e.g., customer, sales order). For each business object you get an entity service which operationes represent the fundamental database operations such as create, read, update, delete, and a number of find operations.
    On top of the entity services of your composite application you can model and implement application services. The operations of the application services represent the business logic of your application. These operations are where your Java coding comes into play.
    Finally, you can expose some of your application services as web services which can then be externally invoked.
    Best regards
    Alexander

  • Problem exposing Accessor Methods on View object (ViewRowImpl.java)

    JDeveloper 9.03
    I have a view link, ViewLinkSourceDest, that links two view objects Source and Destination. Each view object has its respective ViewRowImpl.java file created.
    I have selected "Generate Accessor in View Object" in View link Properties of the View Link Wizard for both source and destination view objects.
    The correct Accessor methods are available in both the source and destination ViewRowImpl files.
    When I access the Source accessor method from the DestinationViewRowImpl object I receive the following error:
              ORA-00904: invalid column name
              It is also is displaying the Source view object's SQL statement with the (:1 = Destination.ID) where clause.
    The error is occurring when trying to retrieve the view object using this type of method call:
              Row r = this.getSourceView();
    After further investigation I have found an example set of view objects in which the error does not occur. The difference was in the ViewLink.xml file.
    The ViewLink.xml file that accesses the Accessor with the error begins like this:
              <ViewLink     
                   Name="ViewLink"
                   Where=":1 = Destination._ID" >
    The ViewLink.xml file that accesses the Accessor with no error begins like this:
              <ViewLink     
                   Name="ViewLink"
                   EntityAssociation ="SourceDestAssociation" >
    suggesting that the use of an association would resolve this problem.
    I was not able to create a View link based on an association that would generate a ViewLink.xml file that ressemble the successful file above. I could however manually add the correct entry to the xml file that caused the error and sucessfully access the Accessor method in the source object. This is not the final answer because the IDE will regenerate the ViewLink.xml file to its original state even if created with the appropriate Association.
    Is this a bug?
    Is the way the ViewLink.xml file created different in JDev 9.03 than in 9.02
    Is there something I am missing that is causing the ViewLink.xml file to generate incorrectly?
    Any suggestions would be helpful.
    Rob

    Steps to recreate:
    1 Create SomeSuperEntityImpl.java extended by SourceEntityImpl.java and DestinationEntityImpl.java entity objects.
    2 Create SourceView and DestinationView objects
    3 Create SourceDestinationAssociation linking the entity object Source PK to Destination FK
    4 Create SourceDestinationView linking Source and Destination view using the SourceDestinationAssociation
    View the SourceDestinationView.xml file and you will see that the viewlink has Where=":1 = source.src_id"
    This is the scenario that causes the initial problem with the Accessor Methods.
    If the SomeSuperEntityImpl.java is removed as the super class and the same procedure is followed you will get the desired 'EntityAssociation = "package.SourceDestinationAssociation"' in the SourceDestinationView.xml file .
    Hope this is a little clearer.
    Rob

  • How to find RFC names in e-commerce application JSPs or in Java coding.

    Hi Experts.
    Please explain me ,how to find RFC names which were used in e-commerce b2b/b2c applications in Java coding using SAP NWDS IDE.
    Thanks in Advance!!!!
    Regards,
    Kiran

    There are two ways to do this.
    I. Create your own Session Log file
    1. Go to http://url:port/b2b/admin/index.jsp
    2. Login with Admin user id and password.
    3. Click on 'Logging' from the left hand navigation
    4. Click on 'Session Logging' tab
    Here you can start your e-commerce application using a URL and 'Start' session logging when you need it. When you 'Stop' the session logging, you will see a log file for download.
    II. View ISA Log files in the system
    The path varies based on how the log config was done. But usually, if you look in this folder structure on the Java Stack, you will see log files.
    .../JC00/j2ee/cluster/server0/log/applications/..
    I hope this helps.
    Pavan

  • How to increase the Java Heap size ?

    Hi
    I am new to java. I have created a java application and i configured in Eclipse. While running my application it throws an error that
    "Exception in thread "Thread-21" java.lang.OutOfMemoryError: Java heap space"
    i have used threads in my application. Then i searched some forums regarding this. The answer i got is "Increase the java heap size" using
    "java -Xms64m -Xmx256m prog" in command prompt. while running.
    But i am not running my application in command prompt. I used Eclipse to run my application. Here my ultimate question is how to set the heap size while running the application in Eclipse and where to set in Eclipse.
    Kindly help me.
    Regards
    Ramesh E

    i have used 20 threads to extract the datas
    Then parallel i am starting one more thread to process the data. Means that i am starting 21st thread. In thread is throwing the error.
    20 threads:
    for (int i = 0; i < 20; i++) {
    try{
    extrThreads[i] = new Thread(this);
    extrThreads.start();
    }catch (Exception e) {
    System.out.println(e);
    21st Thread:
    public void processdata()throws Exception{
    Thread t = new Thread(this);
    t.start();
    if(t!= null)
    t.join();
    funtion();
    This thread is throwing the error

  • Displaying Arabic URL in a JAVA CODED WEB BROWSER

    Hello everyone,
    Please if there is anyone who can help me with Java Code....I have a java coded web browser, but i would like to enable Arabic .... currently, when arabic is typed into the URL bar, it appears at 'square boxes'...i would like example code on how to remedy that problem, so that when a user enters a url in arabic it displays the correct characters...Also, is there a simple code to check the 'hostname' (basically the name entered in the URL bar) whether or not it is in Arabic or not....
    Mucho Gracias in advance, any help would be More than appreciated...
    thanks ....
    email:[email protected]

    I thought it is possible to treat it like JTextArea where a user
    can type in unicode characters....however on IE you can type in arabic (after the keyboard shift CTRL or ALT shift)in the URL bar...however in my little browser you cannot do that....is there anyway to enable that to happen...
    once again thanks in advance....
    oh and for the string check, is there something like :
    host.equalsIgnoreCase('to any unicode characters');
    i tried it using \u06xx but to no avail....
    please any help!! id appreciate it....
    -betterhopes

  • Java coding standard- Number of methods in a class

    Can anybody please tell me that what is the standard range for number of methods in a class. I need to refcator a very old code which contains large number of methods (50 to 100) in each class. Please help.

    I got a huge screen and uses a small font ;)I have a wiiiiide screen. :D What's the maximum number of statements in a line?
    I think that a method starts to get long when it's
    more than 20 lines.Yepp, but I usually don't count line wraps. I'm not going to create another method for something like
    if (abc == null
      && xyz == 17
      && udsfh == false
      try {
        whatever();
      } catch (StupidExceptionA e) {
      } catch (StupidExceptionB e) {
      } catch (StupidExceptionC e) {
      } catch (StupidExceptionD e) {
    }It's annoying, but it also looks stupid to have a method that does nothing else but calling another method and catching the exceptions. That clutters the entire class.

Maybe you are looking for