Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: eclipse help

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default eclipse help

    after executing this code in eclipe:
    public class Main {
     
    	public static void main(String args[]){
     
    		Course x=new Course();
     
    		Activity y=new Activity();
    		String input="[B]ali[/B]";
    		x.register(input);
    		y.registerA(input);
    		System.out.println(input);
     
    	}
     
    }
    //register and registerA methods details are ommited

    the results from the program are true
    but after doing this modifying (use arguments from the command line instead):

    public class Main {
     
    	public static void main(String args[]){
     
    		Course x=new Course();
     
    		Activity y=new Activity();
    		String input=args[0];
    		x.register(input);
    		y.registerA(input);
    		System.out.println(input);
     
    	}
     
    }
    the results are incorrect although i have passed the same argument (ali) from :
    run>run configurations>arguments tab

    please help me


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: eclipse help

    My bets guess is that within your implementation of register() and registerA() you have used something like String == String. Rather than String.equals(String).

    Regards,
    Chris

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: eclipse help

    thanks alot

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: eclipse help

    but if we assume the rest of the code as following:
    public class Main {
     
    	public static void main(String args[]){
     
    		Course x=new Course();
     
    		Activity y=new Activity();
    		String [B]input[/B]=args[0];
    		x.register(input);
    		y.registerA(input);
    	}
     
    }
     
    public class Course {
    Names n=new Names();
    public void register(String k){
    	n.check(k);	
    }
    }
     
    public class Activity extends Course{
     
    	public void registerA(String e){
     
    		n.checkA(e);
    	}
     
    }
     
    public class Names {
    	int i;
     
    	String[] [B]list[/B]={"mos","mona","ali"};
    	Result m=new Result();
    	void check(String s){
     
    		for(i=0;i<=2;i++){
    			if (list[i]==s) {m.success();
    			break;
    			}
    			else if (i==2) {
    				m.fail();}
    			else {
    				continue;
    			}
     
    		}
     
    	}
     
    	void checkA(String b){
     
    		for(i=0;i<=2;i++){
    			if (list[i]==b) {m.successA();
    			break;
    			}
    			else if (i==2) {m.failA();}
    			else {
    				continue;
    			}
     
    		}
     
    	}
     
    	}
     
    public class Result {
    	public void success(){
    		System.out.println("reg in course");}
    	public void fail(){
    		System.out.println("u r not registered");
    	}
    	public void failA(){
    		System.out.println("u r not registered in act");
    	}
    	public void successA(){
    		System.out.println("in the act");
    	}
     
    }

    why the compiler assumed that the reference to the element value in the list array is equals to the reference of the "input" object when the value actually referenced by the array?? you have an illustration to this??
    Last edited by helloworld922; November 25th, 2009 at 12:49 AM.

Similar Threads

  1. Replies: 24
    Last Post: August 4th, 2014, 12:49 PM
  2. List of shortcuts key for Eclipse
    By Flash in forum Java JDK & IDE Tutorials
    Replies: 3
    Last Post: July 18th, 2013, 08:40 AM
  3. How to add JSF libraries to eclipse?
    By tien1504 in forum Java IDEs
    Replies: 5
    Last Post: October 24th, 2012, 04:32 PM
  4. About plugins for eclipse
    By sun26 in forum Java IDEs
    Replies: 1
    Last Post: November 20th, 2009, 09:43 AM
  5. WAR file creation in Eclipse JEE
    By katty in forum Java IDEs
    Replies: 5
    Last Post: May 21st, 2009, 09:45 AM