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.

  • Common Java Problems: Parenthesis, Brackets, Braces, etc. mis-match

    Problem description: Parenthesis, Brackets, Braces, etc. mis-match
    Problem category: Compile-time Problems

    Diagnosis Difficulty: Easy
    Difficulty to Fix: Easy


    This problem occurs when you forget to close an open parenthesis/etc., or accidentally put too many closing parenthesis/etc.

    Missing closing ]
    public class Test
    {
    	public static void main(String[ args)
    	{
    	}
     
    	public static void doIt()
    	{
     
    	}
    }

    Too many closing parenthesis

    public class Test
    {
    	public static void main(String[] args)
    	{
    		int a = (1 + 2) / (3 + 4));
    	}
    }

    Error Messages

    In general, the error messages produced for this type of problem are very similar. Here's an example error message for the first piece of problem code. Sometimes the compiler might spit out the wrong location of the problem because it's matching different parenthesis/etc.

    The best way to detect these problems is to properly format your code. See: http://java.sun.com/docs/codeconv/CodeConventions.pdf

    Test.java:3: ']' expected
    public static void main(String[ args)
    Suggested fixes

    Add/remove the appropriate syntax marker.

    Missing closing ]
    public class Test
    {
    	public static void main(String[] args)
    	{
    	}
     
    	public static void doIt()
    	{
     
    	}
    }

    Too many closing parenthesis

    public class Test
    {
    	public static void main(String[] args)
    	{
    		int a = (1 + 2) / (3 + 4);
    	}
    }
    This article was originally published in forum thread: Common Java Mistakes started by helloworld922 View original post