What is hard coding in Java?




First off, let’s clarify that hard coding is a term that applies to all programming languages and not just Java. So, what is hard coding? Well, it refers to the practice of using actual data values (as in actual numbers or strings like 3 or “abcd”) in the source code when instead what should be used are variables that accept any input value. There are definitely some situations when hard coding values may be necessary, but generally it is looked down upon as a negative practice that should be avoided whenever possible.

Why is it called hard coding?

The reason it is called hardcoding is because of the fact that the practice reduces the flexibility of the code by forcing actual values into the source code.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.

  • I don’t see the huge divide between “programming” and “computing” that others see. Of course, the student programming that I see is all problem solving, not rote exercises. Students can fail at the programming in many different ways (poorly chosen data structures, poorly chosen program organization, poorly chosen algorithms, incorrect coding of algorithms, bad documentation, non-idiomatic use of the programming language, …). I see very high correlations between these different failure modes—I don’t have large enough samples to do factor analysis, but I suspect that I would see primarily one factor for programming skill, with a minor second factor for completeness of documentation. I doubt very much that I’d be able to associate one factor with “programming” and another with “computing”.

  • Sukhbir

    nice i like appericiate all questions