1. Java is free form language explain why?
Java is considered a free-form language because its syntax allows for significant
flexibility in how code is formatted, particularly concerning whitespace.
1. Whitespace Insensitivity: In Java, whitespace (spaces, tabs, and newlines) is
generally ignored in terms of the program's structure. This means that you can
format your code in various ways without affecting its functionality. For example,
you can put multiple statements on a single line or spread them across multiple
lines.
2. Braces for Block Structure: Java uses curly braces {} to define blocks of code (like
classes, methods, and loops). This allows developers to structure their code in a
way that is visually appealing and easy to read, without being constrained by strict
formatting rules.
3. Semicolon Terminators: Statements in Java are typically terminated with a
semicolon ;, which means that you can choose to write statements on the same
line or separate them across different lines, as long as the semicolons are
correctly placed.
4. Indentation and Formatting: While Java itself does not require specific
indentation or formatting, good practices encourage consistent use of indentation
to improve readability.
5. Comments and Documentation: Java supports single-line (//) and multi-line (/* ...
*/) comments, allowing developers to document their code in a way that suits their
preferences, further enhancing the free-form nature.