Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:51:43+00:00 2026-06-11T21:51:43+00:00

I know I can use the comma operator like this for (int i =

  • 0

I know I can use the comma operator like this

for (int i = 1, j = 15; j>10; i++, j--) {
    // do something neat
}

but some articles seem to suggest that the comma operator can be used outside of the for loop declaration, for example

int j = 2, k = 4 ;
int x ;
// Assignment statement with comma operator
x = j + 1, k ;

source: http://www.cs.umd.edu/~clin/MoreJava/ControlFlow/comma.html

or

int x = (expression) ? (i++,2) : 3;

source: https://stackoverflow.com/a/12047433/1084813

This would be a neat trick for a code obfuscation contest or to confuse my colleagues, but neither of the examples will compile (Java 1.6, Eclipse Juno), the error is “The left-hand side of an assignment must be a variable”. I tried looking at the compiler settings to see whether it could be forbidden to prevent bad code, but without luck.

What’s wrong? Was the comma operator a part of an older specification which later changed? Are the people that wrote those examples using a different Java setup that allows this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:51:44+00:00Added an answer on June 11, 2026 at 9:51 pm

    What’s wrong?

    Some of the tricks which work in C don’t work in Java.

    Was the comma operator a part of an older specification which later changed?

    This never worked in Java AFAIK.

    Are the people that wrote those examples using a different Java setup that allows this?

    Its a common mistake to assume Java is just like C or C++ because it is similar. A good portion of coding mistakes on SO are due to people trying to write C++ in Java and getting confused when it doesn’t do what they expect.

    BTW: I have made the same mistake assuming C++ is just like Java as my knowledge of C++ is not current.


    However some tricks which working Java but perhaps not C.

    You can use all currency symbols or which there are a few which look at most the same.

    e.g.

    if( ⁀ ‿ ⁀ == ⁀ ⁔ ⁀ || ¢ + ¢== ₡)
    

    You can use character which are invisible and c couple which reverse the order the rest of the line when printed. 😉

    This program compiles and runs and prints all the odd characters you can use in Java identifiers

    for (char c‮h = 0; c‮h < Character.MAX_VALUE; c‮h++)
        if (Character.isJavaIdentifierPart(c‮h) && !Character.isJavaIdentifierStart(c‮h))
            System.out.printf("%04x <%s>%n", (int) c‮h, "" + c‮h);
    

    which makes its almost too easy.

    http://vanillajava.blogspot.co.uk/2012/08/uses-for-special-characters-in-java-code.html

    http://vanillajava.blogspot.co.uk/2012/09/hidden-code.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I can use something like User.sort {|a, b| a.attribute <=> b.attribute} or
I don't know if Matlab can do this, but I want to store some
I know you can use source control software for source code, but can you
I know I can use Request.Browser.IsMobileDevice . But does anyone know how it works,
I know YQL can query CSV (comma separated values) format text files. But often
I know I can use the -n flag in git grep to show the
I know you can use -fno-objc-arc flag to disable ARC for files that NOT
I know I can use install-data-hook to do anything I want after my data
I know I can use the ActionView helper strip_tags method in my views to
I know I can use the RODBC library for accessing excel (.xls) docs from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.