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 8247549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:53:01+00:00 2026-06-07T22:53:01+00:00

Possible Duplicate: How to find out if “debug mode” is enabled Coming from C#,

  • 0

Possible Duplicate:
How to find out if “debug mode” is enabled

Coming from C#, I cannot believe that Java has no way to execute code only when the program is being debugged. Somehow, Log4J seems to be able to do it. Does anyone know a possibility for this? I’m thinking of something like this:

#if DEBUG
    executedCode();
#endif

Or something like this:

if (Java.isDebugging())
    executeCode();

Ideas?

EDIT: Thanks to Matt Ball, the code in this possible duplicate works:

public static boolean debugging = java.lang.management.ManagementFactory.getRuntimeMXBean().
        getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
  • 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-07T22:53:03+00:00Added an answer on June 7, 2026 at 10:53 pm

    I think you are conflating a debug build of a program with running under the debugger (unless C# is rather strange).

    Many systems – including lots of C/C++ build environments, and I expect C#, given the way Microsoft has historically designed the Visual Studio build processes – have two different types of builds you can do:

    • Release build, with only info/error/warning logging, no debug symbols, extra optimizations, etc.
    • Debug build, with extra logging enabled, debug symbols, possibly tuned-down optimizations.

    You use debug builds while developing and debugging your program, and release builds for final QA and release. The debug builds, however, are independent of being run under a debugger – they’re normal programs, and if you run them the run and still output their extra logging information. This can be very useful.

    Running them under a debugger is completely orthogonal. You can run the release build under a debugger (although, lacking debug symbols, it might not be very useful). In fact, I would submit that you do not want code to change based on whether you are running under a debugger – it makes it rather difficult to debug the code being actually run in the application.

    And unlike C, C++, and C#, Java has no facility for compile-time conditionals, so everything is enabled in the program. You typically deal with this by having a very fast way to check if the debugging message is to be emitted, and doing as little work as possible in the case where it is not.

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

Sidebar

Related Questions

Possible Duplicate: Java Class.cast() vs. cast operator I am unsuccessfully trying to find out
Possible Duplicate: Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”' I'm hoping this is
Possible Duplicate: Find out the instance id from within an ec2 machine I am
Possible Duplicate: How to find out where a function is defined? get filename of
Possible Duplicate: On iPhone: Find out what song is currently playing? (in the iPod
Possible Duplicate: How to find out where a function is defined? I am working
Possible Duplicate: JSON Parsing in Android As I find out I need to use
Possible Duplicate: Automatic counter in Ruby for each? I want to find out the
Possible Duplicate: How to find out where a function is defined? included php file
Possible Duplicate: Learning to write a compiler I looked around trying to find out

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.