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.


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

Results 1 to 2 of 2

Thread: My code return null, Why?

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Thanked 0 Times in 0 Posts

    Default My code return null, Why?

    In the Main class I have the following
    public class test {
        public static void main(String args[]){
            String separ;
            String lin = "/";
            String wind = "\\";
            String s = System.getProperty("file.separator");
            if (s != wind) 
              FileSeparatorExample.separator = lin;

    in the another class
    public class FileSeparatorExample {
         * @param args the command line arguments
      public static String separator;
      public static String a ;
      public FileSeparatorExample(){
          this.a = FileSeparatorExample.separator;
      public static void lodA(){
          a = separator;
          return  ;

    Why System.out.println(FileSeparatorExample.a);
    return me "null"
    how to fix?
    I am a new in java, please help me!!!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: My code return null, Why?

    Do you understand how the static keyword works? Do you understand how constructors are called?

    Why are separator and a static? When do you set separator? When do you set a?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 4
    Last Post: February 26th, 2012, 05:36 PM
  2. string==null or string.equals(null) problem
    By csharp100 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: November 4th, 2011, 08:17 AM
  3. Return Object does not return the expected output
    By Nour Damer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2011, 07:24 AM
  4. Replies: 5
    Last Post: July 7th, 2011, 09:22 AM
  5. how to return value ..
    By gr8mind in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 11th, 2011, 05:27 AM