Java code conventions

Java code conventions

Π Π΅ΠΊΠΎΠΌΠ΅Π½Π΄Π°Ρ†ΠΈΠΈ ΠΊ ΡΡ‚ΠΈΠ»ΡŽ ΠΊΠΎΠ΄Π°

ΠŸΡ€Π°Π²ΠΈΠ»Π° языка Java

ΠŸΡ€Π°Π²ΠΈΠ»Π° Java Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊ

Π‘ΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‚ соглашСния, ΠΏΠΎ ΠΏΠΎΠ²ΠΎΠ΄Ρƒ использования Java Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊ ΠΈ инструмСнтов для Android. Π’ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… случаях соглашСния ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½Ρ‹, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Π² Ρ‚Π°ΠΊΠΈΡ… ΠΊΠ°ΠΊ использованиС старого ΠΊΠΎΠ΄Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ, Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Π½Π΅ΠΎΠ΄ΠΎΠ±Ρ€Π΅Π½Π½Ρ‹ΠΉ ΠΏΠ°Ρ‚Ρ‚Π΅Ρ€Π½ ΠΈΠ»ΠΈ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΡƒ.

ΠŸΡ€Π°Π²ΠΈΠ»Π° Java стиля

ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ Π³ΠΎΡ€Π°Π·Π΄ΠΎ ΠΏΡ€ΠΎΡ‰Π΅ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Ρ‚ΡŒ, ΠΊΠΎΠ³Π΄Π° всС Ρ„Π°ΠΉΠ»Ρ‹ ΠΈΠΌΠ΅ΡŽΡ‚ согласованный ΡΡ‚ΠΈΠ»ΡŒ. ΠœΡ‹ слСдуСм стандартному ΡΡ‚ΠΈΠ»ΡŽ программирования Π½Π° Java, ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΌΡƒ Sun Π² ΠΈΡ… Code Conventions for the Java Programming Language, с нСсколькими ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡΠΌΠΈ ΠΈ дополнСниями. Π”Π°Π½Π½ΠΎΠ΅ руководство ΠΏΠΎ ΡΡ‚ΠΈΠ»ΡŽ являСтся ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½Ρ‹ΠΌ ΠΈ всСсторонним, Π° Ρ‚Π°ΠΊΠΆΠ΅ ΡˆΠΈΡ€ΠΎΠΊΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Java сообщСством.

ΠŸΡ€Π°Π²ΠΈΠ»Π° языка Java

НС ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΡƒΠΉΡ‚Π΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ

Π’ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, Π²Π°ΠΌ захочСтся Π½Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΊΠΎΠ΄, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€:

НС ΠΏΠ΅Ρ€Π΅Ρ…Π²Π°Ρ‚Ρ‹Π²Π°ΠΉΡ‚Π΅ ΠΎΠ±ΠΎΠ±Ρ‰Π΅Π½Π½Ρ‹Π΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ

Иногда Π±Ρ‹Π²Π°Π΅Ρ‚ Π·Π°ΠΌΠ°Π½Ρ‡ΠΈΠ²ΠΎ ΠΏΠΎΠ»Π΅Π½ΠΈΡ‚ΡŒΡΡ с ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΠΎΠΉ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΉ ΠΈ Π½Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‡Ρ‚ΠΎ-Ρ‚ΠΎ Π²Ρ€ΠΎΠ΄Π΅ этого:

Π’Π°ΠΌ Π½Π΅ слСдуСт Ρ‚Π°ΠΊ Π΄Π΅Π»Π°Ρ‚ΡŒ. Π‘ΡƒΡ‚ΡŒ Π² Ρ‚ΠΎΠΌ, Ρ‡Ρ‚ΠΎ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ появлСниС ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ Π²Ρ‹ Π½Π΅ ΠΎΠΆΠΈΠ΄Π°Π»ΠΈ ΠΈ, Π² ΠΈΡ‚ΠΎΠ³Π΅, ошибка Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΡ‚Π»Π°Π²Π»ΠΈΠ²Π°Ρ‚ΡŒΡΡ Π½Π° ΡƒΡ€ΠΎΠ²Π½Π΅ прилоТСния. Π’ΠΎ Π΅ΡΡ‚ΡŒ, Ссли ΠΊΡ‚ΠΎ-Ρ‚ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ Π½ΠΎΠ²Ρ‹ΠΉ Ρ‚ΠΈΠΏ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ, Ρ‚ΠΎ компилятор Π½Π΅ смоТСт Π²Π°ΠΌ ΠΏΠΎΠΌΠΎΡ‡ΡŒ ΠΏΠΎΠ½ΡΡ‚ΡŒ, Ρ‡Ρ‚ΠΎ это другая ошибка.

Π‘ΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‚ Ρ€Π΅Π΄ΠΊΠΈΠ΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ ΠΈΠ· этого ΠΏΡ€Π°Π²ΠΈΠ»Π°: ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½Ρ‹ΠΉ тСстовый ΠΊΠΎΠ΄, ΠΈΠ»ΠΈ ΠΊΠΎΠ΄ Π²Π΅Ρ€Ρ…Π½Π΅Π³ΠΎ уровня, Π³Π΄Π΅ Π²Ρ‹ Ρ…ΠΎΡ‚ΠΈΡ‚Π΅ ΠΏΠ΅Ρ€Π΅Ρ…Π²Π°Ρ‚Ρ‹Π²Π°Ρ‚ΡŒ всС Ρ‚ΠΈΠΏΡ‹ ошибок (для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΡ€Π΅Π΄ΠΎΡ‚Π²Ρ€Π°Ρ‚ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π² ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΎΠΌ интСрфСйсС, ΠΈΠ»ΠΈ Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠΈΡ‚ΡŒ ΠΊΠ°ΠΊΡƒΡŽ-Ρ‚ΠΎ ΠΏΠ°ΠΊΠ΅Ρ‚Π½ΡƒΡŽ Π·Π°Π΄Π°Ρ‡Ρƒ).

Π€ΠΈΠ½Π°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Ρ‹

Π§Ρ‚ΠΎ это: Π€ΠΈΠ½Π°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Ρ‹ β€” это способ Π·Π°ΠΏΡƒΡΠΊΠ°Ρ‚ΡŒ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ ΠΊΠΎΠ΄ ΠΏΠ΅Ρ€Π΅Π΄ Ρ‚Π΅ΠΌ ΠΊΠ°ΠΊ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ собираСтся сборщиком мусора.
Π—Π°: ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΠΎΠ»Π΅Π·Π½Ρ‹ ΠΏΡ€ΠΈ очисткС, Π² особСнности Π²Π½Π΅ΡˆΠ½ΠΈΡ… рСсурсов.
ΠŸΡ€ΠΎΡ‚ΠΈΠ²: Π½Π΅Ρ‚ Π½ΠΈΠΊΠ°ΠΊΠΈΡ… Π³Π°Ρ€Π°Π½Ρ‚ΠΈΠΉ Ρ‚ΠΎΠ³ΠΎ, ΠΊΠΎΠ³Π΄Π° Π±ΡƒΠ΄Π΅Ρ‚ Π²Ρ‹Π·Π²Π°Π½ Ρ„ΠΈΠ½Π°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€, ΠΈ, Π²ΠΎΠΎΠ±Ρ‰Π΅, Π±ΡƒΠ΄Π΅Ρ‚ Π»ΠΈ ΠΎΠ½ Π²Ρ‹Π·Π²Π°Π½.

РСшСниС: ΠœΡ‹ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ Ρ„ΠΈΠ½Π°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Ρ‹. Π’ Π±ΠΎΠ»ΡŒΡˆΠΈΠ½ΡΡ‚Π²Π΅ случаСв, всё Ρ‚ΠΎ, Ρ‡Ρ‚ΠΎ Π²Π°ΠΌ Π½ΡƒΠΆΠ½ΠΎ ΠΎΡ‚ Ρ„ΠΈΠ½Π°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Π°, Π²Ρ‹ смоТСтС ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ΠΏΡ€ΠΈ ΠΏΠΎΠΌΠΎΡ‰ΠΈ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΉ. Если Π²Π°ΠΌ Π΄Π΅ΠΉΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Π½ΡƒΠΆΠ΅Π½ Ρ„ΠΈΠ½Π°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€, Ρ‚ΠΎ ΠΎΠ±ΡŠΡΠ²ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΎΠ΄ close() ΠΈ Π·Π°Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅, ΠΊΠΎΠ³Π΄Π° ΠΎΠ½ Ρ‚ΠΎΡ‡Π½ΠΎ Π±ΡƒΠ΄Π΅Ρ‚ Π²Ρ‹Π·Ρ‹Π²Π°Ρ‚ΡŒΡΡ.

Π˜ΠΌΠΏΠΎΡ€Ρ‚Ρ‹
Π“Ρ€ΡƒΠΏΠΏΠΎΠ²ΠΎΠΉ символ Π² ΠΈΠΌΠΏΠΎΡ€Ρ‚Π°Ρ…

Π§Ρ‚ΠΎ это: Когда Π²Ρ‹ Ρ…ΠΎΡ‚ΠΈΡ‚Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ класс Bar ΠΈΠ· ΠΏΠ°ΠΊΠ΅Ρ‚Π° foo, Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ Π΄Π²Π° способа ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ это:

Π—Π° #1: ΠŸΠΎΡ‚Π΅Π½Ρ†ΠΈΠ°Π»ΡŒΠ½ΠΎ ΡƒΠΌΠ΅Π½ΡŒΡˆΠ°Π΅Ρ‚ количСство Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹Ρ… ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ² ΠΈΠΌΠΏΠΎΡ€Ρ‚Π°.
Π—Π° #2: Π”Π΅Π»Π°Π΅Ρ‚ явным Ρ‚ΠΎ, ΠΊΠ°ΠΊΠΎΠΉ класс Π½Π° самом Π΄Π΅Π»Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ. Π”Π΅Π»Π°Π΅Ρ‚ ΠΊΠΎΠ΄ Π±ΠΎΠ»Π΅Π΅ ΡƒΠ΄ΠΎΠ±ΠΎΡ‡ΠΈΡ‚Π°Π΅ΠΌΡ‹ΠΌ для Ρ‚Π΅Ρ…, ΠΊΡ‚ΠΎ Π΅Π³ΠΎ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚.

РСшСниС: Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΡΡ‚ΠΈΠ»ΡŒ #2 для ΠΈΠΌΠΏΠΎΡ€Ρ‚Π° любого Android ΠΊΠΎΠ΄Π°. Π―Π²Π½ΠΎΠ΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ дСлаСтся для стандартных Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊ (java.util.*, java.io.*, ΠΈ Ρ‚.ΠΏ) ΠΈ для ΠΊΠΎΠ΄Π° ΠΌΠΎΠ΄ΡƒΠ»ΡŒΠ½ΠΎΠ³ΠΎ тСстирования (junit.framework.*).

ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ/Javadoc

ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ„Π°ΠΉΠ» Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ объявлСниС ΠΎΠ± авторских ΠΏΡ€Π°Π²Π°Ρ… Π² самом Π½Π°Ρ‡Π°Π»Π΅. Π”Π°Π»Π΅Π΅ ΠΈΠ΄ΡƒΡ‚ объявлСния ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ² package ΠΈ import, ΠΏΡ€ΠΈΡ‡Π΅ΠΌ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ Π±Π»ΠΎΠΊ раздСляСтся пустой строкой. Π—Π° Π½ΠΈΠΌΠΈ ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ объявлСния класса ΠΈΠ»ΠΈ интСрфСйса. ΠžΠΏΠΈΡˆΠΈΡ‚Π΅, Ρ‡Ρ‚ΠΎ Π΄Π΅Π»Π°Π΅Ρ‚ класс Π² Javadoc-коммСнтариях.

ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ класс ΠΈ Π½Π΅Ρ‚Ρ€ΠΈΠ²ΠΈΠ°Π»ΡŒΠ½Ρ‹ΠΉ public ΠΌΠ΅Ρ‚ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ Javadoc, ΠΏΠΎ ΠΊΡ€Π°ΠΉΠ½Π΅ΠΉ ΠΌΠ΅Ρ€Π΅ с ΠΎΠ΄Π½ΠΎΠΉ Ρ„Ρ€Π°Π·ΠΎΠΉ, ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‰Π΅ΠΉ Ρ‡Ρ‚ΠΎ ΠΎΠ½ Π΄Π΅Π»Π°Π΅Ρ‚. Π€Ρ€Π°Π·Π° Π΄ΠΎΠ»ΠΆΠ½Π° Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с ΠΎΠΏΠΈΡΠ°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ Π³Π»Π°Π³ΠΎΠ»Π° 3-Π³ΠΎ Π»ΠΈΡ†Π°. ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹:

Π’Π°ΠΌ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ ΠΎΠΏΠΈΡΡ‹Π²Π°Ρ‚ΡŒ Javadoc для Ρ‚Ρ€ΠΈΠ²ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… get ΠΈ set ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ², Ρ‚Π°ΠΊΠΈΡ… ΠΊΠ°ΠΊ setFoo(), Ссли ваш Javadoc Π³ΠΎΠ²ΠΎΡ€ΠΈΡ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Β«sets FooΒ». Если ΠΌΠ΅Ρ‚ΠΎΠ΄ Π΄Π΅Π»Π°Π΅Ρ‚ Ρ‡Ρ‚ΠΎ-Ρ‚ΠΎ Π±ΠΎΠ»Π΅Π΅ слоТноС (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, соблюдСниС Π½Π΅ΠΊΠΈΡ… ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠΉ, ΠΈΠ»ΠΈ Ссли Π΅Π³ΠΎ дСйствия ΠΈΠΌΠ΅ΡŽΡ‚ Π²Π°ΠΆΠ½Ρ‹ΠΉ эффСкт Π²Π½Π΅ Π΅Π³ΠΎ самого), Ρ‚ΠΎΠ³Π΄Π° Π΅Π³ΠΎ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ Π½ΡƒΠΆΠ½ΠΎ Π·Π°Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ. И Ссли это Π½Π΅ просто объяснСниС Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎ ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚ Foo, Ρ‚ΠΎ Π²Π°ΠΌ Ρ‚Π°ΠΊΠΆΠ΅ слСдуСт Π΅Π³ΠΎ Π·Π°Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ.

Π’ΠΎΠΎΠ±Ρ‰Π΅, любой ΠΌΠ΅Ρ‚ΠΎΠ΄, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π²Ρ‹ написали ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ ΠΏΠΎΠ»ΡŒΠ·Ρƒ ΠΎΡ‚ Javadoc, Π½Π΅Π²Π°ΠΆΠ½ΠΎ public ΠΎΠ½ ΠΈΠ»ΠΈ Π½Π΅Ρ‚. Public ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ ΡΠ²Π»ΡΡŽΡ‚ΡΡ Ρ‡Π°ΡΡ‚ΡŒΡŽ API, ΠΈ поэтому ΠΎΠ½ΠΈ Ρ‚Ρ€Π΅Π±ΡƒΡŽΡ‚ описания Π² Javadoc.

Для написания Javadoc’ΠΎΠ² Π²Π°ΠΌ слСдуСт ΠΏΡ€ΠΈΠ΄Π΅Ρ€ΠΆΠΈΠ²Π°Ρ‚ΡŒΡΡ Sun Javadoc conventions.

ΠšΠΎΡ€ΠΎΡ‚ΠΊΠΈΠ΅ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹

ΠœΠ΅Ρ‚ΠΎΠ΄Ρ‹ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ нСбольшими ΠΈ Ρ€Π΅ΡˆΠ°ΡŽΡ‰ΠΈΠΌΠΈ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΡƒΡŽ Π·Π°Π΄Π°Ρ‡Ρƒ Π½Π°ΡΡ‚ΠΎΠ»ΡŒΠΊΠΎ, насколько это Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ. Однако, понятно, Ρ‡Ρ‚ΠΎ ΠΈΠ½ΠΎΠ³Π΄Π° большиС ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ Π±Ρ‹Π²Π°ΡŽΡ‚ цСлСсообразны, Ρ‚Π°ΠΊ Ρ‡Ρ‚ΠΎ Π½Π΅Ρ‚ строгого ограничСния Π½Π° Π΄Π»ΠΈΠ½Ρƒ ΠΌΠ΅Ρ‚ΠΎΠ΄Π°. Если ΠΌΠ΅Ρ‚ΠΎΠ΄ ΠΏΡ€Π΅Π²Ρ‹ΡˆΠ°Π΅Ρ‚ 40 строк, Ρ‚ΠΎ Π²Π°ΠΌ, Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, стоит ΠΏΠΎΠ΄ΡƒΠΌΠ°Ρ‚ΡŒ ΠΎ Ρ‚ΠΎΠΌ, ΠΌΠΎΠΆΠ½ΠΎ Π»ΠΈ Π΅Π³ΠΎ Ρ€Π°Π·Π±ΠΈΡ‚ΡŒ Π½Π° части, Π½Π΅ Π½Π°Ρ€ΡƒΡˆΠΈΠ² структуры ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹.

Π›ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅

ΠžΠ±Π»Π°ΡΡ‚ΡŒ видимости Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… Π΄ΠΎΠ»ΠΆΠ½Π° ΡΠ²ΠΎΠ΄ΠΈΡ‚ΡŒΡΡ ΠΊ ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌΡƒ. ДСлая это, Π²Ρ‹ ΡƒΠ»ΡƒΡ‡ΡˆΠ°Π΅Ρ‚Π΅ Ρ‡ΠΈΡ‚Π°Π΅ΠΌΠΎΡΡ‚ΡŒ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΠΎΡΡ‚ΡŒ ΠΊΠΎΠ΄Π°, Π° Ρ‚Π°ΠΊΠΆΠ΅ ΡƒΠΌΠ΅Π½ΡŒΡˆΠ°Π΅Ρ‚Π΅ Π²Π΅Ρ€ΠΎΡΡ‚Π½ΠΎΡΡ‚ΡŒ ошибок. КаТдая пСрСмСнная Π΄ΠΎΠ»ΠΆΠ½Π° ΠΎΠ±ΡŠΡΠ²Π»ΡΡ‚ΡŒΡΡ Π² самом Π³Π»ΡƒΠ±ΠΎΠΊΠΎΠΌ Π±Π»ΠΎΠΊΠ΅, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΠΊΡ€ΡƒΠΆΠ°Π΅Ρ‚ всС Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹Π΅ мСста использования ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ.

Π›ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΎΠ±ΡŠΡΠ²Π»ΡΡ‚ΡŒΡΡ Π² Ρ‚ΠΎΠΌ мСстС, Π³Π΄Π΅ Π²ΠΏΠ΅Ρ€Π²Ρ‹Π΅ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ Π΅Ρ‘ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ. ΠŸΠΎΡ‡Ρ‚ΠΈ каТдая локальная пСрСмСнная нуТдаСтся Π² ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Π΅. Если Π²Ρ‹ Π΅Ρ‰Π΅ Π½Π΅ Π·Π½Π°Π΅Ρ‚Π΅, ΠΊΠ°ΠΊ Ρ‚ΠΎΡ‡Π½ΠΎ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ, Ρ‚ΠΎ Π²Π°ΠΌ слСдуСт ΠΎΡ‚Π»ΠΎΠΆΠΈΡ‚ΡŒ Π΅Ρ‘ объявлСниС, ΠΏΠΎΠΊΠ° Π²Ρ‹ это Π½Π΅ ΡƒΠ·Π½Π°Π΅Ρ‚Π΅.

БущСствуСт ΠΎΠ΄Π½ΠΎ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅, ΠΊΠ°ΡΠ°Ρ‚Π΅Π»ΡŒΠ½ΠΎ Π±Π»ΠΎΠΊΠ° try-catch. Если пСрСмСнная инициализируСтся ΠΏΡ€ΠΈ ΠΏΠΎΠΌΠΎΡ‰ΠΈ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° return ΠΌΠ΅Ρ‚ΠΎΠ΄Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ выбрасываСт провСряСмоС ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅, Ρ‚ΠΎ ΠΎΠ½Π° Π΄ΠΎΠ»ΠΆΠ½Π° ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² Π±Π»ΠΎΠΊΠ΅ try. Если ΠΆΠ΅ пСрСмСнная Π΄ΠΎΠ»ΠΆΠ½Π° ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π²Π½Π΅ Π±Π»ΠΎΠΊΠ° try, Ρ‚ΠΎΠ³Π΄Π° ΠΎΠ½Π° ΠΎΠ±ΡŠΡΠ²Π»ΡΠ΅Ρ‚ΡΡ ΠΏΠ΅Ρ€Π΅Π΄ Π½ΠΈΠΌ, Π½Π΅Π²Π°ΠΆΠ½ΠΎ, Π·Π½Π°Π΅Ρ‚Π΅ Π»ΠΈ Π²Ρ‹ ΠΊΠ°ΠΊ Π΅Ρ‘ Ρ‚ΠΎΡ‡Π½ΠΎ Π½ΡƒΠΆΠ½ΠΎ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ:

Но Π΄Π°ΠΆΠ΅ этот случай ΠΌΠΎΠΆΠ½ΠΎ ΠΎΠ±ΠΎΠΉΡ‚ΠΈ ΠΏΡ€ΠΈ ΠΏΠΎΠΌΠΎΡ‰ΠΈ инкапсуляции Π±Π»ΠΎΠΊΠ° try-catch Π² ΠΌΠ΅Ρ‚ΠΎΠ΄Π΅.

ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π² Ρ†ΠΈΠΊΠ»Π°Ρ… Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΎΠ±ΡŠΡΠ²Π»ΡΡ‚ΡŒΡΡ Π²Π½ΡƒΡ‚Ρ€ΠΈ самого ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π°, Ссли Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π½Π΅Ρ‚ Π½Π΅ΠΏΡ€Π΅ΠΎΠ΄ΠΎΠ»ΠΈΠΌΠΎΠΉ ΠΏΡ€ΠΈΡ‡ΠΈΠ½Ρ‹ этого Π½Π΅ Π΄Π΅Π»Π°Ρ‚ΡŒ.

Π˜ΠΌΠΏΠΎΡ€Ρ‚Ρ‹

ΠžΡ‚ΡΡ‚ΡƒΠΏΡ‹

ΠΌΡ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ 4 ΠΏΡ€ΠΎΠ±Π΅Π»Π° для Π±Π»ΠΎΠΊΠΎΠ². ΠœΡ‹ Π½ΠΈΠΊΠΎΠ³Π΄Π° Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ Ρ‚Π°Π±ΡƒΠ»ΡΡ†ΠΈΡŽ. ΠœΡ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ 8 ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² для пСрСноса строк, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ Π²Ρ‹Π·ΠΎΠ²Ρ‹ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉ ΠΈ присваивания, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ Ρ‚Π°ΠΊ:

Названия полСй

Π€ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки

Для ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰ΠΈΡ… Ρ„ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобок Π½Π΅ выдСляСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Π°Ρ строка, ΠΎΠ½ΠΈ находятся Π² Ρ‚ΠΎΠΉ ΠΆΠ΅ строкС, Ρ‡Ρ‚ΠΎ ΠΈ ΠΊΠΎΠ΄ ΠΏΠ΅Ρ€Π΅Π΄ Π½ΠΈΠΌΠΈ:

ΠœΡ‹ Ρ‚Ρ€Π΅Π±ΡƒΠ΅ΠΌ Ρ„ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки для ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° условия. Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ являСтся, ΠΊΠΎΠ³Π΄Π° ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ условия ΠΈ Π΅Π³ΠΎ Ρ‚Π΅Π»ΠΎ ΠΏΠΎΠΌΠ΅Ρ‰Π°ΡŽΡ‚ΡΡ Π² ΠΎΠ΄Π½Ρƒ строку. Π’ΠΎ Π΅ΡΡ‚ΡŒ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Π°ΠΊ:

Π”Π»ΠΈΠ½Π° строки

КаТдая строка тСкста Π² ΠΊΠΎΠ΄Π΅ Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ Π½Π΅ Π΄Π»ΠΈΠ½Π½Π΅Π΅ 100 символов.
Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: Ссли ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ содСрТит ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠΌΠ°Π½Π΄, ΠΈΠ»ΠΈ URL (ΡƒΠ΄ΠΎΠ±Π½Π΅Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ copy/paste).
Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: строки ΠΈΠΌΠΏΠΎΡ€Ρ‚Π° ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ Π΄Π»ΠΈΠ½Π½Π΅Π΅ 100 символов, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ люди Ρ€Π΅Π΄ΠΊΠΎ Π½Π° Π½ΠΈΡ… смотрят. Π’Π°ΠΊΠΆΠ΅ это ΡƒΠΏΡ€ΠΎΡ‰Π°Π΅Ρ‚ написаниС инструмСнтов.

БокращСния Π² ΠΈΠΌΠ΅Π½Π°Ρ…

РассматривайтС сокращСния ΠΈ Π°Π±Π±Ρ€Π΅Π²ΠΈΠ°Ρ‚ΡƒΡ€Ρ‹ ΠΊΠ°ΠΊ слова. ИмСна Π±ΠΎΠ»Π΅Π΅ ΡƒΠ΄ΠΎΠ±ΠΎΡ‡ΠΈΡ‚Π°Π΅ΠΌΡ‹:

Π₯ΠΎΡ€ΠΎΡˆΠΎΠŸΠ»ΠΎΡ…ΠΎ
XmlHttpRequestXMLHTTPRequest
getCustomerIdgetCustomerID

Π­Ρ‚ΠΎΡ‚ ΡΡ‚ΠΈΠ»ΡŒ Ρ‚Π°ΠΊΠΆΠ΅ примСняСтся, ΠΊΠΎΠ³Π΄Π° сокращСниС ΠΈ Π°Π±Π±Ρ€Π΅Π²ΠΈΠ°Ρ‚ΡƒΡ€Π° β€” это ΠΏΠΎΠ»Π½ΠΎΠ΅ имя:

Π₯ΠΎΡ€ΠΎΡˆΠΎΠŸΠ»ΠΎΡ…ΠΎ
class Htmlclass HTML
String url;String URL;
long id;long ID;

Π‘Ρ‚ΠΈΠ»ΡŒ TODO

Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ TODO для ΠΊΠΎΠ΄Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ являСтся Π²Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ, краткосрочным, ΠΈΠ»ΠΈ Ρ…ΠΎΡ€ΠΎΡˆΠΈΠΌ, Π½ΠΎ Π½Π΅ ΠΈΠ΄Π΅Π°Π»ΡŒΠ½Ρ‹ΠΌ. ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²ΠΊΠ»ΡŽΡ‡Π°Ρ‚ΡŒ Π² сСбя Β«TODO:Β», Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€:

Если ваш ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ ΠΈΠΌΠ΅Π΅Ρ‚ Π²ΠΈΠ΄ Β«Π’ Π±ΡƒΠ΄ΡƒΡ‰Π΅ΠΌ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Ρ‡Ρ‚ΠΎ-Ρ‚ΠΎΒ», Ρ‚ΠΎ ΡƒΠ±Π΅Π΄ΠΈΡ‚Π΅ΡΡŒ, Ρ‡Ρ‚ΠΎ ΠΎΠ½ Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ Π² сСбя ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΡƒΡŽ Π΄Π°Ρ‚Ρƒ (1 января 2011 Π³ΠΎΠ΄Π°), ΠΈΠ»ΠΈ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠ΅ событиС Β«Π£Π΄Π°Π»ΠΈΡ‚ΡŒ послС Π²Ρ‹Ρ…ΠΎΠ΄Π° вСрсии 2.1Β».

Π‘ΠΎΠ³Π»Π°ΡΠΎΠ²Π°Π½Π½ΠΎΡΡ‚ΡŒ

Если Π²Ρ‹ измСняСтС ΠΊΠΎΠ΄, Ρ‚ΠΎ ΠΏΠΎΡ‚Ρ€Π°Ρ‚ΡŒΡ‚Π΅ ΠΌΠΈΠ½ΡƒΡ‚Ρƒ Π½Π° Ρ‚ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Π½Π° ΠΊΠΎΠ΄ Π²ΠΎΠΊΡ€ΡƒΠ³ вас ΠΈ ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΠΈΡ‚ΡŒ Π΅Π³ΠΎ ΡΡ‚ΠΈΠ»ΡŒ. Если Π² Π½Π΅ΠΌ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ ΠΏΡ€ΠΎΠ±Π΅Π»Ρ‹, Ρ‚ΠΎ ΠΈ Π²Π°ΠΌ слСдуСт ΠΈΡ… ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ. Если ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ содСрТат нСбольшой Π½Π°Π±ΠΎΡ€ Π·Π²Π΅Π·Π΄ΠΎΡ‡Π΅ΠΊ, Ρ‚ΠΎ ΠΈ Π²Π°ΠΌ слСдуСт ΠΈΡ… ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ.

Π’Π΅ΡΡŒ смысл Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄Π°Ρ†ΠΈΠΉ ΠΊ ΡΡ‚ΠΈΠ»ΡŽ ΠΊΠΎΠ΄Π° Π² создании ΠΎΠ±Ρ‰Π΅ΠΉ лСксики, Ρ‡Ρ‚ΠΎΠ±Ρ‹ люди ΠΊΠΎΠ½Ρ†Π΅Π½Ρ‚Ρ€ΠΈΡ€ΠΎΠ²Π°Π»ΠΈΡΡŒ Π½Π° Ρ‚ΠΎΠΌ, Ρ‡Ρ‚ΠΎ ΠΎΠ½ΠΈ говорят, вмСсто Ρ‚ΠΎΠ³ΠΎ ΠΊΠ°ΠΊ ΠΎΠ½ΠΈ говорят. ΠœΡ‹ прСдставляСм Π³Π»ΠΎΠ±Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΡ€Π°Π²ΠΈΠ»Π° стиля, Ρ‡Ρ‚ΠΎΠ±Ρ‹ люди Π·Π½Π°Π»ΠΈ эту лСксику. Но Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ ΡΡ‚ΠΈΠ»ΡŒ Ρ‚Π°ΠΊΠΆΠ΅ Π²Π°ΠΆΠ΅Π½. Если ΠΊΠΎΠ΄, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π²Ρ‹ добавляСтС Π² Ρ„Π°ΠΉΠ» выглядит Ρ€Π΅Π·ΠΊΠΎ ΠΎΡ‚Π»ΠΈΡ‡Π½Ρ‹ΠΌ ΠΎΡ‚ Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎ Π±Ρ‹Π», Ρ‚ΠΎ это выбросит Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ читатСля ΠΈΠ· Π΅Π³ΠΎ Ρ€ΠΈΡ‚ΠΌΠ° ΠΈ Π±ΡƒΠ΄Π΅Ρ‚ ΠΌΠ΅ΡˆΠ°Ρ‚ΡŒ Π΅ΠΌΡƒ ΠΏΠΎΠ½ΠΈΠΌΠ°Ρ‚ΡŒ структуру. Π‘Ρ‚Π°Ρ€Π°ΠΉΡ‚Π΅ΡΡŒ ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ этого.

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Google Java Style Guide

1 Introduction

This document serves as the complete definition of Google’s coding standards for source code in the Java™ Programming Language. A Java source file is described as being in Google Style if and only if it adheres to the rules herein.

Like other programming style guides, the issues covered span not only aesthetic issues of formatting, but other types of conventions or coding standards as well. However, this document focuses primarily on the hard-and-fast rules that we follow universally, and avoids giving advice that isn’t clearly enforceable (whether by human or tool).

1.1 Terminology notes

In this document, unless otherwise clarified:

Other «terminology notes» will appear occasionally throughout the document.

1.2 Guide notes

Example code in this document is non-normative. That is, while the examples are in Google Style, they may not illustrate the only stylish way to represent the code. Optional formatting choices made in examples should not be enforced as rules.

2 Source file basics

2.1 File name

2.2 File encoding: UTF-8

Source files are encoded in UTF-8.

2.3 Special characters

2.3.1 Whitespace characters

Aside from the line terminator sequence, the ASCII horizontal space character (0x20) is the only whitespace character that appears anywhere in a source file. This implies that:

2.3.2 Special escape sequences

2.3.3 Non-ASCII characters

For the remaining non-ASCII characters, either the actual Unicode character (e.g. ∞ ) or the equivalent Unicode escape (e.g. \u221e ) is used. The choice depends only on which makes the code easier to read and understand, although Unicode escapes outside string literals and comments are strongly discouraged.

Tip: In the Unicode escape case, and occasionally even when actual Unicode characters are used, an explanatory comment can be very helpful.

ExampleDiscussion
String unitAbbrev = «ΞΌs»;Best: perfectly clear even without a comment.
String unitAbbrev = «\u03bcs»; // «ΞΌs»Allowed, but there’s no reason to do this.
String unitAbbrev = «\u03bcs»; // Greek letter mu, «s»Allowed, but awkward and prone to mistakes.
String unitAbbrev = «\u03bcs»;Poor: the reader has no idea what this is.
return ‘\ufeff’ + content; // byte order markGood: use escapes for non-printable characters, and comment if necessary.

Tip: Never make your code less readable simply out of fear that some programs might not handle non-ASCII characters properly. If that should happen, those programs are broken and they must be fixed.

3 Source file structure

A source file consists of, in order:

Exactly one blank line separates each section that is present.

3.1 License or copyright information, if present

If license or copyright information belongs in a file, it belongs here.

3.2 Package statement

The package statement is not line-wrapped. The column limit (Section 4.4, Column limit: 100) does not apply to package statements.

3.3 Import statements

3.3.1 No wildcard imports

Wildcard imports, static or otherwise, are not used.

3.3.2 No line-wrapping

Import statements are not line-wrapped. The column limit (Section 4.4, Column limit: 100) does not apply to import statements.

3.3.3 Ordering and spacing

Imports are ordered as follows:

If there are both static and non-static imports, a single blank line separates the two blocks. There are no other blank lines between import statements.

Within each block the imported names appear in ASCII sort order. (Note: this is not the same as the import statements being in ASCII sort order, since ‘.’ sorts before ‘;’.)

3.3.4 No static import for classes

Static import is not used for static nested classes. They are imported with normal imports.

3.4 Class declaration

3.4.1 Exactly one top-level class declaration

Each top-level class resides in a source file of its own.

3.4.2 Ordering of class contents

The order you choose for the members and initializers of your class can have a great effect on learnability. However, there’s no single correct recipe for how to do it; different classes may order their contents in different ways.

What is important is that each class uses some logical order, which its maintainer could explain if asked. For example, new methods are not just habitually added to the end of the class, as that would yield «chronological by date added» ordering, which is not a logical ordering.

3.4.2.1 Overloads: never split

Methods of a class that share the same name appear in a single contiguous group with no other members in between. The same applies to multiple constructors (which always have the same name). This rule applies even when modifiers such as static or private differ between the methods.

4 Formatting

Terminology Note: block-like construct refers to the body of a class, method or constructor. Note that, by Section 4.8.3.1 on array initializers, any array initializer may optionally be treated as if it were a block-like construct.

4.1 Braces

4.1.1 Use of optional braces

Other optional braces, such as those in a lambda expression, remain optional.

4.1.2 Nonempty blocks: K & R style

Braces follow the Kernighan and Ritchie style («Egyptian brackets») for nonempty blocks and block-like constructs:

Exception: In places where these rules allow a single statement ending with a semicolon ( ; ), a block of statements can appear, and the opening brace of this block is preceded by a line break. Blocks like these are typically introduced to limit the scope of local variables, for example inside switch statements.

A few exceptions for enum classes are given in Section 4.8.1, Enum classes.

4.1.3 Empty blocks: may be concise

An empty block or block-like construct may be in K & R style (as described in Section 4.1.2). Alternatively, it may be closed immediately after it is opened, with no characters or line break in between ( <> ), unless it is part of a multi-block statement (one that directly contains multiple blocks: if/else or try/catch/finally ).

4.2 Block indentation: +2 spaces

Each time a new block or block-like construct is opened, the indent increases by two spaces. When the block ends, the indent returns to the previous indent level. The indent level applies to both code and comments throughout the block. (See the example in Section 4.1.2, Nonempty blocks: K & R Style.)

4.3 One statement per line

Each statement is followed by a line break.

4.4 Column limit: 100

Java code has a column limit of 100 characters. A «character» means any Unicode code point. Except as noted below, any line that would exceed this limit must be line-wrapped, as explained in Section 4.5, Line-wrapping.

Each Unicode code point counts as one character, even if its display width is greater or less. For example, if using fullwidth characters, you may choose to wrap the line earlier than where this rule strictly requires.

Exceptions:

4.5 Line-wrapping

Terminology Note: When code that might otherwise legally occupy a single line is divided into multiple lines, this activity is called line-wrapping.

There is no comprehensive, deterministic formula showing exactly how to line-wrap in every situation. Very often there are several valid ways to line-wrap the same piece of code.

Note: While the typical reason for line-wrapping is to avoid overflowing the column limit, even code that would in fact fit within the column limit may be line-wrapped at the author’s discretion.

Tip: Extracting a method or local variable may solve the problem without the need to line-wrap.

4.5.1 Where to break

The prime directive of line-wrapping is: prefer to break at a higher syntactic level. Also:

Note: The primary goal for line wrapping is to have clear code, not necessarily code that fits in the smallest number of lines.

4.5.2 Indent continuation lines at least +4 spaces

When line-wrapping, each line after the first (each continuation line) is indented at least +4 from the original line.

When there are multiple continuation lines, indentation may be varied beyond +4 as desired. In general, two continuation lines use the same indentation level if and only if they begin with syntactically parallel elements.

Section 4.6.3 on Horizontal alignment addresses the discouraged practice of using a variable number of spaces to align certain tokens with previous lines.

4.6 Whitespace

4.6.1 Vertical Whitespace

A single blank line always appears:

A single blank line may also appear anywhere it improves readability, for example between statements to organize the code into logical subsections. A blank line before the first member or initializer, or after the last member or initializer of the class, is neither encouraged nor discouraged.

Multiple consecutive blank lines are permitted, but never required (or encouraged).

4.6.2 Horizontal whitespace

Beyond where required by the language or other style rules, and apart from literals, comments and Javadoc, a single ASCII space also appears in the following places only.

This rule is never interpreted as requiring or forbidding additional space at the start or end of a line; it addresses only interior space.

4.6.3 Horizontal alignment: never required

Terminology Note: Horizontal alignment is the practice of adding a variable number of additional spaces in your code with the goal of making certain tokens appear directly below certain other tokens on previous lines.

This practice is permitted, but is never required by Google Style. It is not even required to maintain horizontal alignment in places where it was already used.

Here is an example without alignment, then using alignment:

Tip: Alignment can aid readability, but it creates problems for future maintenance. Consider a future change that needs to touch just one line. This change may leave the formerly-pleasing formatting mangled, and that is allowed. More often it prompts the coder (perhaps you) to adjust whitespace on nearby lines as well, possibly triggering a cascading series of reformattings. That one-line change now has a «blast radius.» This can at worst result in pointless busywork, but at best it still corrupts version history information, slows down reviewers and exacerbates merge conflicts.

4.7 Grouping parentheses: recommended

Optional grouping parentheses are omitted only when author and reviewer agree that there is no reasonable chance the code will be misinterpreted without them, nor would they have made the code easier to read. It is not reasonable to assume that every reader has the entire Java operator precedence table memorized.

4.8 Specific constructs

4.8.1 Enum classes

After each comma that follows an enum constant, a line break is optional. Additional blank lines (usually just one) are also allowed. This is one possibility:

An enum class with no methods and no documentation on its constants may optionally be formatted as if it were an array initializer (see Section 4.8.3.1 on array initializers).

Since enum classes are classes, all other rules for formatting classes apply.

4.8.2 Variable declarations

4.8.2.1 One variable per declaration

Every variable declaration (field or local) declares only one variable: declarations such as int a, b; are not used.

Exception: Multiple variable declarations are acceptable in the header of a for loop.

4.8.2.2 Declared when needed

Local variables are not habitually declared at the start of their containing block or block-like construct. Instead, local variables are declared close to the point they are first used (within reason), to minimize their scope. Local variable declarations typically have initializers, or are initialized immediately after declaration.

4.8.3 Arrays

4.8.3.1 Array initializers: can be «block-like»

Any array initializer may optionally be formatted as if it were a «block-like construct.» For example, the following are all valid (not an exhaustive list):

4.8.3.2 No C-style array declarations

4.8.4 Switch statements

Terminology Note: Inside the braces of a switch block are one or more statement groups. Each statement group consists of one or more switch labels (either case FOO: or default: ), followed by one or more statements (or, for the last statement group, zero or more statements).

4.8.4.1 Indentation

As with any other block, the contents of a switch block are indented +2.

After a switch label, there is a line break, and the indentation level is increased +2, exactly as if a block were being opened. The following switch label returns to the previous indentation level, as if a block had been closed.

4.8.4.2 Fall-through: commented
4.8.4.3 Presence of the default label

Each switch statement includes a default statement group, even if it contains no code.

Exception: A switch statement for an enum type may omit the default statement group, if it includes explicit cases covering all possible values of that type. This enables IDEs or other static analysis tools to issue a warning if any cases were missed.

4.8.5 Annotations

4.8.5.1 Type-use annotations
4.8.5.2 Class annotations

Annotations applying to a class appear immediately after the documentation block, and each annotation is listed on a line of its own (that is, one annotation per line). These line breaks do not constitute line-wrapping (Section 4.5, Line-wrapping), so the indentation level is not increased. Example:

4.8.5.3 Method and constructor annotations

The rules for annotations on method and constructor declarations are the same as the previous section. Example:

Exception: A single parameterless annotation may instead appear together with the first line of the signature, for example:

4.8.5.4 Field annotations

Annotations applying to a field also appear immediately after the documentation block, but in this case, multiple annotations (possibly parameterized) may be listed on the same line; for example:

4.8.5.5 Parameter and local variable annotations

There are no specific rules for formatting annotations on parameters or local variables (except, of course, when the annotation is a type-use annotation).

4.8.6 Comments

This section addresses implementation comments. Javadoc is addressed separately in Section 7, Javadoc.

Any line break may be preceded by arbitrary whitespace followed by an implementation comment. Such a comment renders the line non-blank.

4.8.6.1 Block comment style

Comments are not enclosed in boxes drawn with asterisks or other characters.

4.8.7 Modifiers

Class and member modifiers, when present, appear in the order recommended by the Java Language Specification:

4.8.8 Numeric Literals

5 Naming

5.1 Rules common to all identifiers

5.2 Rules by identifier type

5.2.1 Package names

5.2.2 Class names

Class names are written in UpperCamelCase.

There are no specific rules or even well-established conventions for naming annotation types.

5.2.3 Method names

Method names are written in lowerCamelCase.

5.2.4 Constant names

Constant names use UPPER_SNAKE_CASE : all uppercase letters, with each word separated from the next by a single underscore. But what is a constant, exactly?

These names are typically nouns or noun phrases.

5.2.5 Non-constant field names

Non-constant field names (static or otherwise) are written in lowerCamelCase.

5.2.6 Parameter names

Parameter names are written in lowerCamelCase.

One-character parameter names in public methods should be avoided.

5.2.7 Local variable names

Local variable names are written in lowerCamelCase.

Even when final and immutable, local variables are not considered to be constants, and should not be styled as constants.

5.2.8 Type variable names

Each type variable is named in one of two styles:

5.3 Camel case: defined

Sometimes there is more than one reasonable way to convert an English phrase into camel case, such as when acronyms or unusual constructs like «IPv6» or «iOS» are present. To improve predictability, Google Style specifies the following (nearly) deterministic scheme.

Beginning with the prose form of the name:

Note that the casing of the original words is almost entirely disregarded. Examples:

Prose formCorrectIncorrect
«XML HTTP request»XmlHttpRequestXMLHTTPRequest
«new customer ID»newCustomerIdnewCustomerID
«inner stopwatch»innerStopwatchinnerStopWatch
«supports IPv6 on iOS?»supportsIpv6OnIossupportsIPv6OnIOS
«YouTube importer»YouTubeImporter
YoutubeImporter *

*Acceptable, but not recommended.

Note: Some words are ambiguously hyphenated in the English language: for example «nonempty» and «non-empty» are both correct, so the method names checkNonempty and checkNonEmpty are likewise both correct.

6 Programming Practices

6.1 @Override : always used

A method is marked with the @Override annotation whenever it is legal. This includes a class method overriding a superclass method, a class method implementing an interface method, and an interface method respecifying a superinterface method.

6.2 Caught exceptions: not ignored

When it truly is appropriate to take no action whatsoever in a catch block, the reason this is justified is explained in a comment.

6.3 Static members: qualified using class

When a reference to a static class member must be qualified, it is qualified with that class’s name, not with a reference or expression of that class’s type.

6.4 Finalizers: not used

Tip: Don’t do it. If you absolutely must, first read and understand Effective Java Item 8, «Avoid finalizers and cleaners» very carefully, and then don’t do it.

7 Javadoc

7.1 Formatting

7.1.1 General form

The basic formatting of Javadoc blocks is as seen in this example:

. or in this single-line example:

7.1.2 Paragraphs

One blank lineβ€”that is, a line containing only the aligned leading asterisk ( * )β€”appears between paragraphs, and before the group of block tags if present. Each paragraph except the first has

immediately before the first word, with no space after it. HTML tags for other block-level elements, such as

    or

    , are not preceded with

    7.1.3 Block tags

    7.2 The summary fragment

    Each Javadoc block begins with a brief summary fragment. This fragment is very important: it is the only part of the text that appears in certain contexts such as class and method indexes.

    7.3 Where Javadoc is used

    At the minimum, Javadoc is present for every public class, and every public or protected member of such a class, with a few exceptions noted below.

    Additional Javadoc content may also be present, as explained in Section 7.3.4, Non-required Javadoc.

    7.3.1 Exception: self-explanatory members

    7.3.2 Exception: overrides

    Javadoc is not always present on a method that overrides a supertype method.

    7.3.4 Non-required Javadoc

    Other classes and members have Javadoc as needed or desired.

    Whenever an implementation comment would be used to define the overall purpose or behavior of a class or member, that comment is written as Javadoc instead (using /** ).

    Non-required Javadoc is not strictly required to follow the formatting rules of Sections 7.1.1, 7.1.2, 7.1.3, and 7.2, though it is of course recommended.

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java code conventions

    Java Code Conventions

    Why Have Code Conventions?

    Code conventions are important to programmers for a number of reasons:

    80% of the lifetime cost of a piece of software goes to maintenance.

    Hardly any software is maintained for its whole life by the original author.

    Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly.

    If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.

    Static Code Analysis

    Setting up Checkstyle

    Checkstyle will help educate and enforce our coding standards. You can set up your IDE to use Checkstyle to examine code for conformance to the standards. Learn more about the checks or Google the error message to find out why it complains about certain things.

    Install the CheckStyle-IDEA plugin. File | Preferences | Plugins | Browse Repositories. If nothing shows up in the list you may need to set the Http Proxy Settings. I had to set mine to manual: http://us-auto.proxy.lexmark.com:8080. Search for CheckStyle-IDEA and install it.

    Set the configuration file. In File | Preferences you will now have CheckStyle settings. Click plus sign to add the configuration file. Set the configuration file to http://lexmarkweb.github.io/coding-standards/java-checks-6.1.1.xml (for IntelliJ 13)

    Make this the active configuration.

    Check your code. With you code open in IntelliJ right click and you will see «Check Current File».

    A file consists of sections that should be separated by blank lines and an optional comment identifying each section.

    Source files are encoded in UTF-8

    Files longer than 2000 lines are cumbersome and should be avoided.

    Each Java source file contains a single public class or interface. When private classes and interfaces are associated with a public class, you can put them in the same source file as the public class. The public class should be the first class or interface in the file.

    Java source files have the following ordering:

    All source files should begin with a c-style comment that lists the programmer(s), the date, a copyright notice, and also a brief description of the purpose of the program.

    The first non-comment line of most Java source files is a package statement. After that, import statements can follow.

    Import statements must be grouped with associated packages together and one blank line between groups

    Imported classes should always be listed explicitly

    Four spaces should be used as the unit of indentation. The exact construction of the indentation is 4 spaces.

    Special characters like TAB and page break should be avoided

    Avoid lines longer than 120 characters, since they’re not handled well by many terminals and tools.

    When an expression will not fit on a single line, break it according to these general principles:

    β€’ Break after a comma.

    β€’ Break before an operator.

    β€’ For arithmetic expressions, avoid breaking within a set of parentheses.

    β€’ Align the new line with the beginning of the expression at the same level on the previous line.

    β€’ If the above rules lead to confusing code or to code that’s squished up against the right margin, just indent 8 spaces instead.

    Here are some examples of breaking method calls:

    Following are two examples of breaking an arithmetic expression. The first is preferred, since the break occurs outside the parenthesized expression, which is at a higher level.

    Following are two examples of indenting method declarations. The first is the conventional case. The second would shift the second and third lines to the far right if it used conventional indentation, so instead it indents only 8 spaces.

    Here are three acceptable ways to format ternary expressions:

    Java programs can have two kinds of comments: implementation comments and documentation comments. Implementation comments are those found in C++, which are delimited by /. /, and //. Documentation comments (known as «doc comments») are

    Implementation comments are meant for commenting out code or for comments about the particular implementation. Doc comments are meant to describe the specification of the code, from an implementation-free perspective to be read by developers who might not necessarily have the source code at hand.

    Comments should be used to give overviews of code and provide additional information that is not readily available in the code itself. Comments should contain only information that is relevant to reading and understanding the program. For example, information about how the corresponding package is built or in what directory it resides should not be included as a comment.

    Avoid duplicating information that is present in (and clear from) the code. It is too easy for redundant comments to get out of date. In general, avoid any comments that are likely to get out of date as the code evolves.

    Note: The frequency of comments sometimes reflects poor quality of code. When you feel compelled to add a comment, consider rewriting the code to make it clearer.

    Comments should not be enclosed in large boxes drawn with asterisks or other characters.

    Comments should never include special characters such as form-feed and backspace.

    Implementation Comment Formats

    Programs can have four styles of implementation comments: block, single-line, trailing and end-of-line.

    Block comments are used to provide descriptions of files, methods, data structures and algorithms.

    Block comments should be used at the beginning of each file and before each method. They can also be used in other places, such as within methods.

    Block comments inside a function or method should be indented to the same level as the code they describe.

    A block comment should be preceded by a blank line to set it apart from the rest of the code.

    Block comments have an asterisk » * » at the beginning of each line except the first.

    Short comments can appear on a single line indented to the level of the code that follows. If a comment can’t be written in a single line, it should follow the block comment format. A single-line comment should be preceded by a blank line. Here’s an example of a single-line comment in Java code

    Notice that top-level classes and interfaces are not indented, while their members are. The first line of doc comment ( /** ) for classes and interfaces is not indented; subsequent doc comment lines each have 1 space of indentation (to vertically align the asterisks). Members, including constructors, have 4 spaces for the first doc comment line and 5 spaces thereafter.

    If you need to give information about a class, interface, variable, or method that isn’t appropriate for documentation, use an implementation block comment or single-line comment immediately after the declaration. For example, details about the implementation of a class should go in in such an implementation block comment following the class statement, not in the class doc comment.

    Doc comments should not be positioned inside a method or constructor definition block, because Java associates documentation comments with the first declaration after the comment.

    All classes are to include a comment block that describing the basic purpose of the class. (This is also a good place to put any overarching TODO statements).

    All public methods need to include Java doc comments except for accessors.

    Parameters are to be included, but do not require documentation unless it is something meaningful i.e. avoid * @param name The name

    Return statements are to be included and documented.

    Thrown exceptions may be included, but do not need to be documented.

    Protected / Private methods should include java doc comments when they are not easily understood. This is up to developer / reviewer discretion.

    One declaration per line. In other words,

    Try to initialize local variables where they’re declared. The only reason not to initialize a variable where it’s declared is if the initial value depends on some computation occurring first.

    Local variables are not habitually declared at the start of their containing block or block-like construct. Instead, local variables are declared close to the point they are first used (within reason), to minimize their scope. Local variable declarations typically have initializers, or are initialized immediately after declaration.

    Avoid local declarations that hide declarations at higher levels. For example, do not declare the same variable name in an inner block:

    Class and Interface Declarations

    When coding Java classes and interfaces, the following formatting rules should be followed:

    No space between a method name and the parenthesis «(» starting its parameter list

    Closing brace «>» starts a line by itself indented to match its corresponding opening statement, except when it is a null statement the «>» should appear immediately after the «<"

    Methods are separated by a blank line

    Annotations applying to a class, method or constructor appear immediately after the documentation block, and each annotation is listed on a line of its own (that is, one annotation per line). These line breaks do not constitute line-wrapping so the indentation level is not increased

    Each line should contain at most one statement. Example:

    Compound statements are statements that contain lists of statements enclosed in braces «< statements >«. See the following sections for examples.

    The enclosed statements should be indented one more level than the compound statement.

    The opening brace should be at the end of the line that begins the compound statement; the closing brace should begin a line and be indented to the beginning of the compound statement.

    Braces are used around all statements, even single statements, when they are part of a control structure, such as an if-else or for statement. This makes it easier to add statements without accidentally introducing bugs due to forgetting to add braces.

    A return statement with a value should not use parentheses unless they make the return value more obvious in some way. Example:

    if, if-else, if else-if else Statements

    The if-else class of statements should have the following form:

    Note: if statements always use braces, <>. Avoid the following error-prone form:

    A for statement should have the following form:

    An empty for statement (one in which all the work is done in the initialization, condition, and update clauses) should have the following form:

    When using the comma operator in the initialization or update clause of a for statement, avoid the complexity of using more than three variables. If needed, use separate statements before the for loop (for the initialization clause) or at the end of the loop (for the update clause).

    A while statement should have the following form:

    An empty while statement should have the following form:

    A do-while statement should have the following form:

    A switch statement should have the following form:

    Every time a case falls through (doesn’t include a break statement), add a comment where the break statement would normally be. This is shown in the preceding code example with the /* falls through */ comment.

    Every switch statement should include a default case. The break in the default case is redundant, but it prevents a fall-through error if later another case is added.

    A try-catch statement should have the following format:

    A try-catch statement may also be followed by finally, which executes regardless of whether or not the try block has completed successfully.

    for collection loop

    A for collection loop should have following format

    Blank lines improve readability by setting off sections of code that are logically related.

    Two blank lines should always be used in the following circumstances:

    Between sections of a source file

    Between class and interface definitions

    One blank line should always be used in the following circumstances:

    Between the local variables in a method and its first statement

    Before a block or single-line comment

    Between logical sections inside a method to improve readability

    Blank spaces should be used in the following circumstances:

    Note that a blank space should not be used between a method name and its opening parenthesis. This helps to distinguish keywords from method calls.

    A blank space should appear after commas in argument lists.

    Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier-for example, whether it’s a constant, package, or class-which can be helpful in understanding the code.

    Identifier TypeRules of NamingExamples
    PackagesThe prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.

    Subsequent components of the package name vary according to an organization’s own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.

    ClassesClass names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

    Implementation class should have suffix Impl

    class Raster; class ImageSprite;
    InterfacesInterface names should be capitalized like class names.interface RasterDelegate; interface Storing;
    MethodsMethods should be verbs, in Camel Case

    The term compute can be used where something is computed

    The term find can be used when we look up something

    Is prefix is used for Boolean getter and setters

    Acronyms such as XML and HTTP should be treated as words, such as getHttp(), getXml(). Not getXML() or getHTTP()

    Variable names should be meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for loop control variables.

    Common names for temporary variables are i, j, k, m, and n.

    Boolean variable names should not be negative, for instance, isNotLoaded, unAttached.

    int i; char c; float myWidth;
    ConstantsThe names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores («`_`»).«` static final int MIN_WIDTH = 4; static final int MAX_WIDTH = 999; static final int GET_THE_CPU = 1; «`

    Type conversions must always be done explicitly never rely on implicit type conversion

    Array specifiers must be attached to the type not the variable

    Providing Access to Instance and Class Variables

    Don’t make any instance or class variable public without good reason. Just because it’s a class level variable doesn’t mean it needs a getter and setter.

    One example of appropriate public instance variables is the case where the class is essentially a data structure, with no behavior

    Referring to Class Variables and Methods

    Avoid using an object to access a class (static) variable or method. Use a class name instead. For example:

    String constants should be used except for «» or null, some exceptions would be logging and errors.

    should be written as

    It is generally a good idea to use parentheses liberally in expressions involving mixed operators to avoid operator precedence problems. Even if the operator precedence seems clear to you, it might not be to others-you shouldn’t assume that other programmers know precedence as well as you do.

    Try to make the structure of your program match the intent. Example:

    should instead be written as

    ! operator and conditional expressions

    @Override: always used

    A method is marked with the @Override annotation whenever it is legal. This includes a class method overriding a superclass method, a class method implementing an interface method, and an interface method respecifying a superinterface method.

    Exception:@Override may be omitted when the parent method is @Deprecated.

    Caught exceptions: not ignored

    Except as noted below, it is very rarely correct to do nothing in response to a caught exception. Exceptions should usually be at least logged at debug or trace level.

    When it truly is appropriate to take no action whatsoever in a catch block, the reason this is justified is explained in a comment.

    Exception: In tests, a caught exception may be ignored without comment if it is named expected. The following is a very common idiom for ensuring that the method under test does throw an exception of the expected type, so a comment is unnecessary here.

    Each project/application should choose and enforce usage of a standard logging library (ex. Log4j)

    Each project/application should document when each logging level should be used

    All exceptions should at least be logged (excluding «expected» exceptions like some parsing exceptions)

    Exceptions should be chained except for good reasons

    When adding temporary logging for trouble shooting, add a // TODO remove temporary logs comment by set of log messages that should be removed.

    Consult these resources for guidance on secure coding practices, particularly CERT standard. Some stylistic considerations are mentioned further on.

    Exercise extreme caution with switch statements, especially fall-through statements. If you must use fall-through, please re-think your design approach. If, after much consideration, you still need fall-through, be judicious and deliberate to mark ALL fall-through points with a comment as indicated earlier in this guide.

    Security checks should be located and maintained in a single place. Be sure to apply «Don’t Repeat Yourself» (DRY) principal frequently and comprehensively to all security check logic throughout the application.

    When to Use Generics

    With Collections. The Java Collections framework is excellent and should be used instead of Arrays.

    If you find yourself doing a lot (or perhaps even a little) casting of types you might want to consider Generics

    If you are using variables of type Object to store values form various classes, you might want to use Generics instead.

    Naming Convention for Generic types in a class definition

    Oracle recommends the following naming convention:

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Steve Yohanan

    Printing

    For a version more suitable for printing, use this PDF File.

    This document comprises an opinionated set of conventions for the Java TM programming language. It is intended for use by software engineering teams to employ a common style when writing Java code.

    The following is the original copyright notice provided by Sun. It is to be honored, particularly by adhering to proper attribution as well as usage and redistribution restrictions stated below.

    Though redistribution of this document is discouraged, citing the warning above, you may copy, adapt, and redistribute this document for non-commercial use or for your own internal use in a commercial setting. However, you may not republish this document, nor may you publish or distribute any adaptation of this document for other than non-commercial use or your own internal use, without first obtaining express written approval from Oracle.

    When copying, adapting, or redistributing this document in keeping with the guidelines above, you are required to provide proper attribution to Sun. If you reproduce or distribute the document without making any substantive modifications to its content, please use the following attribution line:

    Copyright 1995-1999 Sun Microsystems, Inc. All rights reserved. Used by
    permission.

    If you modify the document content in a way that alters its meaning, for example, to conform with your own company’s coding conventions, please use this attribution line:

    Adapted with permission from CODE CONVENTIONS FOR THE JAVA TM PROGRAMMING
    LANGUAGE. Copyright 1995-1999 Sun Microsysytems[sic], Inc. All rights
    reserved.

    Either way, please include a hypertext link or other reference to the Java Code Conventions Web site at http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

    Code conventions are important to programmers for a number of reasons:

    This section lists commonly used file suffixes and names.

    The following table lists the file suffixes used by Java software.

    SuffixFile Type
    .javaJava source
    .classJava bytecode
    .jarJava archive

    The following table lists frequently used file names. These files are not required for every directory; however, when they exist the specified names should be used.

    File NameUse
    MakefilePreferred name for makefiles.
    READMEPreferred name for the file that summarizes the contents of a particular directory.

    A file consists of sections that should be separated by blank lines and, optionally, a comment identifying each section. Files longer than 2000 lines are cumbersome and should be avoided. Refer to Appendix A for an example of a complete Java program properly formatted.

    Each Java source file should contain at most one public class or interface. When private classes and interfaces are associated with a public class, put them in the same source file as the public class. The public class should be the first class or interface in the file.

    Java source files have the following ordering.

    All source files should begin with a C-style block comment ( /*. */ ) that lists the file name, RCS keywords, copyright notice, among other things. Section 5.1.1 gives additional information on block comments; however, all other block comments besides the header comments use the // delimeter.

    The following gives a simple example of header comments.

    The use of the XML tags in the header comments are provided as a suggestion. They allow scripts to be run across the source tree to globally modify the values of things like the RCS keywords or copyright notice in individual files when needed.

    The first non-comment line of a Java source files should be the package statement. After that, import statements can follow. Place a single blank line between the header comments and the package statement. Also place a single blank line between the package statement and the first import statement.

    The following gives a simple example of package and import statements.

    The following are additional conventions; the general Java conventions make no reference to them.

    The use of * in an import statement (e.g., import java.awt.* ) should not be used, even though Java provides the functionality. It is considered poor programming style and can lead to ambiguities when multiple classes are used with the same name but from different packages.

    Do not import anything from java.lang directly. These statements are redundant as the complete package is always imported by the compiler and run-time environment regardless.

    Do not import any classes which are not used directly.

    The following gives an example of proper ordering of import statements.

    The following section varies dramatically from the original Java conventions. What is presented here is much more rigid and structured.

    A class declaration should adhere to the following structure (in order).

    The following gives an example of the basic structure of a class declaration.

    An interface declaration is very similar in structure to that of a class. The major differences are the following.

    The following gives an example of the basic structure of an interface declaration.

    The unit of indentation should be 4 spaces. Tab-stops should be set exactly every 8 spaces.

    All indentation must be achieved via the space character; tab characters must not exist in the resultant source file.

    For Emacs users, the following elisp code will automatically convert any tabs into spaces when a java file is saved.

    When an expression will not fit on a single line, break it according to these general principles:

    The following are two examples of breaking method calls.

    The following are two examples of breaking an arithmetic expression. The first is preferred, since the break occurs outside the parenthesized expression, which is at a higher level.

    The following are two examples of indenting method declarations. The first is the conventional case. The second would shift the second and third lines too far to the right if it used conventional indentation, so instead it indents only one tab-stop.

    The following are two examples to format class declarations.

    The following is an example of handling a long assignment statements. Break before the equals sign and indent one tab-stop from the start of the previous line.

    The following are three acceptable ways to format ternary expressions. Refer to Section 10.6.7 for appropriate use of this expression.

    Implementation comments are for notes about a particular implementation or a means for temporarily removing code. Documentation comments are meant to describe the specification of the code, from an implementation-free perspective, to be read by developers who might not necessarily have the source code at hand.

    In general, comments should be used to give overviews of code and provide additional information that is not readily available in the code itself. Comments should contain only information that is relevant to reading and understanding the program. For example, information about how the corresponding package is built or in what directory it resides should not be included as a comment.

    Discussion of nontrivial or nonobvious design decisions is appropriate, but avoid duplicating information that is present in (and clear from) the code. It is too easy for redundant comments to get out of date. In general, avoid any comments that are likely to get out of date as the code evolves. In addition, the frequency of comments sometimes reflects poor quality of code. When feeling compelled to add a comment, one should consider rewriting the code to make it clearer.

    All comments should have a single blank space between the comment delimeter and the text of the comment. In addition, comments should not be enclosed in large boxes drawn with asterisks or other characters. Comments should never include special characters such as form-feed and backspace.

    Programs can have four styles of implementation comments: block, single-line, trailing, and for temporarily removing code.

    Block comments are used to provide descriptions of files, methods, data structures, and algorithms. Block comments may be used at the beginning of each file and before each method. They can also be used in other places, such as within methods. Block comments inside a function or method should be indented to the same level as the code they describe. A block comment should be preceded by a blank line unless it comes immediately after the start of a compound statement (Section 7.2).

    The following is a simple example of a block comment.

    For information about another form of block comments used for documentation, see Section 5.2.

    Short comments can appear on a single line indented to the level of the code that follows. If a comment can not be written in a single line, it should follow the block comment format (Section 5.1.1). A single-line comment should be preceded by a blank line unless it comes immediately after the start of a compound statement (Section 7.2).

    The following are a few examples of single-line comments.

    Very short comments can appear on the same line as the code they describe but should be shifted far enough to separate them from the statements. If more than one short comment appears in a section of related code, they should all be indented to the same tab setting.

    The following are a few examples of trailing comments.

    Trailing comments are also used to help clarify the closing brace of a compound statement (Section 7.2). One example of this usage is at the end of a class declaration; the class name is placed in a trailing comment adjacent to the closing brace (Section 6.5). Another example occurs when several long compound statements are nested; a trailing comment can be added adjacent to the closing brace of a compound statement to help clarify which block the brace closes.

    The following gives an an example for both cases of clarifying a closing brace by use of a trailing comment.

    The // delimiter can comment out a partial or complete line. It can also be used in consecutive multiple lines for commenting-out entire sections of code. It is important to note that this should only be used as a temporary measure while the code is in active development; the unused code should eventually be purged as it can make the source more difficult to maintain.

    The following are examples of temporarily removing code with comments.

    The following is a simple example of a documentation comment used for describing a class.

    Notice that top-level classes and interfaces are not indented, while their members are. The first line of documentation comment ( /** ) for classes and interfaces is not indented; subsequent documentation comment lines each have 1 space of indentation (to vertically align the asterisks). Members, including constructors, have 4 spaces for the first documentation comment line and 5 spaces thereafter. Single line documentation comments are only acceptable when describing fields.

    If one needs to give information about a class, interface, method, or field that is not intended for documentation, use an appropriate implementation comment (Section 5.1) immediately after the declaration.

    Java associates documentation comments with the first declaration after the comment. As a result, documentation comments should not be positioned inside a method or constructor definition block.

    The following is a simple example showing the proper use of documentation comments and implementation comments.

    Only one declaration per line is allowed. Even though Java permits multiple declarations on a line, it makes initialization impossible (see Section 6.2) and leads to confusion when scalars and arrays are declared on the same line. The standard Java convention is to recommend rather than require one declaration per line.

    The following are examples of correct and incorrect declarations.

    The previous example uses a single space between the type and the identifier. Another acceptable alternative is to use tabs.

    The following is an example of declarations using tabs to separate the type from the variable.

    All variables (local and class) should be initialized where they are declared.

    Put all local variable declarations at the beginning of method definitions. The standard Java convention allows for declarations to appear at the beginning of any compound statement; however, this is discouraged because it can lead to issues where a variable declared at a higher scope is unwittingly hidden by one in a lower scope.

    The following is an example of proper placement of declarations at the beginning of a method.

    The one exception to the placement rule is indexes of for loops which in Java can be declared in the for statement.

    The following is an example of a declaration of an index within the for loop.

    Though Java allows modifiers in any order, a consistent ordering improves readability of code. The following is the proper order of modifiers for declarations.

    When coding Java classes and interfaces, the following formatting rules should be followed.

    The following is a simple example of a proper formatting of a class declaration.

    Each line should contain no more than one statement.

    The following is an example of correct and incorrect formatting of simple statements.

    Compound statements are statements that contain lists of statements enclosed in braces ( <> ). See the following subsections for specific examples.

    A return statement with a value should not use parentheses unless they make the value being returned more obvious in some way.

    The following are several examples of proper use of return statements.

    The if-else class of statements should have the following form.

    Like all other compound statements, if statements always use braces ( <> ). As a result, do not use the following error-prone form.

    A for statement should have the following form.

    When using the comma operator in the initialization or update clause of a for statement, avoid the complexity of using more than three variables. If needed, use separate statements before the for loop (for the initialization clause) or at the end of the loop (for the update clause).

    A while statement should have the following form.

    A do-while statement should have the following form.

    A switch statement should have the following form.

    The first statement for each case should appear on the line following the case and should be indented one extra level.

    Every time a case falls through (i.e., does not include a break statement), add a comment where the break statement would normally be. This is shown in the preceding code example with the // XXX falls through comment. Refer to Section 10.6.8 for more information on the appropriate use of the // XXX special comment.

    Every switch statement should include a default case, and it should always be the last case. The break in the default case is redundant because it is the last one in the statement; however, it prevents a fall-through error if later another case is inadvertently added to the end.

    A try-catch statement should have the following form.

    The following is a simple example of a properly formatted try-catch-finally statement.

    Blank lines improve readability by setting off sections of code that are logically related. A single blank line should always be used in the following circumstances.

    Blank spaces should be used in the following circumstances.

    The following is an example of proper use of blank space following a keyword.

    On the other hand, a blank space should not be used between a method name and its opening parenthesis. This helps to distinguish keywords from method calls. Blank space should not appear after the the opening parenthesis or just prior to the closing parenthesis.

    The following is an example of the proper use of blank space for binary operators.

    The following is an example of proper use of blank spaces in a for statement.

    The following are a few examples of proper use of blank space with casts.

    The following are a few examples of correct package names.

    Class and interface names should adhere to the following conventions.

    The following are examples of proper usage for naming classes and interfaces.

    Method names should adhere to the following conventions.

    The following are examples of proper usage for naming methods.

    The following are examples of proper usage for naming variables.

    The names of variables declared class constants ( static final ) and of ANSI constants should be all uppercase with words separated by underscores ( _ ). (ANSI constants should be avoided, for ease of debugging.)

    The following are several examples of proper naming of constants.

    Fields (instance and class variables) should always have private access. They should only be worked with indirectly, via accessors and mutators ( get and set methods).

    The only exception to this rule is the case where the class is essentially a data structure, with no behavior. In other words, if one would have used a struct instead of a class (if Java supported struct ), then it is appropriate to make the fields of the class public.

    It is required to use the this object reference when accessing instance variables or calling non-static methods. Java assumes this in contexts where it is omitted; however, its explicit use removes any ambiguity. In addition, since Java is an object-oriented language it is considered good programming style to have all references (excluding local variables) to be prefaced by an object.

    The following are several example of correct and incorrect access to instance variables.

    A class name is required to access constants, static fields, or static methods. Do not use an object reference. In cases local to the class, do not use this or exclude a reference altogether.

    The following are several examples of correct and incorrect access to constants, class variables, and static methods.

    Do not assign several variables to the same value in a single statement. It is hard to read.

    The following is an example of both incorrect and correct variable assignments.

    Do not use the assignment operator in a place where it can be easily confused with the equality operator.

    The following is an example of both incorrect and correct use of the assignment operator in a conditional.

    Do not use embedded assignments in an attempt to improve run-time performance. This is the job of the compiler.

    The following is an example of both incorrect and correct use of the assignment operator.

    The resource reference name should be based on the resource name. The resource name should be written in mixed case with the first letter of each internal word capitalized

    jms/ [Queue|Topic] Examples:

    mail/ resource-qualifier Example:

    jms/ Factory or jms/ [Queue|Topic]Factory Examples:

    The paramter name should be written in mixed case with the first letter of each internal word capitalized. Parameters may be grouped under a common context name.

    param/CatalogDAOClass param/event/ActionEvent

    The following is an example of both incorrect and correct use of parentheses within a conditional.

    Wherever possible, avoid multiple return statements in a method. It is good programming practice to have a single exit point from a method; otherwise, debugging can be difficult. If necessary, a temporary variable can be used to track the return value.

    The following is an example of using a temporary variable to store the return value for a method rather than have multiple return statements.

    Also, try to make the structure of the program match the intent.

    The following example shows a case where the use of the if-else statement is extraneous.

    The entire previous statement could be written simply as the following.

    The following is another example of a case where the use of the if-else statement is extraneous.

    The entire previous statement could be written simply as the following.

    The following is an example of an acceptable case of more than one return statement for a method.

    If a class or interface contains an accessor ( getFoo() or isFoo() ) and mutator ( setFoo() ) pair that have the same access level they should placed adjacent to each other with the accessor placed first in the file.

    If a class does not derive directly from any other class, explicitly state in the class declaration that it extends from Object even though Java infers this fact.

    Fully-qualified class names (e.g., java.beans.BeanInfo ) should not be used within the code.

    The following are exceptions to this rule.

    The following is an example of acceptable use of fully-qualified class names.

    Use XXX in a comment to flag something that is unconventional or bogus but works. Use FIXME to flag something that is bogus and broken.

    The following gives several example of proper use of special comments.


    A. Code Example

    The following is a complete example of a properly formatted Java class file that properly adheres to the conventions in this document.

    This is version 2.1 (10 October 2016) of the document. It consists of minor updates from v2.0, none of which affected the original conventions.

    Version 2.0 (09 February 2003) was an update of v1.0 to be more general purpose. It was specifically resurrected for use in several software development classes being taught at St. Edward’s University.

    The annals of Version 1.0 (c. 2000) have been lost in time.

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java code conventions

    Π£Π²Π°ΠΆΠ°Π΅ΠΌΡ‹Π΅ посСтитСли! Если Π²Ρ‹ ΠΎΠ±Π½Π°Ρ€ΡƒΠΆΠΈΠ»ΠΈ Π² ΠΊΠ°ΠΊΠΎΠΌ-Π½ΠΈΠ±ΡƒΠ΄ΡŒ словС ΠΎΡˆΠΈΠ±ΠΊΡƒ!
    Π’Ρ‹Π΄Π΅Π»ΠΈΡ‚Π΅ это слово ΠΈ Π½Π°ΠΆΠΌΠΈΡ‚Π΅ Ctrl+Enter ΠΎΠ΄Π½ΠΎΠ²Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎ!
    Π—Π°Ρ€Π°Π½Π΅Π΅ спасибо Π·Π° сотрудничСство!

    ΠšΠΎΠ½Ρ‚Π°ΠΊΡ‚Ρ‹

    АдрСс элСктронной ΠΏΠΎΡ‡Ρ‚Ρ‹ Π·Π°Ρ‰ΠΈΡ‰Π΅Π½ ΠΎΡ‚ спам-Π±ΠΎΡ‚ΠΎΠ². Для просмотра адрСса Π² вашСм Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Π²ΠΊΠ»ΡŽΡ‡Π΅Π½ Javascript.

    БоглашСния ΠΏΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ ΠΊΠΎΠ΄Π° Java (Java Code Conventions)

    Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ Java code conventions. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ Java code conventions. Π€ΠΎΡ‚ΠΎ Java code conventions

    Π”Π°Π½Π½Ρ‹ΠΉ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ Π½Π΅ ΠΏΡ€Π΅Ρ‚Π΅Π½Π΄ΡƒΠ΅Ρ‚ Π½Π° ΠΏΠ°Π»ΡŒΠΌΡƒ пСрвСнства ΠΈΠ»ΠΈ ΠΊΠ°ΠΊ Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄! Π”ΡƒΠΌΠ°ΡŽ Ρ‚Π°ΠΊΠΈΡ… ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ΠΎΠ² Π² сСти довольного ΠΌΠ½ΠΎΠ³ΠΎ, ΠΌΠΎΠΆΠ΅Ρ‚ ΠΌΠ½ΠΎΠ³ΠΈΠ΅ ΠΈΠ· Π½ΠΈΡ… ΠΏΠ΅Ρ€Π΅Π²Π΅Π΄Π΅Π½Ρ‹ ΠΊΡƒΠ΄Π° Π»ΡƒΡ‡ΡˆΠ΅ этого =)

    Π­Ρ‚ΠΎΡ‚ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ я Π΄Π΅Π»Π°Π» для сСбя Π² цСлях ознакомлСния с Π΄Π°Π½Π½Ρ‹ΠΌ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΎΠΌ, Π΄Π° ΠΈ ΠΏΡ€Π°Π²ΠΈΠ»Π°ΠΌ оформлСния ΠΊΠΎΠ΄Π° Π² Ρ†Π΅Π»ΠΎΠΌ. Π’ этом ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄Π΅ отчасти использовались ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹ с этого ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄Π°.

    Для сСбя я старался Π΅Π³ΠΎ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ максимально ΡƒΠ΄ΠΎΠ±ΠΎΠ²Π°Ρ€ΠΈΠΌΡ‹ΠΌ для понимания ΠΈ использования Π² дальнСйшСм =) По этому Ссли ΠΊΡ‚ΠΎ Ρ…ΠΎΡ‡Π΅Ρ‚ Π΅Π³ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π³Π΄Π΅-Ρ‚ΠΎ Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… мСстах, Ρ‚ΠΎ Π½Π΅ Π·Π°Π±Ρ‹Π²Π°Π΅ΠΌ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒ ссылку Π½Π° этот ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π» ΠΈΠ»ΠΈ сайт http://www.magnumblog.space;)

    А Π²ΠΎΠΎΠ±Ρ‰Π΅ ΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ΡΡŒ Π½Π° Π·Π΄ΠΎΡ€ΠΎΠ²ΡŒΠ΅.

    1.1 Π—Π°Ρ‡Π΅ΠΌ Π½ΡƒΠΆΠ½Ρ‹ условныС обозначСния ΠΊΠΎΠ΄Π°

    БоглашСния ΠΏΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ ΠΊΠΎΠ΄Π° Π²Π°ΠΆΠ½Ρ‹ для программистов ΠΏΠΎ ряду ΠΏΡ€ΠΈΡ‡ΠΈΠ½:

    1.2 Π’Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΏΡ€ΠΈΠ·Π½Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ

    Π’ этом Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π΅ содСрТатся стандарты ΠΏΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ ΠΊΠΎΠ΄Π° Π½Π° языка Java, прСдставлСнныС Π² спСцификации ΠΎΡ‚ Sun Microsystems. ΠžΡΠ½ΠΎΠ²Π½Ρ‹Π΅ Π²ΠΊΠ»Π°Π΄Ρ‹ ΠΎΡ‚ ΠŸΠΈΡ‚Π΅Ρ€Π° Кинга, ΠŸΠ°Ρ‚Ρ€ΠΈΠΊΠ° Нотона, Майка Π”Π΅ΠœΠΎΠ½ΠΈ, Π”ΠΆΠΎΠ½Π½ΠΈ ΠšΠ°Π½Π΅Ρ€Π²Ρ‹, ΠšΡΡ‚ΠΈ Π£ΠΎΠ»Ρ€Π°Ρ‚Π° ΠΈ Π‘ΠΊΠΎΡ‚Ρ‚Π° Π₯оммСля.

    По вопросам, связанным с Π°Π΄Π°ΠΏΡ‚Π°Ρ†ΠΈΠ΅ΠΉ, ΠΌΠΎΠ΄ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠ΅ΠΉ ΠΈΠ»ΠΈ распространСниСм этого Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°, поТалуйста, ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°ΠΉΡ‚Π΅ нашС ΡƒΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠ΅ ΠΎΠ± авторских ΠΏΡ€Π°Π²Π°Ρ… ΠΏΠΎ адрСсу http://java.sun.com/docs/codeconv/html/Copyright.doc.html.

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΊ этому Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Ρƒ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½Ρ‹ Π² Π½Π°ΡˆΡƒ Ρ„ΠΎΡ€ΠΌΡƒ ΠΎΠ±Ρ€Π°Ρ‚Π½ΠΎΠΉ связи ΠΏΠΎ адрСсу http://java.sun.com/docs/forms/sendusmail.html.

    Π’ этом Ρ€Π°Π·Π΄Π΅Π»Π΅ пСрСчислСны Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ часто ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹Π΅ ΠΈΠΌΠ΅Π½Π° Ρ„Π°ΠΉΠ»ΠΎΠ² ΠΈ ΠΈΡ… Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ.

    2.1 Π Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ Ρ„Π°ΠΉΠ»ΠΎΠ²

    Π’ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°Ρ… написанных Π½Π° Java ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ Ρ„Π°ΠΉΠ»ΠΎΠ²:

    Π’ΠΈΠΏ Ρ„Π°ΠΉΠ»Π°Π Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅
    Для исходного ΠΊΠΎΠ΄Π°.java
    Для Π±Π°ΠΉΡ‚-ΠΊΠΎΠ΄Π°.class
    2.2 ΠžΠ±Ρ‰ΠΈΠ΅ ΠΈΠΌΠ΅Π½Π° Ρ„Π°ΠΉΠ»ΠΎΠ²

    Часто ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹Π΅ ΠΈΠΌΠ΅Π½Π° Ρ„Π°ΠΉΠ»ΠΎΠ² Π²ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‚:

    Имя Ρ„Π°ΠΉΠ»Π°ΠŸΡ€ΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅
    GNUmakefileΠ—Π°Ρ€Π΅Π·Π΅Ρ€Π²ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎΠ΅ имя для создаваСмых Ρ„Π°ΠΉΠ»ΠΎΠ². ΠœΡ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ gnumake для создания нашСго ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния.
    READMEΠ—Π°Ρ€Π΅Π·Π΅Ρ€Π²ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎΠ΅ имя Ρ„Π°ΠΉΠ»Π° Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ содСрТится информация ΠΎ Ρ„Π°ΠΉΠ»Π°Ρ… находящихся Π² Ρ‚ΠΎΠΉ ΠΆΠ΅ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΎΡ€ΠΈΠΈ.

    Π€Π°ΠΉΠ» состоит ΠΈΠ· Ρ€Π°Π·Π΄Π΅Π»ΠΎΠ², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·Π΄Π΅Π»Π΅Π½Ρ‹ пустыми строками ΠΈ Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ, ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΡ†ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠΌ ΠΊΠ°ΠΆΠ΄ΡƒΡŽ ΡΠ΅ΠΊΡ†ΠΈΡŽ.

    Π€Π°ΠΉΠ»Ρ‹ Π΄Π»ΠΈΠ½ΠΎΠΉ Π±ΠΎΠ»Π΅Π΅ 2000 строк ΡΠ²Π»ΡΡŽΡ‚ΡΡ Π³Ρ€ΠΎΠΌΠΎΠ·Π΄ΠΊΠΈΠΌΠΈ ΠΈ ΠΈΡ… слСдуСт ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ€ форматирования Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½ Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ «ΠŸΡ€ΠΈΠΌΠ΅Ρ€ Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java».

    3.1 Π€Π°ΠΉΠ»Ρ‹ с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ„Π°ΠΉΠ» с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java содСрТит ΠΎΠ΄ΠΈΠ½ class с ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹ΠΌ словом public ΠΈΠ»ΠΈ интСрфСйс. Когда классы с ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹ΠΌ словом private ΠΈ интСрфСйсы связанны с public классом, Ρ‚ΠΎ ΠΈΡ… ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΎΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π² Ρ‚ΠΎΡ‚ ΠΆΠ΅ Ρ„Π°ΠΉΠ» с ΠΈΡ…ΠΎΠ΄Π½Ρ‹ΠΌ ΠΊΠΎΠ΄ΠΎΠΌ, Ρ‡Ρ‚ΠΎ ΠΈ public класс. Класс с ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹ΠΌ словом public Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·ΠΌΠ΅Ρ‰Π΅Π½ ΠΊΠ°ΠΊ ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ класс ΠΈΠ»ΠΈ интСрфСйс Π² Ρ„Π°ΠΉΠ»Π΅.

    Π€Π°ΠΉΠ»Ρ‹ с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java ΠΈΠΌΠ΅ΡŽΡ‚ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ порядок:

    3.1.1 ΠΠ°Ρ‡Π°Π»ΡŒΠ½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ

    ВсС Ρ„Π°ΠΉΠ»Ρ‹ с исходным ΠΊΠΎΠ΄ΠΎΠΌ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с коммСнтария Π² стилС языка C, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ пСрСчислСны Π°Π²Ρ‚ΠΎΡ€Ρ‹ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, Π΄Π°Ρ‚Π°, свСдСния ΠΎΠ± авторских ΠΏΡ€Π°Π²Π°Ρ…, Π° Ρ‚Π°ΠΊ ΠΆΠ΅ ΠΊΡ€Π°Ρ‚ΠΊΠΎ описаниС Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎ Π΄Π΅Π»Π°Π΅Ρ‚ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°. Для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°:

    3.1.2 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ Package ΠΈ Import

    ΠŸΠ΅Ρ€Π²Π°Ρ строка Π±Π΅Π· коммСнтария Π² Ρ„Π°ΠΉΠ»Π΅ с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java это ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ package. ПослС Π½Π΅Π΅ слСдуСт ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ import. Для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°:

    3.1.3 ОбъявлСния классов ΠΈ интСрфСйсов

    Π’ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ Ρ‚Π°Π±Π»ΠΈΡ†Π΅ описаны части объявлСния класса ΠΈΠ»ΠΈ интСрфСйса Π² Ρ‚ΠΎΠΌ порядкС, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ ΠΎΠ½ΠΈ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Ρ‚ΡŒΡΡ. ΠžΠ±Ρ€Π°Π·Π΅Ρ† с коммСнтариями ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½ Π² «ΠŸΡ€ΠΈΠΌΠ΅Ρ€Π΅ Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java»

    Π§Π°ΡΡ‚ΡŒ объявлСния класса/интСрфСйсаЗамСтки
    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ для Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ ΠΏΠΎ классам ΠΈ интСрфСйсам (/**. */)Π‘ΠΌΠΎΡ‚Ρ€ΠΈΡ‚Π΅ Π² «ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ» какая информация Π΄ΠΎΠ»ΠΆΠ½Π° содСрТатся Π² этом ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ
    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ class ΠΈΠ»ΠΈ interface
    Если Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ, Ρ‚ΠΎ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ класса/интСрфСйса (/*. */)Π—Π΄Π΅ΡΡŒ содСрТится любая Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Π°Ρ информация ΠΏΠΎ классу ΠΈΠ»ΠΈ интСрфСйсу, которая Π½Π΅ ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ΠΈΡ‚ для Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ коммСнтария.
    (static) ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ классаБначала ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ класса public, Π·Π°Ρ‚Π΅ΠΌ protected, ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠΎΡ‚ΠΎΠΌ private
    ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ экзСмпляраБпСрва public, Π·Π°Ρ‚Π΅ΠΌ protected, ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠΎΡ‚ΠΎΠΌ private.
    ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€Ρ‹
    ΠœΠ΅Ρ‚ΠΎΠ΄Ρ‹ΠœΠ΅Ρ‚ΠΎΠ΄Ρ‹ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ сгрупированным ΠΏΠΎ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ, Π° Π½Π΅ ΠΏΠΎ области ΠΈΠ»ΠΈ доступности. Для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π° ΠΌΠ΅Ρ‚ΠΎΠ΄ класса private ΠΌΠΎΠΆΠ΅Ρ‚ находится ΠΌΠ΅ΠΆΠ΄Ρƒ двумя public ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌΠΈ экзСмпляра. ЦСль Π² ΠΎΠ±Π»Π΅Π³Ρ‡Π΅Π½ΠΈΠΈ чтСния ΠΈ понимания ΠΊΠΎΠ΄Π°.

    Π’ качСствС Π΅Π΄ΠΈΠ½ΠΈΡ†Ρ‹ отступов слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»Π°. Вочная конструкция отступа (ΠΏΡ€ΠΎΠ±Π΅Π»Ρ‹ ΠΈΠ»ΠΈ символы табуляции) Π½Π΅ ΡƒΠΊΠ°Π·Π°Π½Π°. Вабуляция Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ установлСна Ρ€ΠΎΠ²Π½ΠΎ ΠΊΠ°ΠΆΠ΄Ρ‹Π΅ 8 ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² (Π° Π½Π΅ 4).

    4.1 Π”Π»ΠΈΠ½Π° строки

    Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ строк Π΄Π»ΠΈΠ½Π½Π΅Π΅ 80 символов, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ ΠΎΠ½ΠΈ Π½Π΅ ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°ΡŽΡ‚ΡΡ ΠΌΠ½ΠΎΠ³ΠΈΠΌΠΈ Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°ΠΌΠΈ ΠΈ инструмСнтами.

    4.2 ΠŸΠ΅Ρ€Π΅Π½ΠΎΡ строки

    Если Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π½Π΅ помСщаСтся Π½Π° ΠΎΠ΄Π½ΠΎΠΉ строкС, Ρ€Π°Π·Π±Π΅ΠΉΡ‚Π΅ Π΅Π³ΠΎ Π² соотвСтствии с этими ΠΎΠ±Ρ‰ΠΈΠΌΠΈ ΠΏΡ€ΠΈΠ½Ρ†ΠΈΠΏΠ°ΠΌΠΈ:

    НСсколько ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ² пСрСноса строки Π² Π²Ρ‹Π·ΠΎΠ²Π°Ρ… ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ²:

    НиТС ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Ρ‹ Π΄Π²Π° ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π° пСрСноса арифмСтичСского выраТСния. ΠŸΠ΅Ρ€Π²ΠΎΠ΅ ΠΏΡ€Π΅Π΄ΠΏΠΎΡ‡Ρ‚ΠΈΡ‚Π΅Π»ΡŒΠ½Π΅Π΅, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ Ρ€Π°Π·Ρ€Ρ‹Π² происходит Π²Π½Π΅ выраТСния Π² скобках, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ находится Π½Π° Π±ΠΎΠ»Π΅Π΅ высоком ΡƒΡ€ΠΎΠ²Π½Π΅.

    ΠžΡ‚ΡΡ‚ΡƒΠΏΡ‹ Π² строках с ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ if слСдуСт ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΡ‚ΡŒ ΠΏΠΎ ΠΏΡ€Π°Π²ΠΈΠ»Ρƒ 8-ΠΌΠΈ ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ², Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ Ссли ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ стандартныС 4-Ρ€Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»Π°, Ρ‚ΠΎ поиск Ρ‚Π΅Π»Π° ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° Π±ΡƒΠ΄Π΅Ρ‚ Π·Π°Ρ‚Ρ€ΡƒΠ΄Π½ΠΈΡ‚Π΅Π»Π΅Π½. НапримСр:

    Π’ΠΎΡ‚ Ρ‚Ρ€ΠΈ ΠΏΡ€ΠΈΠ΅ΠΌΠ»Π΅ΠΌΡ‹Ρ… способа форматирования Ρ‚Π΅Ρ€Π½Π°Ρ€Π½Ρ‹Ρ… Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ:

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΊΠΎΠ΄Π° ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ для описания ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Ρ… строк/Π±Π»ΠΎΠΊΠΎΠ² ΠΊΠΎΠ΄Π° ΠΈΠ»ΠΈ Ρ†Π΅Π»ΠΎΠ³ΠΎ Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΠ°. ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для докумСнтирования ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠΏΠΈΡΠ°Ρ‚ΡŒ ΡΠΏΠ΅Ρ†ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΡŽ ΠΊΠΎΠ΄Π° (Π΅Π³ΠΎ интСрфСйс), Π½Π΅ Π·Π°Π²ΠΈΡΡΡ‰ΡƒΡŽ ΠΎΡ‚ Π΅Π³ΠΎ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ. ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для докумСнтирования Π΄Π΅Π»Π°ΡŽΡ‚ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΎΠ², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±ΡƒΠ΄ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ваши ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ (Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ классов) Π½Π΅ имСя ΠΈΡ… исходного ΠΊΠΎΠ΄Π°.

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π½ΡƒΠΆΠ½Ρ‹, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΊΠΎΠ΄ ΠΈΠ»ΠΈ ΠΏΠΎΡΡΠ½ΠΈΡ‚ΡŒ ΠΌΠΎΠΌΠ΅Π½Ρ‚Ρ‹, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ слоТно ΠΏΠΎΠ½ΡΡ‚ΡŒ нСпосрСдствСнно ΠΈΠ· ΠΊΠΎΠ΄Π°. ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ лишь Ρ‚Ρƒ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ, которая Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠ° для чтСния ΠΈ понимания ΠΊΠΎΠ΄Π° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹. НапримСр ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΎ Ρ‚ΠΎΠΌ, ΠΊΠ°ΠΊ ΠΎΡ‚ΠΊΠΎΠΌΠΏΠΈΠ»ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ связанный ΠΏΠ°ΠΊΠ΅Ρ‚ ΠΈΠ»ΠΈ Π² ΠΊΠ°ΠΊΠΎΠΉ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΎΡ€ΠΈΠΈ ΠΎΠ½ находится Π½Π΅ стоит ΠΎΠΏΠΈΡΡ‹Π²Π°Ρ‚ΡŒ Π² ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ.

    ΠžΠ±ΡΡƒΠΆΠ΄Π΅Π½ΠΈΠ΅ Π½Π΅Ρ‚Ρ€ΠΈΠ²ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΈΠ»ΠΈ Π½Π΅ΠΎΡ‡Π΅Π²ΠΈΠ΄Π½Ρ‹Π΅ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠΉ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ, Π½ΠΎ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ ΠΎΠΏΠΈΡΡ‹Π²Π°Ρ‚ΡŒ Ρ‚ΠΎ, Ρ‡Ρ‚ΠΎ ΠΈ Ρ‚Π°ΠΊ ясно ΠΈΠ· ΠΊΠΎΠ΄Π°. Π’Π°ΠΊΠΈΠ΅ «ΠΈΠ·Π±Ρ‹Ρ‚ΠΎΡ‡Π½Ρ‹Π΅» ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΎΡ‡Π΅Π½ΡŒ быстро ΠΌΠΎΠ³ΡƒΡ‚ ΡΡ‚Π°Ρ‚ΡŒ Π½Π΅Π°ΠΊΡ‚ΡƒΠ°Π»ΡŒΠ½Ρ‹ΠΌΠΈ. Π’ ΠΎΠ±Ρ‰Π΅ΠΌ, слСдуСт ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ Π»ΡŽΠ±Ρ‹Ρ… ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ ΡΡ‚Π°Ρ‚ΡŒ Π½Π΅Π°ΠΊΡ‚ΡƒΠ°Π»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΏΠΎ ΠΌΠ΅Ρ€Π΅ развития ΠΊΠΎΠ΄Π°.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: ЧастоС использованиС ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² ΠΈΠ½ΠΎΠ³Π΄Π° Π³ΠΎΠ²ΠΎΡ€ΠΈΡ‚ ΠΎ Π½ΠΈΠ·ΠΊΠΎΠΌ качСство ΠΊΠΎΠ΄Π°. Когда Π²Ρ‹ чувствуСтС Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎΡΡ‚ΡŒ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ, ΠΏΠΎΠΏΡ€ΠΎΠ±ΡƒΠΉΡ‚Π΅ ΠΏΠ΅Ρ€Π΅ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΊΠΎΠ΄, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ½ стал понятнСС.

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ Π·Π°ΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ Π² большиС ΠΊΠ²Π°Π΄Ρ€Π°Ρ‚Ρ‹, ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½Π½Ρ‹Π΅ Π·Π²Π΅Π·Π΄ΠΎΡ‡ΠΊΠ°ΠΌΠΈ ΠΈΠ»ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ символами. НапримСр:

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… символов, Ρ‚Π°ΠΊΠΈΡ… ΠΊΠ°ΠΊ символ ΠΊΠΎΠ½Ρ†Π° страницы ΠΈΠ»ΠΈ backspace.

    5.1 Π€ΠΎΡ€ΠΌΠ°Ρ‚ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²

    Π’ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°Ρ… ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡΡ 4 Π²ΠΈΠ΄Π° ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²: Π±Π»ΠΎΡ‡Π½Ρ‹Π΅, однострочныС, ΠΏΡ€ΠΈΡ†Π΅ΠΏΠ½Ρ‹Π΅ ΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π΄ΠΎ ΠΊΠΎΠ½Ρ†Π° строки.

    5.1.1 Π‘Π»ΠΎΠΊ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²

    Π‘Π»ΠΎΡ‡Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ для описания Ρ„Π°ΠΉΠ»ΠΎΠ², ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ², структур Π΄Π°Π½Π½Ρ‹Ρ… ΠΈ Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΠΎΠ². Π’Π°ΠΊ ΠΆΠ΅ ΠΈΡ… слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π² Π½Π°Ρ‡Π°Π»Π΅ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΈ ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠΌ. Они Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… мСстах, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Π²Π½ΡƒΡ‚Ρ€ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ². Π‘Π»ΠΎΡ‡Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π²Π½ΡƒΡ‚Ρ€ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΠΌΠ΅Ρ‚ΡŒ отступ Π½Π° Ρ‚ΠΎΠΌ ΠΆΠ΅ ΡƒΡ€ΠΎΠ²Π½Π΅, Ρ‡Ρ‚ΠΎ ΠΈ ΠΊΠΎΠ΄, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΠ½ΠΈ ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‚.

    ΠŸΠ΅Ρ€Π΅Π΄ Π±Π»ΠΎΡ‡Π½Ρ‹ΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ слСдуСт ΠΎΡΡ‚Π°Π²Π»ΡΡ‚ΡŒ ΠΏΡƒΡΡ‚ΡƒΡŽ строку, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½ΠΎ ΠΎΡ‚Π΄Π΅Π»ΠΈΡ‚ΡŒ Π΅Π³ΠΎ ΠΎΡ‚ ΠΊΠΎΠ΄Π°. КаТдая строка Π±Π»ΠΎΡ‡Π½ΠΎΠ³ΠΎ коммСнтария (ΠΊΡ€ΠΎΠΌΠ΅ ΠΏΠ΅Ρ€Π²ΠΎΠΉ) Π΄ΠΎΠ»ΠΆΠ½Π° Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с символа «*«.

    Если Π±Π»ΠΎΡ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ начинаСтся с «/*-«, это ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚ Π² Π΄Π°Π½Π½ΠΎΠΌ Π±Π»ΠΎΠΊΠ΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ особоС Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ нСльзя ΠΏΠΎΡ‚Π΅Ρ€ΡΡ‚ΡŒ (Π’Π°ΠΊΠΎΠΉ Π±Π»ΠΎΠΊ Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΠ΅Ρ€Π΅Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ срСдствами автоформатирования). НапримСр:

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: Если Π²Ρ‹ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚Π΅ срСдства автоформатирования, Π²Π°ΠΌ Π½Π΅ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ «/*-» Π² ΠΊΠΎΠ΄Π΅, Π½ΠΎ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ это Π½Π° случай Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎ ΠΊΡ‚ΠΎ-Ρ‚ΠΎ Π΄Ρ€ΡƒΠ³ΠΎΠΉ ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°ΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ срСдства автоформатирования Π½Π° вашСм ΠΊΠΎΠ΄Π΅.

    5.1.2 ΠžΠ΄Π½ΠΎΡΡ‚Ρ€ΠΎΡ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ

    ΠžΠ΄Π½ΠΎΡΡ‚Ρ€ΠΎΡ‡Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ (ΠΊΠΎΡ€ΠΎΡ‚ΠΊΠΈΠ΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ) ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΈΡΠ°Ρ‚ΡŒ Π² ΠΎΠ΄Π½ΠΎΠΉ строкС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ отступ Π½Π° ΡƒΡ€ΠΎΠ²Π½Π΅ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π³ΠΎ Π±Π»ΠΎΠΊΠ° ΠΊΠΎΠ΄Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΠ½ описываСт. Если ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π΅ помСщаСтся Π² ΠΎΠ΄Π½Ρƒ строку, слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π±Π»ΠΎΡ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ (смотритС «Π‘Π»ΠΎΠΊ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²»). ΠžΠ΄Π½ΠΎΡΡ‚Ρ€ΠΎΡ‡Π½ΠΎΠΌΡƒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΡŽ Π΄ΠΎΠ»ΠΆΠ½Π° ΠΏΡ€Π΅Π΄ΡˆΠ΅ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ пустая строка. Π’ΠΎΡ‚ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ однострочного коммСнтария Π² Java-ΠΊΠΎΠ΄Π΅ (смотритС «ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ»):

    5.1.3 ΠŸΡ€ΠΈΡ†Π΅ΠΏΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ

    ΠžΡ‡Π΅Π½ΡŒ ΠΊΠΎΡ€ΠΎΡ‚ΠΊΠΈΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ ΠΌΠΎΠΆΠ½ΠΎ Ρ€Π°ΡΠΏΠΎΠ»ΠΎΠΆΠΈΡ‚ΡŒ Π½Π° Ρ‚ΠΎΠΉ ΠΆΠ΅ строкС, Ρ‡Ρ‚ΠΎ ΠΈ описываСмый ΠΊΠΎΠ΄. ΠŸΡ€ΠΈ этом Π΅Π³ΠΎ слСдуСт ΡΠ΄Π²ΠΈΠ½ΡƒΡ‚ΡŒ Π²ΠΏΡ€Π°Π²ΠΎ Π½Π°ΡΡ‚ΠΎΠ»ΡŒΠΊΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ½ Π½Π΅ сливался с ΠΊΠΎΠ΄ΠΎΠΌ. Если Π² ΠΎΠ΄Π½ΠΎΠΌ Π±Π»ΠΎΠΊΠ΅ ΠΊΠΎΠ΄Π° присутствуСт Π±ΠΎΠ»Π΅Π΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ Ρ‚Π°ΠΊΠΎΠ³ΠΎ коммСнтария, ΠΈΡ… Π½Π°Ρ‡Π°Π»ΠΎ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ Π½Π° ΠΎΠ΄Π½ΠΎΠΌ ΡƒΡ€ΠΎΠ²Π½Π΅.

    Π‘Ρ‚Π°Ρ€Π°ΠΉΡ‚Π΅ΡΡŒ ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ коммСнтирования ΠΊΠ°ΠΆΠ΄ΠΎΠΉ строчки ΠΊΠΎΠ΄Π° ΠΏΠΎΠ΄ΠΎΠ±Π½Ρ‹ΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΏΡ€ΠΈΡ†Π΅ΠΏΠ½Ρ‹Ρ… ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² Π² Java ΠΊΠΎΠ΄Π΅ (смотритС Ρ‚Π°ΠΊΠΆΠ΅ «ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для докумСнтирования»):

    5.1.4 ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π² ΠΊΠΎΠ½Ρ†Π΅ строки

    Π‘ΠΈΠΌΠ²ΠΎΠ»Π°ΠΌΠΈ // начинаСтся ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ продолТится Π΄ΠΎ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ строки (Π½ΠΎΠ²ΠΎΠΉ строки). Он ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°Π½ΠΈΠΌΠ°Ρ‚ΡŒ всю строку ΠΈΠ»ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π΅Π΅ Ρ‡Π°ΡΡ‚ΡŒ. Π•Π³ΠΎ Π½Π΅ слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ для многострочных ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π², ΠΎΠ΄Π½Π°ΠΊΠΎ Π΅Π³ΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π·Π°ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ нСсколько строк ΠΊΠΎΠ΄Π°. Рассмотрим ΠΏΡ€ΠΈΠΌΠ΅Ρ€ всСх Ρ‚Ρ€Π΅Ρ… Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ΠΎΠ² Π΅Π³ΠΎ использования:

    5.2 ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для докумСнтирования

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: смотритС «ΠŸΡ€ΠΈΠΌΠ΅Ρ€ Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java» для ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ² Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΎΠ² ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π², описанных здСсь.

    Для получСния Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΉ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ смотритС «ΠšΠ°ΠΊ Π½Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΊ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Ρƒ для Javadoc«, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ Π² сСбя ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΎ Ρ‚Π΅Π³Π°Ρ… ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π° (@return, @param, @see):

    Для получСния большСй ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ ΠΎ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΡ… коммСнтариях ΠΈ Javadoc, посСтитС домашнюю страницу Javadoc:

    Π”ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠ΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‚ Java классы, интСрфСйсы, конструкторы, ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ ΠΈ поля. ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ помСщаСтся Π² ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΡ‚Π΅Π»ΠΈ /**. */, ΠΎΠ΄ΠΈΠ½ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π° ΠΎΠ΄ΠΈΠ½ элСмСнт API. Π’Π°ΠΊΠΎΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π΄ΠΎΠ»ΠΆΠ΅Π½ Ρ€Π°ΡΠΏΠΎΠ»Π°Π³Π°Ρ‚ΡŒΡΡ нСпосрСдствСнно ΠΏΠ΅Ρ€Π΅Π΄ объявлСниСм:

    ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ классы ΠΈ интСрфСйсы Π½Π΅ ΠΈΠΌΠ΅ΡŽΡ‚ отступов, Π² ΠΎΡ‚Π»ΠΈΡ‡ΠΈΠΈ ΠΎΡ‚ ΠΈΡ… Ρ‡Π»Π΅Π½ΠΎΠ². ΠŸΠ΅Ρ€Π²Π°Ρ строка Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ коммСнтария (/**) для классов ΠΈ интСрфСйсов Π½Π΅ ΠΈΠΌΠ΅Π΅Ρ‚ отступов; каТдая ΠΏΠΎΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π°Ρ строка Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ коммСнтария ΠΈΠΌΠ΅Π΅Ρ‚ 1 ΠΏΡ€ΠΎΠ±Π΅Π» (для Π²Π΅Ρ€Ρ‚ΠΈΠΊΠ°Π»ΡŒΠ½ΠΎΠ³ΠΎ выравнивания Π·Π²Π΅Π·Π΄ΠΎΡ‡Π΅ΠΊ). Π§Π»Π΅Π½Ρ‹ класса, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ конструкторы, ΠΈΠΌΠ΅ΡŽΡ‚ 4 ΠΏΡ€ΠΎΠ±Π΅Π»Π° для ΠΏΠ΅Ρ€Π²ΠΎΠΉ строки Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ коммСнтария ΠΈ 5 для ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Ρ….

    Если Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΏΡ€Π΅Π΄ΠΎΡΡ‚Π°Π²ΠΈΡ‚ΡŒ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΎ классС, интСрфСйсС, ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π΅, Π½Π΅ ΠΏΡ€ΠΈΠ½Π°Π΄Π»Π΅ΠΆΠ°Ρ‰ΡƒΡŽ ΠΊ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π±Π»ΠΎΡ‡Π½Ρ‹ΠΉ (смотритС Ρ€Π°Π·Π΄Π΅Π» 5.1.1) ΠΈΠ»ΠΈ однострочный (смотритС Ρ€Π°Π·Π΄Π΅Π» 5.1.2) ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ нСпосрСдствСнно послС объявлСния. НапримСр, Π΄Π΅Ρ‚Π°Π»ΠΈ ΠΎ Ρ€Π΅Π°Π»ΠΈΠ·ΡƒΠ΅ΠΌΠΎΠΌ классС Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΠ΄Ρ‚ΠΈ Π² Ρ‚Π°ΠΊΠΎΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π² Π±Π»ΠΎΠΊΠ΅ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ, Π° Π½Π΅ Π² Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅ΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ.

    Π”ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ Ρ€Π°ΡΠΏΠΎΠ»Π°Π³Π°Ρ‚ΡŒΡΡ Π²Π½ΡƒΡ‚Ρ€ΠΈ Π±Π»ΠΎΠΊΠ° Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° ΠΈΠ»ΠΈ конструктора, ΠΏΠΎΡ‚ΠΎΠΌΡƒ Ρ‡Ρ‚ΠΎ Java связываСт Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ с ΠΏΠ΅Ρ€Π²Ρ‹ΠΌ послС Π½Π΅Π³ΠΎ объявлСниСм.

    6.1 ΠšΠΎΠ»ΠΈΡ‡Π΅ΡΡ‚Π²ΠΎ объявлСний Π² строкС

    РСкомСндуСтся ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΎΠ΄Π½ΠΎ объявлСниС Π½Π° строку, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ это ΠΎΠ±Π»Π΅Π³Ρ‡Π°Π΅Ρ‚ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅. Π”Ρ€ΡƒΠ³ΠΈΠΌΠΈ словами:

    Ни Π² ΠΊΠΎΠ΅ΠΌ случаС нСльзя ΠΎΠ±ΡŠΡΠ²Π»ΡΡ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π² ΠΎΠ΄Π½ΠΎΠΉ строкС. НапримСр:

    НС ΠΏΠΎΠΌΠ΅Ρ‰Π°ΠΉΡ‚Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Ρ€Π°Π·Π½Ρ‹Ρ… Ρ‚ΠΈΠΏΠΎΠ² (имССтся Π² Π²ΠΈΠ΄Ρƒ Π½Π΅ Ρ‚ΠΈΠΏ самих ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…, Π° Ρ‚ΠΈΠΏ Π΄Π°Π½Π½Ρ‹Ρ… ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π² Π½ΠΈΡ… хранятся) Π² ΠΎΠ΄Π½Ρƒ строку. НапримСр:

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: Π’ ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Π½Ρ‹Ρ… Π²Ρ‹ΡˆΠ΅ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°Ρ… ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ ΠΎΠ΄ΠΈΠ½ ΠΏΡ€ΠΎΠ±Π΅Π» ΠΌΠ΅ΠΆΠ΄Ρƒ Ρ‚ΠΈΠΏΠΎΠΌ ΠΈ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ΠΎΠΌ. Π”Ρ€ΡƒΠ³ΠΎΠΉ ΠΏΡ€ΠΈΠ΅ΠΌΠ»Π΅ΠΌΠΎΠΉ Π°Π»ΡŒΡ‚Π΅Ρ€Π½Π°Ρ‚ΠΈΠ²ΠΎΠΉ являСтся использованиС табуляции для выравнивания ΠΈΠ½Π΅Π΄Π½Ρ‚ΠΈΠ²ΠΈΠΊΡ‚ΠΎΡ€ΠΎΠ² Π² ΠΎΠ΄ΠΈΠ½Ρƒ линию (использованиС клавиши Tab которая Ρ€Π°Π²Π½Π° ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ 4-ΠΌ ΠΏΡ€ΠΎΠ±Π΅Π»Π°ΠΌ), Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€:

    6.2 Π Π°Π·ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅

    Π Π°Π·ΠΌΠ΅Ρ‰Π°ΠΉΡ‚Π΅ объявлСния Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² Π½Π°Ρ‡Π°Π»Π΅ Π±Π»ΠΎΠΊΠΎΠ² (Π±Π»ΠΎΠΊΠΎΠΌ являСтся любой ΠΊΠΎΠ΄, Π·Π°ΠΊΠ»ΡŽΡ‡Π΅Π½Π½Ρ‹ΠΉ Π² Ρ„ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки «<«» ΠΈ «>«). НС ΠΆΠ΄ΠΈΡ‚Π΅ объявлСния ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… Π΄ΠΎ ΠΈΡ… ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ использования; Π­Ρ‚ΠΎ ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°ΠΏΡƒΡ‚Π°Ρ‚ΡŒ Π½Π΅ΠΎΠΏΡ‹Ρ‚Π½ΠΎΠ³ΠΎ программиста ΠΈ Π·Π°Ρ‚Ρ€ΡƒΠ΄Π½ΠΈΡ‚ΡŒ ΠΏΠ΅Ρ€Π΅Π½ΠΎΡΠΈΠΌΠΎΡΡ‚ΡŒ ΠΊΠΎΠ΄Π° Π² ΠΏΡ€Π΅Π΄Π΅Π»Π°Ρ… области.

    ЕдинствСнным ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ ΠΈΠ· этого ΠΏΡ€Π°Π²ΠΈΠ»Π° ΡΠ²Π»ΡΡŽΡ‚ΡΡ индСксы Ρ†ΠΈΠΊΠ»ΠΎΠ² for, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π² Java ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΠΎΠ±ΡŠΡΠ²Π»Π΅Π½Ρ‹ Π² ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π΅ for:

    Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… объявлСний, ΠΏΠ΅Ρ€Π΅ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰ΠΈΡ… объявлСния Π±ΠΎΠ»Π΅Π΅ высокого уровня. НапримСр, Π½Π΅ ΠΎΠ±ΡŠΡΠ²Π»ΡΠΉΡ‚Π΅ ΠΎΠ΄Π½Ρƒ ΠΈ Ρ‚Ρƒ ΠΆΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ ΠΏΠ΅Ρ€Π΅Π΄ Π±Π»ΠΎΠΊΠΎΠΌ ΠΊΠΎΠ΄Π° ΠΈ Π²ΠΎ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΌ Π±Π»ΠΎΠΊΠ΅:

    6.3 Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΡ

    Π‘Ρ‚Π°Ρ€Π°ΠΉΡ‚Π΅ΡΡŒ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Ρ‚Π°ΠΌ, Π³Π΄Π΅ Π²Ρ‹ ΠΈΡ… ΠΎΠ±ΡŠΡΠ²Π»ΡΠ΅Ρ‚Π΅. ЕдинствСнная ΠΏΡ€ΠΈΡ‡ΠΈΠ½Π° Π½Π΅ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ Π² мСстС Π΅Ρ‘ объявлСния β€” Ссли Π΅Ρ‘ Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ зависит ΠΎΡ‚ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… ΠΏΡ€Π΅Π΄Π²Π°Ρ€ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… вычислСний.

    6.4 ОбъявлСния классов ΠΈ интСрфСйсов

    ΠŸΡ€ΠΈ написании Java классов ΠΈ интСрфСйсов Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΡΠΎΠ±Π»ΡŽΠ΄Π°Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ ΠΏΡ€Π°Π²ΠΈΠ»Π° форматирования:

    7.1 ΠŸΡ€ΠΎΡΡ‚Ρ‹Π΅ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹

    КаТдая строка Π΄ΠΎΠ»ΠΆΠ½Π° ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ Π½Π΅ Π±ΠΎΠ»Π΅Π΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π°. НапримСр:

    НС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π·Π°ΠΏΡΡ‚ΡƒΡŽ для Π³Ρ€ΡƒΠΏΠΏΠΈΡ€ΠΎΠ²ΠΊΠΈ Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ², Π΄Π°ΠΆΠ΅ Ссли это Π²ΠΈΠ΄Π½ΠΎ Π½Π΅Π²ΠΎΠΎΡ€ΡƒΠΆΠ΅Π½Π½Ρ‹ΠΌ Π³Π»Π°Π·ΠΎΠΌ. НапримСр:

    7.2 БоставныС ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹
    7.3 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ return

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ return, Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅, Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ скобки, Ссли Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΈΡ… использованиС Π½Π΅ сдСлаСт Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π±ΠΎΠ»Π΅Π΅ понятным. НапримСр:

    7.4 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ if, if-else, if-else-if-else

    Π“Ρ€ΡƒΠΏΠΏΠ° ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ² (ΠΊΠ°ΠΊ ΠΈ Π΅Π΄Π΅Π½ΠΈΡ‡Π½ΠΎΠ΅ использованиС) if-else Π΄ΠΎΠ»ΠΆΠ½Π° ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ if всСгда Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡΡ с Ρ„ΠΈΠ³ΡƒΡ€Π½Ρ‹ΠΌΠΈ скобками » «. Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ Ρ„ΠΎΡ€ΠΌΡ‹:

    7.5 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° for

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° for Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    ΠŸΡƒΡΡ‚ΠΎΠΉ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° for (Ρ‚ΠΎΡ‚, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ вся Ρ€Π°Π±ΠΎΡ‚Π° выполняСтся Π² ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ, условии ΠΈ ΠΈΡ‚Π΅Ρ€Π°Ρ†ΠΈΠΈ) Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    ΠŸΡ€ΠΈ использовании ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° запятой Π² Π±Π»ΠΎΠΊΠ΅ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΈΠ»ΠΈ ΠΈΡ‚Π΅Ρ€Π°Ρ†ΠΈΠΈ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° Ρ†ΠΈΠΊΠ»Π° for ΠΈΠ·Π±Π΅Π³Π°ΠΉΡ‚Π΅ использования Π±ΠΎΠ»Π΅Π΅ Ρ‡Π΅ΠΌ Ρ‚Ρ€Π΅Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…. Если Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ ΠΏΠ΅Ρ€Π΅Π΄ Ρ†ΠΈΠΊΠ»ΠΎΠΌ for (для случая Π±Π»ΠΎΠΊΠ° ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ) ΠΈΠ»ΠΈ Π² ΠΊΠΎΠ½Ρ†Π΅ Ρ†ΠΈΠΊΠ»Π° (для случая Π±Π»ΠΎΠΊΠ° ΠΈΡ‚Π΅Ρ€Π°Ρ†ΠΈΠΈ).

    7.6 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° while

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° while Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    ΠŸΡƒΡΡ‚ΠΎΠΉ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° while Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    7.7 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° do-while

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° do-while Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    7.8 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ switch

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ switch Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ Ρ„ΠΎΡ€ΠΌΡƒ:

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ€Π°Π·, ΠΊΠΎΠ³Π΄Π° Π²Ρ‹Π±ΠΎΡ€ проваливаСтся (Π½Π΅ Π²ΠΊΠ»ΡŽΡ‡Π°Ρ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ break), Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ, Π³Π΄Π΅ ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ находится ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ break. Π­Ρ‚ΠΎ ΠΏΠΎΠΊΠ°Π·Π°Π½ΠΎ Π² ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΌ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅ ΠΊΠΎΠ΄Π° с ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ /* ΠΏΡ€ΠΎΠ²Π°Π» */.

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ switch Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²ΠΊΠ»ΡŽΡ‡Π°Ρ‚ΡŒ Π²Ρ‹Π±ΠΎΡ€ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ (default). ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ break Π² Π²Ρ‹Π±ΠΎΡ€Π΅ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ лишний, Π½ΠΎ ΠΎΠ½ ΠΏΡ€Π΅Π΄ΠΎΡ‚Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ Π²ΠΎΠ·Π½ΠΈΠΊΠ½ΠΎΠ²Π΅Π½ΠΈΠ΅ ошибки, Ссли ΠΏΠΎΠ·ΠΆΠ΅ Π΅Ρ‰Π΅ ​​один Π²Ρ‹Π±ΠΎΡ€ добавится.

    7.9 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ try-catch

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ try-catch Π΄ΠΎΠ»ΠΆΠ½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚:

    8.1 ΠŸΡƒΡΡ‚Ρ‹Π΅ строки

    ΠŸΡƒΡΡ‚Ρ‹Π΅ строки ΡƒΠ»ΡƒΡ‡ΡˆΠ°ΡŽΡ‚ Ρ‡ΠΈΡ‚Π°Π±Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ, выдСляя Ρ€Π°Π·Π΄Π΅Π»Ρ‹ ΠΊΠΎΠ΄Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ логичСски связаны ΠΌΠ΅ΠΆΠ΄Ρƒ собой.

    Π”Π²Π΅ пустыС строки всСгда Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… случаях:

    Одна пустая строка всСгда Π΄ΠΎΠ»ΠΆΠ½Π° ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… случаях:

    8.2 Расстановка ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ²

    Π Π°Π·Π΄Π΅Π»ΡΡŽΡ‰ΠΈΠ΅ ΠΏΡ€ΠΎΠ±Π΅Π»Ρ‹ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΡ‚Π°Π²ΠΈΡ‚ΡŒΡΡ ΠΏΡ€ΠΈ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… ΠΎΠ±ΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΡΡ‚Π²Π°Ρ…:

    ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ ΠΏΡ€ΠΎΠ±Π΅Π» Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ ΠΌΠ΅ΠΆΠ΄Ρƒ ΠΈΠΌΠ΅Π½Π΅ΠΌ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° ΠΈ Π΅Π³ΠΎ ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰Π΅ΠΉ скобкой. Π­Ρ‚ΠΎ ΠΏΠΎΠΌΠΎΠ³Π°Π΅Ρ‚ ΠΎΡ‚Π»ΠΈΡ‡Π°Ρ‚ΡŒ ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹Π΅ слова ΠΎΡ‚ Π²Ρ‹Π·ΠΎΠ²ΠΎΠ² ΠΌΠ΅Ρ‚ΠΎΠ΄Π°.

    ΠŸΡ€Π°Π²ΠΈΠ»Π°, ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Π½Ρ‹Π΅ Π² Π΄Π°Π½Π½ΠΎΠΌ Ρ€Π°Π·Π΄Π΅Π»Π΅, ΡΠ²Π»ΡΡŽΡ‚ΡΡ ΠΎΡΠ½ΠΎΠ²ΠΎΠΏΠΎΠ»Π°Π³Π°ΡŽΡ‰ΠΈΠΌΠΈ. Π‘ΠΎΠ»Π΅Π΅ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½Ρ‹Π΅ ΠΏΡ€Π°Π²ΠΈΠ»Π° ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Ρ‹ Π² Ρ‚Π°Π±Π»ΠΈΡ†Π΅:

    10.1 ΠžΠ±Π΅ΡΠΏΠ΅Ρ‡Π΅Π½ΠΈΠ΅ доступа ΠΊ экзСмпляру ΠΈ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ класса

    Одним ΠΈΠ· ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ² умСстного использования public ΠΏΠΎΠ»Π΅ΠΉ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ случай, ΠΊΠΎΠ³Π΄Π° класс описываСт лишь структуру Π΄Π°Π½Π½Ρ‹Ρ…, Π±Π΅Π· ΠΊΠ°ΠΊΠΎΠ³ΠΎ-Π»ΠΈΠ±ΠΎ повСдСния. Π”Ρ€ΡƒΠ³ΠΈΠΌΠΈ словами, Ссли Π±Ρ‹ Π²Ρ‹ ΠΌΠΎΠ³Π»ΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ struct вмСсто class (Ссли Π±Ρ‹ Java ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π» struct), Ρ‚ΠΎΠ³Π΄Π° ΠΌΠΎΠΆΠ½ΠΎ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ экзСмпляра класса public.

    10.2 ΠžΠ±Ρ€Π°Ρ‰Π΅Π½ΠΈΠ΅ ΠΊ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌ класса

    Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ использованиС ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° для доступа ΠΊ статичСским полям ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌ класса. ВмСсто этого ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ имя класса. НапримСр:

    10.3 ΠšΠΎΠ½ΡΡ‚Π°Π½Ρ‚Ρ‹

    ЧислСнныС константы (Π»ΠΈΡ‚Π΅Ρ€Π°Π»Ρ‹) Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ, Π·Π° ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ -1, 0 ΠΈ 1, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² Ρ†ΠΈΠΊΠ»Π°Ρ… для управлСния счСтчиком.

    10.4 ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ присваивания Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ ΠΈ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π°ΠΌ ΠΈ Ρ‚.Π΄.

    Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ присваивания значСния Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ Π² ΠΎΠ΄Π½ΠΎΠΌ Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠΈ. Π­Ρ‚ΠΎ услоТняСт Ρ‡Ρ‚Π΅Π½ΠΈΠ΅. НапримСр:

    НС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ присваивания Π² мСстах, Π³Π΄Π΅ ΠΎΠ½ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ Π»Π΅Π³ΠΊΠΎ спутан с ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ сравнСния. НапримСр:

    Π»ΡƒΡ‡ΡˆΠ΅ Π½Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Π°ΠΊ:

    НС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Π΅ присваивания, ΠΏΡ‹Ρ‚Π°ΡΡΡŒ ΡƒΡΠΊΠΎΡ€ΠΈΡ‚ΡŒ ΡΠΊΠΎΡ€ΠΎΡΡ‚ΡŒ выполнСния ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹. Π­Ρ‚ΠΎ Ρ€Π°Π±ΠΎΡ‚Π° компилятора, ΠΈ, ΠΊΡ€ΠΎΠΌΠ΅ Ρ‚ΠΎΠ³ΠΎ, Π½Π° самом Π΄Π΅Π»Π΅ Ρ€Π΅Π΄ΠΊΠΎ ΠΏΠΎΠΌΠΎΠ³Π°Π΅Ρ‚. НапримСр:

    Π΄ΠΎΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ написано Ρ‚Π°ΠΊ:

    10.5 Π Π°Π·Π»ΠΈΡ‡Π½Ρ‹Π΅ ΠΏΡ€ΠΈΡ‘ΠΌΡ‹ программирования
    10.5.1 ΠšΡ€ΡƒΠ³Π»Ρ‹Π΅ скобки
    10.5.2 Π’ΠΎΠ·Π²Ρ€Π°Ρ‚ значСния

    ΠŸΠΎΠΏΡ€ΠΎΠ±ΡƒΠΉΡ‚Π΅ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ структуру вашСй ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ понятной. НапримСр:

    вмСсто этого слСдуСт Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Π°ΠΊ:

    Π»ΡƒΡ‡ΡˆΠ΅ Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Π°ΠΊ:

    10.5.3 ВыраТСния ΠΏΠ΅Ρ€Π΅Π΄ ‘?’ Π² условном ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π΅

    Если Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ содСрТит Π±ΠΈΠ½Π°Ρ€Π½Ρ‹ΠΉ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€, находящийся ΠΏΠ΅Ρ€Π΅Π΄ Ρ‚Π΅Ρ€Π½Π°Ρ€Π½Ρ‹ΠΌ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ ?:, ΠΎΠ½ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Π·Π°ΠΊΠ»ΡŽΡ‡Π΅Π½ Π² скобки. НапримСр:

    10.5.4 Π‘ΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ

    Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ XXX Π² ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎ этот ΠΊΠΎΠ΄ Π½Π΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ, Π½ΠΎ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚. Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ FIXME для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎ ΠΊΠΎΠ΄ Π½Π΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ ΠΈ Π½Π΅ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚.

    11.1 ΠŸΡ€ΠΈΠΌΠ΅Ρ€ Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java

    Π‘Π»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ ΠΊΠ°ΠΊ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Ρ„Π°ΠΉΠ» с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java, содСрТащим ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ класс. Π˜Π½Ρ‚Π΅Ρ€Ρ„Π΅ΠΉΡΡ‹ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ΡΡ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ. Для Π±ΠΎΠ»Π΅Π΅ ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½ΠΎΠ³ΠΎ изучСния ΠΏΡ€ΠΎΡ‡Ρ‚ΠΈΡ‚Π΅ «ΠžΠ±ΡŠΡΠ²Π»Π΅Π½ΠΈΠ΅ классов ΠΈ интСрфСйсов» ΠΈ «Π”ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠ΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ«.

    Π’Π΅Ρ€ΡΠΈΡŽ для ΠΎΡ„Ρ„Π»Π°ΠΉΠ½ чтСния ΠΌΠΎΠΆΠ½ΠΎ Π½Π°ΠΉΡ‚ΠΈ Π² ΠΌΠΎΠ΅ΠΌ Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΈ Github

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java code conventions

    The information on this page is for Archive Purposes Only

    This page is not being actively maintained. Links within the documentation may not work and the information itself may no longer be valid. The last revision to this document was made on April 20, 1999

    10.1 Providing Access to Instance and Class Variables

    Don’t make any instance or class variable public without good reason. Often, instance variables don’t need to be explicitly set or gotten-often that happens as a side effect of method calls.

    10.2 Referring to Class Variables and Methods

    Avoid using an object to access a class (static) variable or method. Use a class name instead. For example:

    10.3 Constants

    10.4 Variable Assignments

    Avoid assigning several variables to the same value in a single statement. It is hard to read. Example:

    fooBar.fChar = barFoo.lchar = ‘c’; // AVOID!

    Do not use the assignment operator in a place where it can be easily confused with the equality operator. Example:

    should be written as

    Do not use embedded assignments in an attempt to improve run-time performance. This is the job of the compiler. Example:

    d = (a = b + c) + r; // AVOID!

    should be written as

    10.5 Miscellaneous Practices

    10.5.1 Parentheses

    It is generally a good idea to use parentheses liberally in expressions involving mixed operators to avoid operator precedence problems. Even if the operator precedence seems clear to you, it might not be to others-you shouldn’t assume that other programmers know precedence as well as you do.

    10.5.2 Returning Values

    Try to make the structure of your program match the intent. Example:

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java code conventions

    The information on this page is for Archive Purposes Only

    This page is not being actively maintained. Links within the documentation may not work and the information itself may no longer be valid. The last revision to this document was made on April 20, 1999

    7.1 Simple Statements

    Each line should contain at most one statement. Example:

    7.2 Compound Statements

    Compound statements are statements that contain lists of statements enclosed in braces » < statements >«. See the following sections for examples.

    7.3 return Statements

    A return statement with a value should not use parentheses unless they make the return value more obvious in some way. Example:

    7.4 if, if-else, if else-if else Statements

    The if-else class of statements should have the following form:

    7.5 for Statements

    A for statement should have the following form:

    An empty for statement (one in which all the work is done in the initialization, condition, and update clauses) should have the following form:

    When using the comma operator in the initialization or update clause of a for statement, avoid the complexity of using more than three variables. If needed, use separate statements before the for loop (for the initialization clause) or at the end of the loop (for the update clause).

    7.6 while Statements

    A while statement should have the following form:

    An empty while statement should have the following form:

    7.7 do-while Statements

    A do-while statement should have the following form:

    7.8 switch Statements

    A switch statement should have the following form:

    Every time a case falls through (doesn’t include a break statement), add a comment where the break statement would normally be. This is shown in the preceding code example with the /* falls through */ comment.

    Every switch statement should include a default case. The break in the default case is redundant, but it prevents a fall-through error if later another case is added.

    7.9 try-catch Statements

    A try-catch statement should have the following format:

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java Code Style: ΠΊΠ°ΠΊ ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»ΡΡ‚ΡŒ ΠΊΠΎΠ΄ Java

    Π‘Ρ‚Π°Ρ‚ΡŒΡ ΠΎΠ± ΠΈΠΌΠ΅Π½Π°Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…, классов ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ², скобках, коммСнтариях, Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ ΠΊΠΎΠ΄Π° ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΡ… ΠΏΡ€Π°Π²ΠΈΠ»Π°Ρ… Ρ…ΠΎΡ€ΠΎΡˆΠ΅Π³ΠΎ Ρ‚ΠΎΠ½Π°, принятых Π² языкС JavΠ°.

    Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ Java code conventions. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ Java code conventions. Π€ΠΎΡ‚ΠΎ Java code conventions

    Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ Java code conventions. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ Java code conventions. Π€ΠΎΡ‚ΠΎ Java code conventions

    Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ Java code conventions. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ Java code conventions. Π€ΠΎΡ‚ΠΎ Java code conventions

    Π’ языкС Java, ΠΊΠ°ΠΊ ΠΈ Π²ΠΎ ΠΌΠ½ΠΎΠ³ΠΈΡ… Π΄Ρ€ΡƒΠ³ΠΈΡ… языках программирования, Π΅ΡΡ‚ΡŒ Π½Π΅ΠΎΡ„ΠΈΡ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅, Π½ΠΎ принятыС сообщСством Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΎΠ² соглашСния ΠΏΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ ΠΊΠΎΠ΄Π°. Π”Π°Π²Π°ΠΉΡ‚Π΅ ΠΏΠΎΠΏΡ€ΠΎΠ±ΡƒΠ΅ΠΌ Ρ€Π°Π·ΠΎΠ±Ρ€Π°Ρ‚ΡŒΡΡ, Ρ‡Ρ‚ΠΎ это Ρ‚Π°ΠΊΠΎΠ΅, ΠΊΠ°ΠΊ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ ΠΈ ΠΏΠΎΡ‡Π΅ΠΌΡƒ Π²Π°ΠΆΠ½ΠΎ.

    Π—Π°Ρ‡Π΅ΠΌ Π½ΡƒΠΆΠ΅Π½ Π΅Π΄ΠΈΠ½Ρ‹ΠΉ ΡΡ‚ΠΈΠ»ΡŒ ΠΊΠΎΠ΄Π°

    Java Code Style β€” это Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄Π°Ρ†ΠΈΠΈ ΠΈ соглашСния ΠΎ стилС ΠΊΠΎΠ΄Π°, собранныС вмСстС. НапримСр:

    РСгламСнтируСтся мноТСство Π²Π΅Ρ‰Π΅ΠΉ, связанных с ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΠ΅ΠΌ исходного тСкста ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌ, ΠΈ приводятся трСбования, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΡƒΡ‡ΠΈΡ‚Ρ‹Π²Π°Ρ‚ΡŒ. ΠŸΠΎΡ‡Π΅ΠΌΡƒ Π²ΠΎΠ·Π½ΠΈΠΊΠ»ΠΈ эти стандарты?

    ΠŸΡ€ΠΈΡ‡ΠΈΠ½Ρ‹, ΠΏΠΎ ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΈ ΠΏΡ€ΠΈΡˆΠ»ΠΈ ΠΊ Ρ‚Π°ΠΊΠΈΠΌ соглашСниям, Π»ΠΎΠ³ΠΈΡ‡Π½Ρ‹ ΠΈ просты:

    ИспользованиС общСпринятых соглашСний ΠΏΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ позволяСт ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ΠΊΠΎΠ΄ Π±ΠΎΠ»Π΅Π΅ Π°ΠΊΠΊΡƒΡ€Π°Ρ‚Π½Ρ‹ΠΌ, ΠΈΠ·Π±Π΅ΠΆΠ°Ρ‚ΡŒ ошибок, связанных с Ρ€Π°Π·Π½Ρ‹ΠΌΠΈ стилями написания Ρƒ людСй, Ρ€Π°Π±ΠΎΡ‚Π°ΡŽΡ‰ΠΈΡ… Π½Π°Π΄ ΠΎΠ΄Π½ΠΈΠΌ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ΠΎΠΌ.

    Π€ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π½Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ΅

    Π‘Ρ‚ΠΈΠ»ΡŒ Π½Π΅ ΠΈΠ³Ρ€Π°Π΅Ρ‚ Ρ€ΠΎΠ»ΠΈ для ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Π°, Π½ΠΎ Π²Π°ΠΆΠ΅Π½ для чтСния ΠΊΠΎΠ΄Π° Ρ‡Π΅Π»ΠΎΠ²Π΅ΠΊΠΎΠΌ. НашС Π·Ρ€Π΅Π½ΠΈΠ΅ устроСно Ρ‚Π°ΠΊ, Ρ‡Ρ‚ΠΎ спСрва ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ ΠΈ Π°Π½Π°Π»ΠΈΠ·ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΎΠ±Ρ€Π°Π·Ρ‹, Π° Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π·Π°Ρ‚Π΅ΠΌ ΠΌΡ‹ вдаёмся Π² Π΄Π΅Ρ‚Π°Π»ΠΈ. А Ссли Π±Π»ΠΎΠΊΠΈ исходного тСкста ΡƒΠ½ΠΈΡ„ΠΈΡ†ΠΈΡ€ΠΎΠ²Π°Π½Ρ‹, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ ΠΏΠΎΠ½ΠΈΠΌΠ°Π΅Ρ‚, Ρ‡Ρ‚ΠΎ ΠΏΠ΅Ρ€Π΅Π΄ Π½ΠΈΠΌ Π·Π° конструкция, Π΄Π°ΠΆΠ΅ Π½Π΅ вникая Π² сам ΠΊΠΎΠ΄.

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Nikolay995 / JavaCodeStyle.md

    Π€Π°ΠΉΠ»Ρ‹ с исходным ΠΊΠΎΠ΄ΠΎΠΌ

    Π€Π°ΠΉΠ»Ρ‹ с исходным ΠΊΠΎΠ΄ΠΎΠΌ хранятся Π² ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ΅ UTF-8.

    Π‘ΠΈΠΌΠ²ΠΎΠ»Ρ‹ пустого мСста

    ΠšΡ€ΠΎΠΌΠ΅ символов ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄Π° строки, Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ASCII-ΠΏΡ€ΠΎΠ±Π΅Π» (0x20) встрСчаСтся Π² Ρ„Π°ΠΉΠ»Π°Ρ…. Π­Ρ‚ΠΎ ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚:

    Для любого символа, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΈΠΌΠ΅Π΅Ρ‚ ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½ΡƒΡŽ escape-ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ (b, \t, \n, \f, \r, «, ‘ ΠΈ \), эта ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ вмСсто ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π³ΠΎ octal (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ \012) ΠΈΠ»ΠΈ Unicode-символа (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ \u000a).

    Для ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Ρ… Π½Π΅-ASCII символов, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ ΠΈΠ»ΠΈ сам Unicode-символ (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ∞) ΠΈΠ»ΠΈ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ Unicode escape-символ (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ \u221e). Π’Ρ‹Π±ΠΎΡ€ символа зависит Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎ Ρ‚ΠΎΠ³ΠΎ, насколько Π»Π΅Π³ΠΊΠΎ ΠΊΠΎΠ΄ с Π½ΠΈΠΌ Ρ‡ΠΈΡ‚Π°Ρ‚ΡŒ ΠΈ ΠΏΠΎΠ½ΠΈΠΌΠ°Ρ‚ΡŒ, хотя Unicode escape-символы Π²Π½Π΅ строковых Π»ΠΈΡ‚Π΅Ρ€Π°Π»ΠΎΠ² ΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² Π²ΡΡ‚Π°Π²Π»ΡΡ‚ΡŒ Π½Π΅ рСкомСндуСтся.

    Π‘ΠΎΠ²Π΅Ρ‚: Π² случаС использования Unicode escape-символа, ΠΈ ΠΈΠ½ΠΎΠ³Π΄Π° Π΄Π°ΠΆΠ΅ ΠΊΠΎΠ³Π΄Π° ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ сам Unicode символ, ΠΏΠΎΡΡΠ½ΡΡŽΡ‰ΠΈΠ΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΠΎΠ»Π΅Π·Π½Ρ‹.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ€ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ
    String unitAbbrev = «ΞΌs»;Π›ΡƒΡ‡ΡˆΠΈΠΉ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚: всС ясно Π΄Π°ΠΆΠ΅ Π±Π΅Π· коммСнтария
    String unitAbbrev = «\u03bcs»; // «ΞΌs»Π Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ся, Π½ΠΎ Π½Π΅Ρ‚ ΠΏΡ€ΠΈΡ‡ΠΈΠ½Ρ‹ Ρ‚Π°ΠΊ Π΄Π΅Π»Π°Ρ‚ΡŒ
    String unitAbbrev = «\u03bcs»; // Greek letter mu, «s»Π Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ся, Π½ΠΎ странно выглядит ΠΈ нСустойчиво ΠΊ ошибкам
    String unitAbbrev = «\u03bcs»;ΠŸΠ»ΠΎΡ…ΠΎ: Ρ‡ΠΈΡ‚Π°Ρ‚Π΅Π»ΡŒ Π½Π΅ ΠΏΠΎΠΉΠΌΠ΅Ρ‚, Ρ‡Ρ‚ΠΎ это Ρ‚Π°ΠΊΠΎΠ΅
    return ‘\ufeff’ + content; // byte order markΠ₯ΠΎΡ€ΠΎΡˆΠΎ: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ escape-символ для Π½Π΅ΠΏΠ΅Ρ‡Π°Ρ‚Π½Ρ‹Ρ… символов, ΠΈ Π΅ΡΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚

    Π‘ΠΎΠ²Π΅Ρ‚: Π½Π΅ Π΄Π΅Π»Π°ΠΉΡ‚Π΅ ваш ΠΊΠΎΠ΄ ΠΌΠ΅Π½Π΅Π΅ Ρ‡ΠΈΡ‚Π°Π΅ΠΌΡ‹ΠΌ просто ΠΈΠ· боязни, Ρ‡Ρ‚ΠΎ какая-Π»ΠΈΠ±ΠΎ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ° Π½Π΅ смоТСт ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π΅-ASCII символы Π²Π΅Ρ€Π½ΠΎ. Если Ρ‚Π°ΠΊΠΎΠ΅ случаСтся, Π·Π½Π°Ρ‡ΠΈΡ‚ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ° Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Π½Π΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ ΠΈ Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ ΠΏΠΎΡ‡ΠΈΠ½Π΅Π½Π°.

    Π€Π°ΠΉΠ» с исходным ΠΊΠΎΠ΄ΠΎΠΌ состоит ΠΈΠ·:

    Π‘Π΅ΠΊΡ†ΠΈΠΈ Ρ€Π°Π·Π΄Π΅Π»ΡΡŽΡ‚ΡΡ ΠΎΠ΄Π½ΠΎΠΉ пустой Π»ΠΈΠ½ΠΈΠ΅ΠΉ.

    Имя ΠΏΠ°ΠΊΠ΅Ρ‚Π° Π½Π΅ раздСляСтся пСрСносом строки. Заданная Π½Π°ΠΌΠΈ Π΄Π»ΠΈΠ½Π° строки Π½Π΅ распространяСтся Π½Π° строку с ΠΈΠΌΠ΅Π½Π΅ΠΌ ΠΏΠ°ΠΊΠ΅Ρ‚Π°.

    ИспользованиС wildcard ΠΈ static ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΎΠ² Π½Π΅ рСкомСндуСтся. Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: Ссли ситуация ΠΎΠΏΡ€Π°Π²Π΄Π°Π½Π°, ΠΈ всС испортируСмыС ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ ΠΈ константы Π±Π»ΠΈΠ·ΠΊΠΈ ΠΏΠΎ смыслу ΠΊ классу Π² Π΄Π°Π½Π½ΠΎΠΌ Ρ„Π°ΠΉΠ»Π΅.

    Π˜ΠΌΠΏΠΎΡ€Ρ‚ Π½Π΅ раздСляСтся пСрСносом строки. Заданная Π½Π°ΠΌΠΈ Π΄Π»ΠΈΠ½Π° строки Π½Π΅ распространяСтся Π½Π° строку с ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΎΠΌ класса.

    НСт ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΡ€Π°Π²ΠΈΠ» Π½Π° порядок ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΎΠ². ΠŸΡ€ΠΈΠ΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡΡ стиля, Π·Π°Π΄Π°Π½Π½ΠΎΠ³ΠΎ ΠΏΠΎ-ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ Π² ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΠΎΠΉ всСми IDE.

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ класс Π²Π΅Ρ€Ρ…Π½Π΅Π³ΠΎ уровня находится Π² ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎΠΌ Ρ„Π°ΠΉΠ»Π΅ с Π΅Π³ΠΎ ΠΈΠΌΠ΅Π½Π΅ΠΌ.

    ΠŸΠΎΡ€ΡΠ΄ΠΎΠΊ располоТСния Ρ‡Π»Π΅Π½ΠΎΠ² класса

    Π§Π»Π΅Π½Ρ‹ классы Ρ€Π°ΡΠΏΠΎΠ»Π°Π³Π°ΡŽΡ‚ΡΡ Π² Ρ‚Π°ΠΊΠΎΠΌ порядкС:

    НС Ρ€Π°Π·Ρ€Ρ‹Π²Π°Π΅ΠΌ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ ΠΏΠ΅Ρ€Π΅Π³Ρ€ΡƒΠΆΠ΅Π½Π½Ρ‹Ρ… ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ²

    Если Ρƒ класса Π΅ΡΡ‚ΡŒ нСсколько конструкторов ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² с ΠΎΠ΄Π½ΠΈΠΌ ΠΈ Ρ‚Π΅ΠΌ ΠΆΠ΅ ΠΈΠΌΠ΅Π½Π΅ΠΌ, ΠΎΠ½ΠΈ Ρ€Π°ΡΠΏΠΎΠ»Π°Π³Π°ΡŽΡ‚ΡΡ Π΄Ρ€ΡƒΠ³ Π·Π° Π΄Ρ€ΡƒΠ³ΠΎΠΌ, Π±Π΅Π· Π²ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ Π΄Ρ€ΡƒΠ³ΠΈΡ… ΠΏΠΎΠ»Π΅ΠΉ/ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ²

    Π‘Ρ‚Π°Π²ΠΈΠΌ скобки, Π΄Π°ΠΆΠ΅ Ссли это Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ

    НСпустыС Π±Π»ΠΎΠΊΠΈ: ΡΡ‚ΠΈΠ»ΡŒ K & R

    Π‘ΠΊΠΎΠ±ΠΊΠΈ ставятся Π² соотвСтствии со стилСм ΠšΠ΅Ρ€Π½ΠΈΠ³Π°Π½Π° ΠΈ Π ΠΈΡ‡ΠΈ (ЕгипСтскиС скобки) для нСпустых Π±Π»ΠΎΠΊΠΎΠ²:

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ Π΄Π΅Π»Π°ΡŽΡ‚ΡΡ для Enum-классов.

    ΠŸΡƒΡΡ‚Ρ‹Π΅ Π±Π»ΠΎΠΊΠΈ Π½Π΅ ΡƒΠΊΠΎΡ€Π°Ρ‡ΠΈΠ²Π°Π΅ΠΌ

    Π‘Ρ‚Π°Π²ΠΈΠΌ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ строки ΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ, Π΄Π°ΠΆΠ΅ Ссли Ρ‚Π΅Π»ΠΎ Π±Π»ΠΎΠΊΠ° пустоС:

    ΠžΡ‚ΡΡ‚ΡƒΠΏΡ‹ слСва для Π±Π»ΠΎΠΊΠΎΠ²

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ€Π°Π·, ΠΊΠΎΠ³Π΄Π° ΠΌΡ‹ ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ Π½ΠΎΠ²Ρ‹ΠΉ Π±Π»ΠΎΠΊ, отступ увСличиваСтся Π½Π° 2 ΠΏΡ€ΠΎΠ±Π΅Π»Π°. Когда Π±Π»ΠΎΠΊ заканчиваСтся, отступ возвращаСтся Π΄ΠΎ ΠΏΡ€Π΅ΠΆΠ½Π΅Π³ΠΎ значСния. ΠžΡ‚ΡΡ‚ΡƒΠΏ примСняСтся ΠΈ для ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² Π² Π±Π»ΠΎΠΊΠ΅.

    Одно Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π½Π° строку

    КаТдоС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΈΠ»ΠΈ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ заканчиваСтся ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ΠΎΠΌ строки.

    Π”Π»ΠΈΠ½Π° строки Π² ΠΊΠΎΠ΄Π΅ ΠΈΠΌΠ΅Π΅Ρ‚ Π»ΠΈΠΌΠΈΡ‚ Π² 120 символов. ΠšΡ€ΠΎΠΌΠ΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΉ, любая строка большС Π»ΠΈΠΌΠΈΡ‚Π° Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·Π±ΠΈΡ‚Π° Π½Π° 2 строки, ΠΊΠ°ΠΊ описано Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ ΠŸΠ΅Ρ€Π΅Π½ΠΎΡ строки.

    ΠŸΡ€ΠΈ пСрСносС строк, каТдая пСрСнСсСнная строка послС самой ΠΏΠ΅Ρ€Π²ΠΎΠΉ отступаСт слСва Π½Π° 8 ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² ΠΎΡ‚ Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎΠΉ строки. Π’ ΠΎΠ±Ρ‰Π΅ΠΌ случаС, отступ для 2 пСрСнСсСнных строк Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ссли Π½Π°Ρ‡ΠΈΠ½Π°ΡŽΡ‚ΡΡ с синтаксичСски ΠΏΠ°Ρ€Π°Π»Π»Π΅Π»ΡŒΠ½Ρ‹Ρ… конструкций.

    Π’Π΅Ρ€Ρ‚ΠΈΠΊΠ°Π»ΡŒΠ½ΠΎΠ΅ пустоС мСсто

    Одна пустая строка стоит:

    НСсколько пустых строк подряд Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ΡΡ, Π½ΠΎ Π½Π΅ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ.

    Π“ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½ΠΎΠ΅ пустоС мСсто

    ΠžΠ΄ΠΈΠ½ΠΎΡ‡Π½Ρ‹ΠΉ ASCII-ΠΏΡ€ΠΎΠ±Π΅Π» встрСчаСтся Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… мСстах (ΠΏΠΎΠΌΠΈΠΌΠΎ трСбования синтаксиса языка, Π»ΠΈΡ‚Π΅Ρ€Π°Π»ΠΎΠ², ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΎΠ² ΠΈ javadoc):

    ΠŸΡ€Π°Π²ΠΈΠ»Π° относятся ΠΊ ΠΏΡ€ΠΎΠ±Π΅Π»Π°ΠΌ Π²Π½ΡƒΡ‚Ρ€ΠΈ строки, Π° Π½Π΅ отступам (ΠΎΠ³ΠΎΠ²Π°Ρ€ΠΈΠ²Π°ΡŽΡ‚ΡΡ Π² Π΄Ρ€ΡƒΠ³ΠΎΠΌ Ρ€Π°Π·Π΄Π΅Π»Π΅).

    Π“ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½ΠΎΠ΅ Π²Ρ‹Ρ€Π°Π²Π½ΠΈΠ²Π°Π½ΠΈΠ΅ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ

    Π’Ρ‹Ρ€Π°Π²Π½ΠΈΠ²Π°Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ ΡƒΠ»ΡƒΡ‡ΡˆΠΈΡ‚ΡŒ Ρ‡ΠΈΡ‚Π°Π΅ΠΌΠΎΡΡ‚ΡŒ, Π½ΠΎ создаСт ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡ‹ для дальнСйшСй ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΈ. Допустим, ΠΏΠΎΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅Π΅ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ Π·Π°Ρ‚Ρ€Π°Π³ΠΈΠ²Π°Π΅Ρ‚ всСго 1 строку. Часто Ρ‚Π°ΠΊΠΎΠ΅ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ сбиваСт Π²Ρ‹Ρ€Π°Π²Π½ΠΈΠ²Π°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ выглядит ΡƒΠΆΠ΅ Π½Π΅ Ρ‚Π°ΠΊ Ρ…ΠΎΡ€ΠΎΡˆΠΎ. Но Ρ‡Π°Ρ‰Π΅ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ стрСмится ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ порядок выравнивания ΠΈ мСняСт оступы Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… строках, инициируя ΠΊΠ°ΡΠΊΠ°Π΄Π½ΡƒΡŽ ΡΠ΅Ρ€ΠΈΡŽ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΉ. Π­Ρ‚ΠΎ однострочноС ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ Ρ‚Π΅ΠΏΠ΅Ρ€ΡŒ ΠΈΠΌΠ΅Π΅Ρ‚ «Ρ€Π°Π΄ΠΈΡƒΡ пораТСния». Π­Ρ‚ΠΎ бСсполСзная Ρ€Π°Π±ΠΎΡ‚Π°, Ρ‚Π°ΠΊΠΆΠ΅ это ΡƒΡ…ΡƒΠ΄ΡˆΠ°Π΅Ρ‚ Ρ‡ΠΈΡ‚Π°Π΅ΠΌΠΎΡΡ‚ΡŒ истории вСрсий, замСдляСт Ρ€Π΅Π²ΡŒΡŽΠ΅Ρ€ΠΎΠ² ΠΈ затрудняСт Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅ merge-ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ΠΎΠ².

    ПослС ΠΊΠ°ΠΆΠ΄ΠΎΠΉ запятой послС опрСдСлСния Enum-константы Π½ΡƒΠΆΠ΅Π½ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ строки. Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ допускаСтся пустая строка послС этого. ΠŸΡ€ΠΈΠΌΠ΅Ρ€:

    Enum-классы Π² ΠΎΡΡ‚Π°Π»ΡŒΠ½ΠΎΠΌ ΠΏΠΎΠ΄Ρ‡ΠΈΠ½ΡΡŽΡ‚ΡΡ ΠΎΠ±Ρ‰ΠΈΠΌ ΠΏΡ€Π°Π²ΠΈΠ»Π°ΠΌ оформлСния классов.

    Π’ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ строкС опрСдСляСтся Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄Π½Π° пСрСмСнная

    КаТдоС ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ (ΠΏΠΎΠ»Π΅ ΠΈΠ»ΠΈ локальная пСрСмСнная) состоит Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΈΠ· ΠΎΠ΄Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ: опрСдСлСния Π²ΠΈΠ΄Π° int a, b; Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ.

    ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ ΠΏΠΎ ΠΌΠ΅Ρ€Π΅ надобности

    Π›ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π½Π΅ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ опрСдСлятся Π² Π½Π°Ρ‡Π°Π»Π΅ Π±Π»ΠΎΠΊΠ° ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π°. ВмСсто этого, ΠΎΠ½ ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ ΠΊΠ°ΠΊ ΠΌΠΎΠΆΠ½ΠΎ Π±Π»ΠΈΠΆΠ΅ ΠΊ мСсту ΠΈΡ… ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ использования, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΡƒΠΌΠ΅Π½ΡŒΡˆΠΈΡ‚ΡŒ ΠΎΠ±Π»Π°ΡΡ‚ΡŒ дСйствия ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ. Π›ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΊΠ°ΠΊ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ сразу ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΡŽΡ‚ΡΡ.

    ΠšΠ²Π°Π΄Ρ€Π°Ρ‚Π½Ρ‹Π΅ скобки ставятся рядом с Ρ‚ΠΈΠΏΠΎΠΌ, Π° Π½Π΅ самой ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ: String[] args, Π½ΠΎ Π½Π΅ String args[].

    Π’Π½ΡƒΡ‚Ρ€ΠΈ скобок Π² switch-Π±Π»ΠΎΠΊΠ΅ Ρ€Π°ΡΠΏΠΎΠ»Π°Π³Π°ΡŽΡ‚ΡΡ ΠΎΠ΄Π½Π° ΠΈΠ»ΠΈ нСсколько Π³Ρ€ΡƒΠΏΠΏ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ². КаТдая Π³Ρ€ΡƒΠΏΠΏΠ° содСрТит ΠΎΠ΄Π½Ρƒ ΠΈΠ»ΠΈ нСсколько ΠΌΠ΅Ρ‚ΠΎΠΊ (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ FOO: ΠΈΠ»ΠΈ default:), Π·Π° ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΉ ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹.

    Как ΠΈ с Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ Π±Π»ΠΎΠΊΠ°ΠΌΠΈ, оступ для содСрТимого составляСт +2 ΠΏΡ€ΠΎΠ±Π΅Π»Π°. ПослС ΠΌΠ΅Ρ‚ΠΊΠΈ стоит ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ строки, ΠΈ отступ снова увСличиваСтся Π½Π° +2, ΠΊΠ°ΠΊ Π² случаС с ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΠΈΠ΅ΠΌ Π½ΠΎΠ²ΠΎΠ³ΠΎ Π±Π»ΠΎΠΊΠ°. Π‘Π»Π΅Π΄ΡƒΡŽΡ‰Π°Ρ ΠΌΠ΅Ρ‚ΠΊΠ° находится Π½Π° ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΌ ΡƒΡ€ΠΎΠ²Π½Π΅, ΠΊΠ°ΠΊ Π±ΡƒΠ΄Ρ‚ΠΎ Π±Π»ΠΎΠΊ закрылся.

    ΠŸΡ€ΠΎΠ²Π°Π»Ρ‹ Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ ΠΌΠ΅Ρ‚ΠΊΠΈ: Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ дСлаСтся Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для пустых ΠΌΠ΅Ρ‚ΠΎΠΊ (ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π²Ρ‹ΡˆΠ΅ с case 1:). Для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ switch Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ default-ΠΌΠ΅Ρ‚ΠΊΠ°, Π΄Π°ΠΆΠ΅ Ссли ΠΎΠ½Π° Π½Π΅ содСрТит ΠΊΠΎΠ΄Π°.

    Аннотации, примСняСмыС ΠΊ классу, ΠΌΠ΅Ρ‚ΠΎΠ΄Ρƒ ΠΈΠ»ΠΈ конструктору ставятся сразу послС Π±Π»ΠΎΠΊΠ° Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ, ΠΈ находятся Π½Π° ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎΠΉ строкС (ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΉ Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠΈ Π½Π° строкС). ΠžΡ‚ΡΡ‚ΡƒΠΏ слСва послС Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠΈ Π½Π΅ увСличиваСтся. ΠŸΡ€ΠΈΠΌΠ΅Ρ€:

    НСт ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΡ€Π°Π²ΠΈΠ» для форматирования Π°Π½Π½Ρ‚ΠΎΡ‚Π°Ρ†ΠΈΠΉ Π½Π° ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°Ρ…, Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…, Ρ‚ΠΈΠΏΠ°Ρ….

    ΠœΠΎΠ΄ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€Ρ‹ классов ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² ставятся Π² порядкС, Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄ΠΎΠ²Π°Π½Π½ΠΎΠΌ Java Language Specification:

    public protected private abstract default static final transient volatile synchronized native strictfp

    ЧисловыС Π»ΠΈΡ‚Π΅Ρ€Π°Π»Ρ‹ Ρ‚ΠΈΠΏΠ° long ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ Π±ΠΎΠ»ΡŒΡˆΡƒΡŽ Π±ΡƒΠΊΠ²Ρƒ L, Π½ΠΈΠΊΠΎΠ³Π΄Π° Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Π½ΠΈΠΆΠ½ΠΈΠΉ рСгистр (Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΈΠ·Π±Π΅ΠΆΠ°Ρ‚ΡŒ ΠΏΡƒΡ‚Π°Π½ΠΈΡ†Ρ‹ с Ρ†ΠΈΡ„Ρ€ΠΎΠΉ 1). НапримСр, Π½Π°Π΄ΠΎ ΠΏΠΈΡΠ°Ρ‚ΡŒ 3000000000L вмСсто 3000000000l.

    ΠŸΡ€Π°Π²ΠΈΠ»Π° для всСх ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ΠΎΠ²

    ИмСна ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠ² ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² Π½ΠΈΠΆΠ½Π΅ΠΌ рСгистрС, слова просто ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ ΠΊΠΎΠ½ΠΊΠ°Ρ‚Π΅Π½ΠΈΡ€ΡƒΡŽΡ‚ΡΡ Π΄Ρ€ΡƒΠ³ с Π΄Ρ€ΡƒΠ³ΠΎΠΌ (Π±Π΅Π· Π½ΠΈΠΆΠ½ΠΈΡ… ΠΏΠΎΠ΄Ρ‡Π΅Ρ€ΠΊΠΈΠ²Π°Π½ΠΈΠΉ). НапримСр, com.example.deepspace, Π° Π½Π΅ com.example.deepSpace ΠΈΠ»ΠΈ com.example.deep_space.

    ИмСна классов ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² UpperCamelCase.

    НСт ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΡ€Π°Π²ΠΈΠ» для имСнования Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠΉ.

    ВСстовыС классы Π½Π°Ρ‡ΠΈΠ½Π°ΡŽΡ‚ΡΡ с ΠΈΠΌΠ΅Π½ΠΈ класса, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΠ½ΠΈ Ρ‚Π΅ΡΡ‚ΠΈΡ€ΡƒΡŽΡ‚, ΠΈ Π·Π°ΠΊΠ°Π½Ρ‡ΠΈΠ²Π°ΡŽΡ‚ΡΡ Π½Π° Test. НапримСр, HashTest ΠΈΠ»ΠΈ HashIntegrationTest.

    ИмСна ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² lowerCamelCase.

    ИмСна констант ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ CONSTANT_CASE: всС Π±ΡƒΠΊΠ²Ρ‹ Π² Π²Π΅Ρ€Ρ…Π½Π΅ΠΌ рСгистрС, слова ΠΎΡ‚Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Π½ΠΈΠΆΠ½ΠΈΠΌ ΠΏΠΎΠ΄Ρ‡Π΅Ρ€ΠΊΠΈΠ²Π°Π½ΠΈΠ΅ΠΌ. Но Ρ‡Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ константа?

    КаТдая константа являСтся static final ΠΏΠΎΠ»Π΅ΠΌ, Π½ΠΎ Π½Π΅ всС static final поля ΡΠ²Π»ΡΡŽΡ‚ΡΡ константами. ΠŸΡ€Π΅ΠΆΠ΄Π΅ Ρ‡Π΅ΠΌ ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ константой, ΠΏΠΎΠ΄ΡƒΠΌΠ°ΠΉΡ‚Π΅ Ρ€Π΅Π°Π»ΡŒΠ½ΠΎ Π»ΠΈ ΠΎΠ½Π° являСтся Π΅ΠΉ. НапримСр, Ссли Π²ΠΈΠ΄ΠΈΠΌΠΎΠ΅ состояниС экзСмпляра ΠΎΠ±ΡŒΠ΅ΠΊΡ‚Π° ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒΡΡ, это Ρ‚ΠΎΡ‡Π½ΠΎ Π½Π΅ константа. ΠŸΡ€ΠΎΡΡ‚ΠΎ мысли ΠΎ Ρ‚ΠΎΠΌ, Ρ‡Ρ‚ΠΎ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΌΠ΅Π½ΡΡ‚ΡŒΡΡ Π² процСссС Ρ€Π°Π±ΠΎΡ‚Ρ‹, Π½Π΅ достаточно. ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹:

    ИмСна нСконстантных ΠΏΠΎΠ»Π΅ΠΉ

    ИмСна ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² lowerCamelCase. ΠžΠ΄Π½ΠΎΡΠΈΠΌΠ²ΠΎΠ»ΡŒΠ½Ρ‹Ρ… ΠΈΠΌΠ΅Π½ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² Π² ΠΏΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹Ρ… ΠΌΠ΅Ρ‚ΠΎΠ΄Π°Ρ… слСдуСт ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ.

    ИмСна Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…

    ИмСна Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² lowerCamelCase. Π”Π°ΠΆΠ΅ ΠΊΠΎΠ³Π΄Π° ΠΎΠ½ΠΈ final ΠΈ immutable, Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π½Π΅ Π½Π°Π΄ΠΎ ΠΏΡƒΡ‚Π°Ρ‚ΡŒ с константами, ΠΈ ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΡ… ΠΊΠ°ΠΊ константы.

    ИмСна ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… Ρ‚ΠΈΠΏΠΎΠ²

    КаТдая пСрСмСнная Ρ‚ΠΈΠΏΠ° имСнуСтся ΠΎΠ΄Π½ΠΈΠΌ ΠΈΠ· 2 способов:

    ΠžΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ Camel Case

    Иногда Π΅ΡΡ‚ΡŒ нСсколько способов ΠΊΠΎΠ½Π²Π΅Ρ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π°Π½Π³Π»ΠΈΠΉΡΠΊΡƒΡŽ Ρ„Ρ€Π°Π·Ρƒ Π² camel case, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ для Π°Π±Π±Ρ€Π΅Π²ΠΈΠ°Ρ‚ΡƒΡ€ ΠΈΠ»ΠΈ Π½Π΅ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹Ρ… ΠΈΠΌΠ΅Π½ Ρ‚ΠΈΠΏΠ° «IPv6» ΠΈΠ»ΠΈ «iOS». Π§Ρ‚ΠΎΠ±Ρ‹ имя Π±Ρ‹Π»ΠΎ прСдсказуСмо, прСдлагаСтся такая схСма.

    ΠŸΡ€ΠΈΠΌΠΈΡ‚Π΅ Π²ΠΎ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ рСгистр Π±ΡƒΠΊΠ² Π² ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹Ρ… словах Π½Π΅ принимаСтся Π²ΠΎ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅. ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹:

    ΠžΡ€ΠΈΠ³ΠΈΠ½Π°Π»ΡŒΠ½Π°Ρ Ρ„Ρ€Π°Π·Π°ΠŸΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎΠΠ΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ
    «XML HTTP request»XmlHttpRequestXMLHTTPRequest
    «new customer ID»newCustomerIdnewCustomerID
    «inner stopwatch»innerStopwatchinnerStopWatch
    «supports IPv6 on iOS?»supportsIpv6OnIossupportsIPv6OnIOS
    «YouTube importer»YouTubeImporterYoutubeImporter

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ слова ΠΈΠΌΠ΅ΡŽΡ‚ нСсколько написаний Ρ‡Π΅Ρ€Π΅Π· дСфис Π² английском языкС, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ΠΎΠ±Π° «nonempty» ΠΈ «non-empty» Π²Π΅Ρ€Π½Ρ‹. Π’Π°ΠΊΠΈΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ, ΠΈΠΌΠ΅Π½Π° ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² checkNonempty ΠΈ checkNonEmpty Ρ‚ΠΎΠΆΠ΅ ΠΎΠ±Π° Π²Π΅Ρ€Π½Ρ‹.

    @Override: всСгда ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ

    ΠœΠ΅Ρ‚ΠΎΠ΄ всСгда помСчаСтся Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠ΅ΠΉ @Override, Ссли это Π²Π΅Ρ€Π½ΠΎ с Ρ‚ΠΎΡ‡ΠΊΠΈ зрСния языка. Π­Ρ‚ΠΎ Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ Π² сСбя:

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: @Override ΠΌΠΎΠΆΠ½ΠΎ ΠΎΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ, Ссли ΠΌΠ΅Ρ‚ΠΎΠ΄ родитСля обьявлСн ΠΊΠ°ΠΊ @Deprecated.

    ΠŸΠ΅Ρ€Π΅Ρ…Π²Π°Ρ‚Ρ‹Π²Π°Π΅ΠΌΡ‹Π΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ: Π½Π΅ ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΡƒΡŽΡ‚ΡΡ

    ΠšΡ€ΠΎΠΌΠ΅ случая, описываСмого Π½ΠΈΠΆΠ΅, ΠΎΡ‡Π΅Π½ΡŒ Ρ€Π΅Π΄ΠΊΠΎ являСтся ΠΊΠΎΡ€Ρ€Π΅ΠΊΡ‚Π½Ρ‹ΠΌ Π½ΠΈΡ‡Π΅Π³ΠΎ Π½Π΅ Π΄Π΅Π»Π°Ρ‚ΡŒ Π² ΠΎΡ‚Π²Π΅Ρ‚ Π½Π° ΠΏΠ΅Ρ€Π΅Ρ…Π²Π°Ρ‡Π΅Π½Π½ΠΎΠ΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ (Ρ‚ΠΈΠΏΠΎΠ²Ρ‹Π΅ способы: Π»ΠΎΠ³Π³ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π΅Π³ΠΎ, Ссли ΠΆΠ΅ обьявлСно «Π½Π΅Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹ΠΌ», Π²Ρ‹Π±Ρ€ΠΎΡΠΈΡ‚ΡŒ Π·Π°Π½ΠΎΠ²ΠΎ ΠΊΠ°ΠΊ AssertionError).

    Когда Ρ€Π΅Π°Π»ΡŒΠ½ΠΎ Π½ΠΈΡ‡Π΅Π³ΠΎ Π½Π΅ Π½Π°Π΄ΠΎ Π΄Π΅Π»Π°Ρ‚ΡŒ Π² catch-Π±Π»ΠΎΠΊΠ΅, ΠΏΡ€ΠΈΡ‡ΠΈΠ½Π° указываСтся Π² ΠΏΠΎΡΡΠ½ΡΡŽΡ‰Π΅ΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ:

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: Π² тСстах, ΠΏΠ΅Ρ€Π΅Ρ…Π²Π°Ρ‡Π΅Π½Π½ΠΎΠ΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π±Π΅Π· коммСнтария, Ссли имя ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ начинаСтся с expected. Π­Ρ‚ΠΎ часто встрСчаСтся, ΠΊΠΎΠ³Π΄Π° Π½Π°Π΄ΠΎ ΡƒΠ±Π΅Π΄ΠΈΡ‚ΡŒΡΡ, Ρ‡Ρ‚ΠΎ тСстируСмый ΠΊΠΎΠ΄ бросаСт ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Π½ΡƒΠΆΠ½ΠΎΠ³ΠΎ Ρ‚ΠΈΠΏΠ°, поэтому ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ излишСн.

    БтатичСскиС Ρ‡Π»Π΅Π½Ρ‹ класса: ΡƒΠΊΠ°Π·Ρ‹Π²Π°ΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· имя класса

    Когда Π½ΡƒΠΆΠ½ΠΎ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΡΠΎΡΠ»Π°Ρ‚ΡŒΡΡ Π½Π° статичСскоС ΠΏΠΎΠ»Π΅ ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ класса, ΠΎΠ½ΠΎ опрСдСляСтся с ΠΈΠΌΠ΅Π½Π΅ΠΌ класса, Π° Π½Π΅ с ссылкой Π½Π° ΠΎΠ±ΡŒΠ΅ΠΊΡ‚ ΠΈΠ»ΠΈ Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°ΡŽΡ‰Π΅Π΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ Ρ‚ΠΈΠΏΠ° этого класса.

    Finalizers: Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ

    Π‘ΠΎΠ²Π΅Ρ‚: Π½Π΅ Π΄Π΅Π»Π°ΠΉΡ‚Π΅ этого. Если ΠΏΠΎΠ·Π°Ρ€Π΅Π· Π½Π°Π΄ΠΎ, сначала ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°ΠΉΡ‚Π΅ ΠΈ ΠΏΠΎΠΉΠΌΠΈΡ‚Π΅ Effective Java Item 7, «Avoid Finalizers», Π° послС этого Π½Π΅ Π΄Π΅Π»Π°ΠΉΡ‚Π΅ этого.

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    kakawait/java-coding-style-guideline

    Use Git or checkout with SVN using the web URL.

    Work fast with our official CLI. Learn more.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    Java Coding Style Guideline

    Version: 2.0

    Author: Thibaud LEPRETRE

    Greatly inspired by (thanks guys):

    Table of Contents

    1.1 Why have code conventions

    Code conventions are important to programmers for a number of reasons:

    For the conventions to work, every person writing software must conform to the code conventions. Everyone.

    Example code in this document is non-normative. That is, while the examples are in style guide, they may not illustrate the only stylish way to represent the code. Optional formatting choices made in examples should not be enforced as rules.

    2 Source file basics

    Use the following file suffixes:

    File typeSuffix
    Java source.java
    Java bytecode.class

    The source file name consists of the case-sensitive name of the top-level class it contains.

    Source files are encoded in UTF-8.

    2.4 Special characters

    2.4.1 Whitespace characters

    Aside from the line terminator sequence, the ASCII horizontal space character ( 0x20 ) is the only whitespace character that appears anywhere in a source file. This implies that:

    2.4.2 Special escape sequences

    2.4.3 Non-ASCII characters

    For the remaining non-ASCII characters, either the actual Unicode character (e.g. ∞ ) or the equivalent Unicode escape (e.g. \u221e ) is used, depending only on which makes the code easier to read and understand.

    Tip: in the Unicode escape case, and occasionally even when actual Unicode characters are used, an explanatory comment can be very helpful.

    ExampleDiscussion
    String unitAbbrev = «ΞΌs»;Best: perfectly clear even without a comment.
    String unitAbbrev = «\u03bcs»; // «ΞΌs»Allowed, but there’s no reason to do this.
    String unitAbbrev = «\u03bcs»; // Greek letter mu, «s»Allowed, but awkward and prone to mistakes.
    String unitAbbrev = «\u03bcs»;Poor: the reader has no idea what this is.
    return ‘\ufeff’ + content; // byte order markGood: use escapes for non-printable characters, and comment if necessary.

    Tip: Never make your code less readable simply out of fear that some programs might not handle non-ASCII characters properly. If that should happen, those programs are broken and they must be fixed.

    3 Source file structure

    A source file consists of, in order:

    Exactly one blank line separates each section that is present.

    3.1 License or copyright information

    If license or copyright information belongs in a file, it belongs here.

    3.2 Package statement

    The first non-comment line of most Java source files is a package statement.

    3.2.1 No line-wrapping

    The package statement is not line-wrapped. The section 4.2.1 Line length does not apply to package statements.

    3.3 Import statements

    3.3.1 No wildcard imports

    Wildcard imports, static or otherwise, are not used.

    3.3.2 No line-wrapping

    The import statement is not line-wrapped. The section 4.2.1 Line length does not apply to import statements.

    3.3.3 Ordering and spacing

    Import statements are divided into the following groups, in this order, with each group separated by a single blank line:

    Within a group there are no blank lines, and the imported names appear in ASCII sort order. (Note: this is not the same as the import statements being in ASCII sort order; the presence of semicolons warps the result.)

    3.4 Class and Interface declaration

    3.4.1 One top-level class declaration

    Each top-level class resides in a source file of its own.

    3.4.2 Class member ordering

    The ordering of the members of a class can have a great effect on learnability, but there is no single correct recipe for how to do it. Different classes may order their members differently.

    What is important is that each class order its members in some logical order, which its maintainer could explain if asked. For example, new methods are not just habitually added to the end of the class, as that would yield «chronological by date added» ordering, which is not a logical ordering.

    You can optionally adopt the following arrangement (which place public method before all other to separate API from implementation):

    3.4.3 Overloads: never split

    When a class has multiple constructors, or multiple methods with the same name, these appear sequentially, with no intervening members.

    Moreover keep getter and setter together.

    Each time a new block or block-like construct is opened, the indent increases by tab. When the block ends, the indent returns to the previous indent level. The indent level applies to both code and comments throughout the block.

    4.1.1 Alignement using 4 spaces

    Use 4 spaces for expressing the indentation level and for alignment.

    Example using indentation equals to four spaces:

    4.1.2 Why not using tabs/smartab?

    Avoid lines longer than 120 characters. Except as noted below, any line that would exceed this limit must be line-wrapped, as explained in Section 4.2.2 Wrapping lines.

    Exceptions:

    4.2.2 Wrapping lines

    When line-wrapping, each line after the first (each continuation line) is indented at least +8 (2 times indentation) from the original line.

    When there are multiple continuation lines, indentation may be varied beyond +8 (2 times indentation) as desired. In general, two continuation lines use the same indentation level if and only if they begin with syntactically parallel elements.

    There is no comprehensive, deterministic formula showing exactly how to line-wrap in every situation. Very often there are several valid ways to line-wrap the same piece of code.

    General principles can be used:

    Tip: extracting a method or local variable may solve the problem without the need to line-wrap.

    Here are some examples of breaking method calls:

    Following are two examples of breaking an arithmetic expression. The first is preferred, since the break occurs outside the parenthesized expression, which is at a higher level.

    Following are two examples of indenting method declarations. The first is the conventional case. The second would shift the second and third lines to the far right if it used conventional indentation, so instead it indents only 8 spaces.

    Line wrapping for if statements should generally use the 2 tabs rule, since conventional (1 tab) indentation makes seeing the body difficult. For example:

    Here are three acceptable ways to format ternary expressions:

    4.3.1 Nonempty blocks

    Braces follow the Kernighan and Ritchie style (Egyptian brackets) for nonempty blocks and block-like constructs:

    An empty block or block-like construct may be closed immediately after it is opened, with no characters or line break in between ( <> ), unless it is part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else or try/catch/finally ).

    For multi-block statement:

    4.4.1 Vertical Whitespace

    A single blank line appears:

    Multiple consecutive blank lines are permitted, but never required (or encouraged).

    4.4.2 Horizontal whitespace

    Beyond where required by the language or other style rules, and apart from literals, comments and Javadoc, a single ASCII space also appears in the following places only.

    This rule never requires or forbids additional space at the start or end of a line; it addresses only interior space.

    4.4.3 Horizontal alignment

    This practice is permitted, but is never required. It is not even required to maintain horizontal alignment in places where it was already used.

    Here is an example without alignment, then using alignment:

    Tip: Alignment can aid readability, but it creates problems for future maintenance. Consider a future change that needs to touch just one line. This change may leave the formerly-pleasing formatting mangled, and that is allowed. More often it prompts the coder (perhaps you) to adjust whitespace on nearby lines as well, possibly triggering a cascading series of reformattings. That one-line change now has a «blast radius.» This can at worst result in pointless busywork, but at best it still corrupts version history information, slows down reviewers and exacerbates merge conflicts.

    4.5.1.1 One variable per declaration

    Every variable declaration (field or local) declares only one variable: declarations such as int a, b; are not used.

    Local variables are not habitually declared at the start of their containing block or block-like construct. Instead, local variables are declared close to the point they are first used (within reason), to minimize their scope. Local variable declarations typically have initializers, or are initialized immediately after declaration.

    4.5.2 Classes and Interfaces

    When coding Java classes and interfaces, the following formatting rules should be followed:

    4.6.1 Simple statements

    Each line should contain at most one statement. Example:

    4.6.2 Compound statements

    Compound statements are statements that contain lists of statements enclosed in braces ( < statements >). See the following sections for examples.

    4.6.3 return statements

    A returnstatement with a value should not use parentheses unless they make the return value more obvious in some way. Example:

    The if-else class of statements should have the following form:

    4.6.5 for statements

    A for statement should have the following forms:

    When using the comma operator in the initialization or update clause of aforstatement, avoid the complexity of using more than three variables. If needed, use separate statements before the for loop (for the initialization clause) or at the end of the loop (for the update clause).

    An empty for statement (one in which all the work is done in the initialization, condition, and update clauses) should have the following form:

    4.6.6 while statements

    A while statement should have the following form:

    An empty while statement should have the following form:

    4.6.7 do-while statements

    A do-while statement should have the following form:

    4.6.8 switch statements

    A switch statement should have the following form:

    Vertical whitespaces are allowed:

    As with any other block, the contents of a switch block are indented +4.

    After a switch label, a newline appears, and the indentation level is increased +4, exactly as if a block were being opened. The following switch label returns to the previous indentation level, as if a block had been closed.

    4.6.8.2 Fall-through: commented

    Every time a case falls through (doesn’t include a break statement), add a comment where the break statement would normally be. This is shown in the preceding code example with the for example: // falls through comment.

    Every switch statement should include a default case. The break in the default case is redundant, but it prevents a fall-through error if later another case is added.

    4.6.9 try-catch statements

    A try-catch statement should have the following forms:

    A try-catch statement may has multiple redundant catch clause:

    4.7 Specific constructs

    After each comma that follows an enum constant, a line-break is optional. Additional blank lines (usually just one) are also allowed. This is one possibility:

    An enum class with no methods and no documentation on its constants may optionally be formatted as if it were an array initializer (see Section 4.7.3.1 Array initializers).

    Since enum classes are classes, all other rules for formatting classes apply Section 4.5.2 Classes and Interfaces.

    Annotations applying to a class, method or constructor appear immediately after the documentation block, and each annotation is listed on a line of its own (that is, one annotation per line). Example:

    Exception: A single parameterless annotation may instead appear together with the first line of the signature, for example:

    There are no specific rules for formatting parameter and local variable annotations.

    4.7.3.1 Array initializers

    Any array initializer may optionally be formatted as if it were a «block-like construct.» For example, the following are all valid (not an exhaustive list):

    4.7.3.2 No C-style array declarations

    Comments are not enclosed in boxes drawn with asterisks or other characters.

    Class and member modifiers, when present, appear in the order recommended by the Java Language Specification:

    4.9 Numeric Literals

    4.10 Runtime Exception

    RuntimeException or any unchecked exception should not declared on signature since it is misleading to the user of that API.

    Declaring in javadoc is recommended if possible.

    5.1 Common to all identifiers

    5.2 By indentifier type

    The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.

    Package names are all lowercase, with consecutive words simply concatenated together (no underscores). For example,

    Class names are written in UpperCamelCase.

    There are no specific rules or even well-established conventions for naming annotation types.

    Test classes are named starting with the name of the class they are testing, and ending with Test. For example, HashTest or HashIntegrationTest

    Method names are written in lowerCamelCase.

    5.2.4 Constant names

    Constant names use CONSTANT_CASE : all uppercase letters, with words separated by underscores. But what is a constant, exactly?

    Every constant is a static final field, but not all static final fields are constants. Before choosing constant case, consider whether the field really feels like a constant. For example, if any of that instance’s observable state can change, it is almost certainly not a constant. Merely intending to never mutate the object is generally not enough. Examples

    These names are typically nouns or noun phrases.

    5.2.5 Non-constant field names

    Non-constant field names (static or otherwise) are written in lowerCamelCase.

    5.2.6 Parameter names

    Parameter names are written in lowerCamelCase.

    One-character parameter names should be avoided.

    5.2.7 Local variable names

    Local variable names are written in lowerCamelCase, and can be abbreviated more liberally than other types of names.

    However, one-character names should be avoided, except for temporary and looping variables.

    Even when final and immutable, local variables are not considered to be constants, and should not be styled as constants.

    5.2.8 Type variable names

    Each type variable is named in one of two styles:

    Sometimes there is more than one reasonable way to convert an English phrase into camel case, such as when acronyms or unusual constructs like «IPv6» or «iOS» are present. To improve predictability use the following (nearly) deterministic scheme.

    Note that the casing of the original words is almost entirely disregarded. Examples:

    Prose formCorrectIncorrect
    «XML HTTP request»XmlHttpRequestXMLHTTPRequest
    «new customer ID»newCustomerIdnewCustomerID
    «inner stopwatch»innerStopwatchinnerStopWatch
    «supports IPv6 on iOS?»supportsIpv6OnIossupportsIPv6OnIOS
    «YouTube importer»YouTubeImporter *

    * Can also accept YoutubeImporter but not recommended

    Note: Some words are ambiguously hyphenated in the English language: for example «nonempty» and «non-empty» are both correct, so the method names checkNonempty and checkNonEmpty are likewise both correct.

    6 Programming Practices

    6.1 Avoid public class members

    Don’t make any instance or class variable public without good reason. Often, instance variables don’t need to be explicitly set or gottenβ€”often that happens as a side effect of method calls.

    One example of appropriate public instance variables is the case where the class is essentially a data structure, with no behavior. In other words, if you would have used a struct instead of a class (if Java supported struct ), then it’s appropriate to make the class’s instance variables public.

    6.2 Static members: qualified using class

    When a reference to a static class member must be qualified, it is qualified with that class’s name, not with a reference or expression of that class’s type.

    6.3 Variable Assignments

    Avoid assigning several variables to the same value in a single statement. It is hard to read. Example:

    Do not use the assignment operator in a place where it can be easily confused with the equality operator. Example:

    should be written as

    Do not use embedded assignments in an attempt to improve run-time performance. This is the job of the compiler. Example:

    should be written as

    6.4 Grouping parentheses

    It is generally a good idea to use parentheses liberally in expressions involving mixed operators to avoid operator precedence problems. Even if the operator precedence seems clear to you, it might not be to othersβ€”you shouldn’t assume that other programmers know precedence as well as you do.

    6.5 Returning Values

    Try to make the structure of your program match the intent. Example:

    should instead be written as

    should be written as

    6.6 Expressions before ‘?’ in the Conditional Operator

    6.7 @Override: always used

    A method is marked with the @Override annotation whenever it is legal. This includes a class method overriding a superclass method, a class method implementing an interface method, and an interface method respecifying a superinterface method.

    6.8 Caught exceptions

    When it truly is appropriate to take no action whatsoever in a catch block, the reason this is justified is explained in a comment.

    The basic formatting of Javadoc blocks is as seen in this example:

    . or in this single-line example:

    The basic form is always acceptable. The single-line form may be substituted when there are no at-clauses present, and the entirety of the Javadoc block (including comment markers) can fit on a single line.

    One blank line β€” that is, a line containing only the aligned leading asterisk ( * ) β€” appears between paragraphs, and before the group of «at-clauses» if present. Each paragraph but the first has

    immediately before the first word, with no space after.

    7.2 The summary fragment

    The Javadoc for each class and member begins with a brief summary fragment. This fragment is very important: it is the only part of the text that appears in certain contexts such as class and method indexes.

    7.3 Where Javadoc is used

    At the minimum, Javadoc is present for every public class, and every public or protected member of such a class, with a few exceptions noted below.

    Other classes and members still have Javadoc as needed. Whenever an implementation comment would be used to define the overall purpose or behavior of a class, method or field, that comment is written as Javadoc instead. (It’s more uniform, and more tool-friendly.)

    7.3.1 Exception: self-explanatory methods

    7.3.2 Exception: overrides

    Javadoc is not always present on a method that overrides a supertype method.

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java code conventions

    The information on this page is for Archive Purposes Only

    This page is not being actively maintained. Links within the documentation may not work and the information itself may no longer be valid. The last revision to this document was made on April 20, 1999

    A file consists of sections that should be separated by blank lines and an optional comment identifying each section.

    Files longer than 2000 lines are cumbersome and should be avoided.

    For an example of a Java program properly formatted, see «Java Source File Example» on page 19.

    3.1 Java Source Files

    Each Java source file contains a single public class or interface. When private classes and interfaces are associated with a public class, you can put them in the same source file as the public class. The public class should be the first class or interface in the file.

    Java source files have the following ordering:

    3.1.1 Beginning Comments

    All source files should begin with a c-style comment that lists the class name, version information, date, and copyright notice:

    3.1.2 Package and Import Statements

    The first non-comment line of most Java source files is a package statement. After that, import statements can follow. For example:

    3.1.3 Class and Interface Declarations

    The following table describes the parts of a class or interface declaration, in the order that they should appear. See «Java Source File Example» on page 19 for an example that includes comments.

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java code conventions

    The information on this page is for Archive Purposes Only

    This page is not being actively maintained. Links within the documentation may not work and the information itself may no longer be valid. The last revision to this document was made on April 20, 1999

    Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4).

    4.1 Line Length

    Avoid lines longer than 80 characters, since they’re not handled well by many terminals and tools.

    Note: Examples for use in documentation should have a shorter line length-generally no more than 70 characters.

    4.2 Wrapping Lines

    When an expression will not fit on a single line, break it according to these general principles:

    Here are some examples of breaking method calls:

    Following are two examples of breaking an arithmetic expression. The first is preferred, since the break occurs outside the parenthesized expression, which is at a higher level.

    Following are two examples of indenting method declarations. The first is the conventional case. The second would shift the second and third lines to the far right if it used conventional indentation, so instead it indents only 8 spaces.

    Line wrapping for if statements should generally use the 8-space rule, since conventional (4 space) indentation makes seeing the body difficult. For example:

    Here are three acceptable ways to format ternary expressions:

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    princensit/java-coding-conventions

    Use Git or checkout with SVN using the web URL.

    Work fast with our official CLI. Learn more.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    Java Coding Conventions

    This document serves the coding standards for source code in Java language. It is intended for use by software engineering teams to employ a common style when writing Java code.

    Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly.

    Source file structure

    Exactly one blank line separates each section that is present.

    Ordering of class contents

    JUnit Tests method ordering

    paragraph tag to separate multiple paragraphs.

    * Nulla non mollis leo. Aliquam efficitur lectus eros, sit amet ultrices * ex fringilla at. * * @return user issued books */ public Book[] getBooks(User user) < return dao.getBooks(user); >«>

    It is a software metric, used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program’s source code. More details to be shared!

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java code conventions

    One goal of a programming course is for you to learn to write programs that are not only correct but also understandable. These guidelines should help you toward that goal. They will give you a good basis for developing a style of your own as you become a more experienced programmer. This page includes guidelines for Java constructs that will be covered later in the semester. Skim these sections now and read them more carefully later, when the topics are discussed.

    Some of these guidelines are standard Java practice, while others are intended to develop good coding habits. When in doubt, choose the alternative that makes the code most obviously correct:

    We adhere to Java’s naming conventions. These may seem arbitrary and bizarre if you’re not used to them. Nonetheless, conforming to aesthetic standards of coding is something you’ll need to do in just about any software development workplace, so it’s good practice.

    Java class, field, method, and variable names are written in CamelCase: Words are smashed together and the first letter of each word is capitalized. No word separator, like the underscore _, is used.

    There is one exception to CamelCase: constants. Constants are in all-caps with words separated by underscores. Constants should also have the keyword final, and they are usually static:

    Class and interface names are generally noun or noun phrases and begin with a capital letter:

    Method names generally begin with a lowercase letter. A call on a procedure is a statement to do something, so a procedure name is generally a verb phrase that is a command to do something.

    A function call yields a value, so a function name is generally a noun phrase that describes the value.

    However, a convention in Java is that a function that yields the value of a field (say title) is the name of the field preceded by «get». People are of two minds on this; not everyone thinks it’s a good idea. The name «title» could also be used.

    The name of a boolean function is often a verb phrase starting with «is», thus describing what the value means:

    Variable names generally start with a lowercase letter.

    Variable names should give the reader some hint about what the variable is used for. A well-chosen name, which gives a hint at the meaning of the variable, helps document a program, making it easier to understand. On the other hand, using the names of your friends or flowers that you like as variable names just annoys and makes the program harder to understand. Don’t do that. Also, refrain from using vague names like counter or var or data; instead think about what the variable really is for and use a more concrete name.

    There is a tension between writing long descriptive names and very short names. A long name may make it easy to remember what the variable is for, but its length may make the whole program seem long and complicated. It may be difficult to see what a very short name means, but it makes the program short. For example, consider these two statements, which look so different only because of the length of the variable name:

    hypotenuseOfTriangle= 6 * (2 + hypotenuseOfTriangle) + 7 / hypotenuseOfTriangle
    — hypotenuseOfTriangle;

    A name can rarely be used to give a complete, precise definition of the entity it names, and a complete definition should always be given where the entity is defined.

    Here is a compromise. We tend to use shorter names for parameters and local variables and longer names for fields and static variables. We explain why.

    Local variable names. A local variable is a variable that is declared in a method body. Its declaration should be placed as close to its first use as possible. The scope of a local variable is usually short, and its meaning is often obvious either from a comment on its declaration or from the short code in which it is used. Therefore, names of local variables may be short.

    Package names are usually all lowercase and consist of nouns.

    Use a formatting convention consistently within a class. For example, the position of open braces «<" should be the same throughout the program.

    Put only one statement on a line (although there may be exceptional cases where more than one is better). Don’t pack everything together, making a program hard to read.

    Make sure that all lines can be read without the need for horizontal scrolling. A mximum of 80 characters per line is recommended.

    Indentation is used to make the structure of a program clear. The basic rule is:

    We prefer putting an opening curly brace «<" at the end of a line, and not on a line by itself, as shown below. The closing brace ">» appears on its own line, indented as shown below.

    There are two reasons for documenting a program well.

    First, you, the programmer, need all the help you can get while writing and debugging the program. This means that documentation should be written during the coding/debugging process; it should not be put off until the program is considered finished. The tendency is to wait until the end, and then document. That just means you will make more errors, take more time programming, and end up with more bugs in your program. Get in the habit of documenting a field when you declare it and specifying a method before you write its body. If you decide to change what a method is supposed to do, change its specification first!

    You document a program well so that others have an easier time understanding it. A professional programmer is well regarded if their code is easy to maintain by others. A grader of your assignment will be more likely to feel good about you when grading if your program is well documented. So, document your program well.

    The Elements of Style, a famous little book on writing style by Cornell Professors W. Strunk, Jr., and E.B. White, contains several rules that are useful for programming as well as writing. Among them are:

    Omit needless words.
    Use the active voice.

    Java has three kinds of comments. Comments that start with «//» are one-line comments: the comment ends at the end of the line. Comments that start with «/*» must end with «*/», but they may span many lines.

    A Javadoc comment starts with «/**» (and therefore ends with «*/». Javadoc stands for «Java documentation». These comments have a special place in Java and also in Eclipse, when dealing with a Java program. Suppose a method is written like this:

    If you now hover the mouse over a call of this function, e.g.

    a pop-up window opens with the specification of the method in it! So you get to see preciely what the function call will do and what its preconditions is. Do you see how writing specifications during programming can help you?

    Some people have a tendency to put a «//» comment on almost every line. This is generally just noise, making it harder to read the program. Don’t do it. Refrain from commenting lines like this:

    Assume that the reader has experience with Java and understands basic statements. Generally speaking, the only kinds of comments needed are those that are mentioned in this section 3 on comments.

    The class invariant is the collection of meanings of and constraints on fields of a class. The class invariant is generally placed in comments on each individual field declaration or placed as a single comment before the fields. Here are examples. Note the appearance of constraints, when necessary. We have made them javadoc comments so the Eclipse feature of showing the javadoc comments when an occurrence of the field name is moused over will work.

    /** The hour of the day, in 0..23.*/
    private int hr;

    /** temps[0..numRecorded-1] are the recorded temperatures */
    private double[] temps;
    /** number of temperatures recorded */
    private int numRecorded;

    If you are not interested in using the javadoc facility in an IDE, since the fields are private, javadoc comments are not necessary. Therefore, you can write the class invariant in a readable style as one-line comments on the same line as the declaration:

    private int hr; // The hour of the day, in 0..23.

    private double[] temps; // temps[0..numRecorded-1] are the recorded temperatures
    private int numRecorded; // number of temperatures recorded

    The purpose of a constructor is to initialize all fields so that the class invariant is true. Then, when writing a method, you can assume that the class invariant is true when the method is called and write the method body so that it terminates with the class invariant true. Looking often at the class invariant can help prevent mistakes caused by forgetting just what a field means or what its constraints are.

    Java has certain conventions for describing the parameters and result of a method. For example, one can write this within a Javadoc specification to describe parameter b and the result

    One can certainly use these. However, we have found that a specification can be written more compactly and clearly without using those, and we do not require them. The main guideline is to write the specification as a command to do something, naming all parameters in that command. Examples are given below.

    Procedure specifications are generally best written as commands to do something, e.g.

    Function specifications are generally written to indicate what to return, e.g.:

    The purpose of a constructor is to initialize all fields so that the class invariant is true. We favor writing a constructor specification as illustrated by the following:

    A call binarySearch(25, c) will work properly only if 25 is in array c and c is sorted. If not, the method can do anything.

    If it doesn’t cost too much, the method can be made more robust by checking that the precondition is true (using a Java assert statement), but it is not necessary.

    Similarly, a postcondition is an assertion that will be true upon termination of the method.

    Each public class is given in a separate file. The beginning of the file should contain a javadoc comment that explains what the class is for. This can be a simple, short summary. Often, one also puts here information concerning the author, the date of last modification, and so on. Here is an example.

    Inner classes and non-public classes that are defined in the same file along with a public class should be specified in a similar fashion.

    Just as the sentences of an essay are grouped in paragraphs, so the sequence of statements of the body of a method should be grouped into logical units. Often, the clarity of the program is enhanced by preceding a logical unit by a comment that explains what it does. This comment serves as the specification for the logical unit; it should say precisely what the logical unit does.

    The comment for such a logical unit is called a statement-comment. It should be written as a command to do something. Here is an example.

    Statement comments must be complete. The comment

    Use of blank lines. Place a blank line after the implementation of each statement-comment. In the following example,

    // If t is empty, print an error message and return.
    if (t.length() == 0) <
    .
    return false;
    >

    // Store the French translation of t in tFrench.
    .

    Place assertions wherever the code below depends on that assertion being true and the assertion helps the reader understand. One particular use of it can be in a function body that returns in several places. The following illustrates this:

    If the is true, nothing is done, but if it is false, execution throws an exception and, generally, the program terminates.

    Using the assert statement instead of an assertion-comment has the advantage of catching errors that cause the assertion to be false. Some people advocate leaving assertions in a finished program, for just that reason, unless the boolean expression is so complicated that it ends up slowing down the program execution.

    A loop invariant is an assertion that is true before and after each iteration of a loop and is used to prove correctness of the loop (i.e. prove that execution of the loop achieves the desired postcondition). We do not explain loop invariants here. Our purpose is only to show where they are placed in the program.

    A loop invariant is placed as a comment just before the loop. Below, we show a loop invariant in the same code written using a while loop and written using a for-loop.

    Principle : Declare a variable as close to its first use as possible.

    Look at the small example below. Variable temp has been declared first. This causes the reader to ask, «What is temp for? Well, I don’t know.» The reader goes on and sees that there are some statements to swap b and c under certain circumstances and skips them because the reader knows how to write a swap. Well, the reader still doesn’t know what temp is for!

    /** Return middle value of b, c, d */
    public static int middle(int b, int c, int d) <
    int temp;

    // Swap b, c to put smaller in b
    if (b > c) <
    temp= b;
    b= c;
    c= temp;
    >

    // < b Use of access modifiers

    ModifierClassPackageSubclassWorld
    publicyesyesyesyes
    protectedyesyesyesno
    packageyesyesnono
    privateyesnonono

    Problems with the getter/setter terminology

    Here is conventional terminology: a getter method is a function that returns the value of a field (and changes nothing); a setter method is a procedure that stores a value in a field.

    This terminology has problems, and it is better to use an alternative terminology: creators, observers, and mutators. This pdf file explains it all in one page.

    Immutable classes (or objects)

    A side effect occurs when evaluation of an expression changes a value. For example, a side effect occurs if evaluation of the following loop condition, which is a call on function f, changes some variable:

    Generally, side effects should be avoided. This means, for example, that an assignment statement like

    should change no variable other than b. A side-effect that changes something else could be disastrous, unless it is very well documented and the programmer is aware of what is happening. In fact, the theory of proving programs correct tells us that formal proofs of correctness when side effects may occur are far far more complex than when they may not.

    Standard paradigms

    One does see some standard paradigms that use side effects. For example, below is a loop that reads and prints lines of a BufferedReader br; the loop condition has the side effect of assigning to variable line.

    However, we would never write the loop like this, preferring to write it as follows, in a way that has no side effects, even though it is longer that the one above.

    Benevolent side effects

    There is one class of side effect that is OK. A benevolent side effect is one that changes the state but not in a way that the user can observe. A benevolent side effect can be used to make a program more efficient. Here is an example.

    Consider implementing a class that mantains a set of questions-and-answers. When someone asks a question, the corresponding answer is given. The questions-and-answers are implemented in an array, and one has to search the list in linear fashion to find a question. It is better if more frequently asked questions are at the front of the list, so they are more efficiently found. This can be achieved by the following: Whenever a question is asked, move it up one position in the array. This changes the representation of the set of questions-and-answers, but not the set itself; the user cannot notice the change. This is a benevolent side effect.

    So if you see that something is deprecated and you have the time, look for the better alternative and use it instead.

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Java code conventions

    Π£Π²Π°ΠΆΠ°Π΅ΠΌΡ‹Π΅ посСтитСли! Если Π²Ρ‹ ΠΎΠ±Π½Π°Ρ€ΡƒΠΆΠΈΠ»ΠΈ Π² ΠΊΠ°ΠΊΠΎΠΌ-Π½ΠΈΠ±ΡƒΠ΄ΡŒ словС ΠΎΡˆΠΈΠ±ΠΊΡƒ!
    Π’Ρ‹Π΄Π΅Π»ΠΈΡ‚Π΅ это слово ΠΈ Π½Π°ΠΆΠΌΠΈΡ‚Π΅ Ctrl+Enter ΠΎΠ΄Π½ΠΎΠ²Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎ!
    Π—Π°Ρ€Π°Π½Π΅Π΅ спасибо Π·Π° сотрудничСство!

    ΠšΠΎΠ½Ρ‚Π°ΠΊΡ‚Ρ‹

    АдрСс элСктронной ΠΏΠΎΡ‡Ρ‚Ρ‹ Π·Π°Ρ‰ΠΈΡ‰Π΅Π½ ΠΎΡ‚ спам-Π±ΠΎΡ‚ΠΎΠ². Для просмотра адрСса Π² вашСм Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Π²ΠΊΠ»ΡŽΡ‡Π΅Π½ Javascript.

    БоглашСния ΠΏΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ ΠΊΠΎΠ΄Π° Java (Java Code Conventions)

    Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ Java code conventions. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ Java code conventions. Π€ΠΎΡ‚ΠΎ Java code conventions

    Π”Π°Π½Π½Ρ‹ΠΉ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ Π½Π΅ ΠΏΡ€Π΅Ρ‚Π΅Π½Π΄ΡƒΠ΅Ρ‚ Π½Π° ΠΏΠ°Π»ΡŒΠΌΡƒ пСрвСнства ΠΈΠ»ΠΈ ΠΊΠ°ΠΊ Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄! Π”ΡƒΠΌΠ°ΡŽ Ρ‚Π°ΠΊΠΈΡ… ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ΠΎΠ² Π² сСти довольного ΠΌΠ½ΠΎΠ³ΠΎ, ΠΌΠΎΠΆΠ΅Ρ‚ ΠΌΠ½ΠΎΠ³ΠΈΠ΅ ΠΈΠ· Π½ΠΈΡ… ΠΏΠ΅Ρ€Π΅Π²Π΅Π΄Π΅Π½Ρ‹ ΠΊΡƒΠ΄Π° Π»ΡƒΡ‡ΡˆΠ΅ этого =)

    Π­Ρ‚ΠΎΡ‚ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ я Π΄Π΅Π»Π°Π» для сСбя Π² цСлях ознакомлСния с Π΄Π°Π½Π½Ρ‹ΠΌ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΎΠΌ, Π΄Π° ΠΈ ΠΏΡ€Π°Π²ΠΈΠ»Π°ΠΌ оформлСния ΠΊΠΎΠ΄Π° Π² Ρ†Π΅Π»ΠΎΠΌ. Π’ этом ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄Π΅ отчасти использовались ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹ с этого ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄Π°.

    Для сСбя я старался Π΅Π³ΠΎ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ максимально ΡƒΠ΄ΠΎΠ±ΠΎΠ²Π°Ρ€ΠΈΠΌΡ‹ΠΌ для понимания ΠΈ использования Π² дальнСйшСм =) По этому Ссли ΠΊΡ‚ΠΎ Ρ…ΠΎΡ‡Π΅Ρ‚ Π΅Π³ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π³Π΄Π΅-Ρ‚ΠΎ Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… мСстах, Ρ‚ΠΎ Π½Π΅ Π·Π°Π±Ρ‹Π²Π°Π΅ΠΌ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒ ссылку Π½Π° этот ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π» ΠΈΠ»ΠΈ сайт http://www.magnumblog.space;)

    А Π²ΠΎΠΎΠ±Ρ‰Π΅ ΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ΡΡŒ Π½Π° Π·Π΄ΠΎΡ€ΠΎΠ²ΡŒΠ΅.

    1.1 Π—Π°Ρ‡Π΅ΠΌ Π½ΡƒΠΆΠ½Ρ‹ условныС обозначСния ΠΊΠΎΠ΄Π°

    БоглашСния ΠΏΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ ΠΊΠΎΠ΄Π° Π²Π°ΠΆΠ½Ρ‹ для программистов ΠΏΠΎ ряду ΠΏΡ€ΠΈΡ‡ΠΈΠ½:

    1.2 Π’Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΏΡ€ΠΈΠ·Π½Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ

    Π’ этом Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π΅ содСрТатся стандарты ΠΏΠΎ ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΡŽ ΠΊΠΎΠ΄Π° Π½Π° языка Java, прСдставлСнныС Π² спСцификации ΠΎΡ‚ Sun Microsystems. ΠžΡΠ½ΠΎΠ²Π½Ρ‹Π΅ Π²ΠΊΠ»Π°Π΄Ρ‹ ΠΎΡ‚ ΠŸΠΈΡ‚Π΅Ρ€Π° Кинга, ΠŸΠ°Ρ‚Ρ€ΠΈΠΊΠ° Нотона, Майка Π”Π΅ΠœΠΎΠ½ΠΈ, Π”ΠΆΠΎΠ½Π½ΠΈ ΠšΠ°Π½Π΅Ρ€Π²Ρ‹, ΠšΡΡ‚ΠΈ Π£ΠΎΠ»Ρ€Π°Ρ‚Π° ΠΈ Π‘ΠΊΠΎΡ‚Ρ‚Π° Π₯оммСля.

    По вопросам, связанным с Π°Π΄Π°ΠΏΡ‚Π°Ρ†ΠΈΠ΅ΠΉ, ΠΌΠΎΠ΄ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠ΅ΠΉ ΠΈΠ»ΠΈ распространСниСм этого Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°, поТалуйста, ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°ΠΉΡ‚Π΅ нашС ΡƒΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠ΅ ΠΎΠ± авторских ΠΏΡ€Π°Π²Π°Ρ… ΠΏΠΎ адрСсу http://java.sun.com/docs/codeconv/html/Copyright.doc.html.

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΊ этому Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Ρƒ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½Ρ‹ Π² Π½Π°ΡˆΡƒ Ρ„ΠΎΡ€ΠΌΡƒ ΠΎΠ±Ρ€Π°Ρ‚Π½ΠΎΠΉ связи ΠΏΠΎ адрСсу http://java.sun.com/docs/forms/sendusmail.html.

    Π’ этом Ρ€Π°Π·Π΄Π΅Π»Π΅ пСрСчислСны Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ часто ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹Π΅ ΠΈΠΌΠ΅Π½Π° Ρ„Π°ΠΉΠ»ΠΎΠ² ΠΈ ΠΈΡ… Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ.

    2.1 Π Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ Ρ„Π°ΠΉΠ»ΠΎΠ²

    Π’ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°Ρ… написанных Π½Π° Java ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ Ρ„Π°ΠΉΠ»ΠΎΠ²:

    Π’ΠΈΠΏ Ρ„Π°ΠΉΠ»Π°Π Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅
    Для исходного ΠΊΠΎΠ΄Π°.java
    Для Π±Π°ΠΉΡ‚-ΠΊΠΎΠ΄Π°.class
    2.2 ΠžΠ±Ρ‰ΠΈΠ΅ ΠΈΠΌΠ΅Π½Π° Ρ„Π°ΠΉΠ»ΠΎΠ²

    Часто ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹Π΅ ΠΈΠΌΠ΅Π½Π° Ρ„Π°ΠΉΠ»ΠΎΠ² Π²ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‚:

    Имя Ρ„Π°ΠΉΠ»Π°ΠŸΡ€ΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅
    GNUmakefileΠ—Π°Ρ€Π΅Π·Π΅Ρ€Π²ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎΠ΅ имя для создаваСмых Ρ„Π°ΠΉΠ»ΠΎΠ². ΠœΡ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ gnumake для создания нашСго ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния.
    READMEΠ—Π°Ρ€Π΅Π·Π΅Ρ€Π²ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎΠ΅ имя Ρ„Π°ΠΉΠ»Π° Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ содСрТится информация ΠΎ Ρ„Π°ΠΉΠ»Π°Ρ… находящихся Π² Ρ‚ΠΎΠΉ ΠΆΠ΅ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΎΡ€ΠΈΠΈ.

    Π€Π°ΠΉΠ» состоит ΠΈΠ· Ρ€Π°Π·Π΄Π΅Π»ΠΎΠ², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·Π΄Π΅Π»Π΅Π½Ρ‹ пустыми строками ΠΈ Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ, ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΡ†ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠΌ ΠΊΠ°ΠΆΠ΄ΡƒΡŽ ΡΠ΅ΠΊΡ†ΠΈΡŽ.

    Π€Π°ΠΉΠ»Ρ‹ Π΄Π»ΠΈΠ½ΠΎΠΉ Π±ΠΎΠ»Π΅Π΅ 2000 строк ΡΠ²Π»ΡΡŽΡ‚ΡΡ Π³Ρ€ΠΎΠΌΠΎΠ·Π΄ΠΊΠΈΠΌΠΈ ΠΈ ΠΈΡ… слСдуСт ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ€ форматирования Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½ Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ «ΠŸΡ€ΠΈΠΌΠ΅Ρ€ Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java».

    3.1 Π€Π°ΠΉΠ»Ρ‹ с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ„Π°ΠΉΠ» с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java содСрТит ΠΎΠ΄ΠΈΠ½ class с ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹ΠΌ словом public ΠΈΠ»ΠΈ интСрфСйс. Когда классы с ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹ΠΌ словом private ΠΈ интСрфСйсы связанны с public классом, Ρ‚ΠΎ ΠΈΡ… ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΎΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π² Ρ‚ΠΎΡ‚ ΠΆΠ΅ Ρ„Π°ΠΉΠ» с ΠΈΡ…ΠΎΠ΄Π½Ρ‹ΠΌ ΠΊΠΎΠ΄ΠΎΠΌ, Ρ‡Ρ‚ΠΎ ΠΈ public класс. Класс с ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹ΠΌ словом public Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·ΠΌΠ΅Ρ‰Π΅Π½ ΠΊΠ°ΠΊ ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ класс ΠΈΠ»ΠΈ интСрфСйс Π² Ρ„Π°ΠΉΠ»Π΅.

    Π€Π°ΠΉΠ»Ρ‹ с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java ΠΈΠΌΠ΅ΡŽΡ‚ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ порядок:

    3.1.1 ΠΠ°Ρ‡Π°Π»ΡŒΠ½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ

    ВсС Ρ„Π°ΠΉΠ»Ρ‹ с исходным ΠΊΠΎΠ΄ΠΎΠΌ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с коммСнтария Π² стилС языка C, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ пСрСчислСны Π°Π²Ρ‚ΠΎΡ€Ρ‹ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, Π΄Π°Ρ‚Π°, свСдСния ΠΎΠ± авторских ΠΏΡ€Π°Π²Π°Ρ…, Π° Ρ‚Π°ΠΊ ΠΆΠ΅ ΠΊΡ€Π°Ρ‚ΠΊΠΎ описаниС Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎ Π΄Π΅Π»Π°Π΅Ρ‚ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°. Для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°:

    3.1.2 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ Package ΠΈ Import

    ΠŸΠ΅Ρ€Π²Π°Ρ строка Π±Π΅Π· коммСнтария Π² Ρ„Π°ΠΉΠ»Π΅ с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java это ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ package. ПослС Π½Π΅Π΅ слСдуСт ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ import. Для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°:

    3.1.3 ОбъявлСния классов ΠΈ интСрфСйсов

    Π’ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ Ρ‚Π°Π±Π»ΠΈΡ†Π΅ описаны части объявлСния класса ΠΈΠ»ΠΈ интСрфСйса Π² Ρ‚ΠΎΠΌ порядкС, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ ΠΎΠ½ΠΈ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Ρ‚ΡŒΡΡ. ΠžΠ±Ρ€Π°Π·Π΅Ρ† с коммСнтариями ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½ Π² «ΠŸΡ€ΠΈΠΌΠ΅Ρ€Π΅ Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java»

    Π§Π°ΡΡ‚ΡŒ объявлСния класса/интСрфСйсаЗамСтки
    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ для Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ ΠΏΠΎ классам ΠΈ интСрфСйсам (/**. */)Π‘ΠΌΠΎΡ‚Ρ€ΠΈΡ‚Π΅ Π² «ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ» какая информация Π΄ΠΎΠ»ΠΆΠ½Π° содСрТатся Π² этом ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ
    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ class ΠΈΠ»ΠΈ interface
    Если Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ, Ρ‚ΠΎ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ класса/интСрфСйса (/*. */)Π—Π΄Π΅ΡΡŒ содСрТится любая Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Π°Ρ информация ΠΏΠΎ классу ΠΈΠ»ΠΈ интСрфСйсу, которая Π½Π΅ ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ΠΈΡ‚ для Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ коммСнтария.
    (static) ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ классаБначала ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ класса public, Π·Π°Ρ‚Π΅ΠΌ protected, ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠΎΡ‚ΠΎΠΌ private
    ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ экзСмпляраБпСрва public, Π·Π°Ρ‚Π΅ΠΌ protected, ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠΎΡ‚ΠΎΠΌ private.
    ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€Ρ‹
    ΠœΠ΅Ρ‚ΠΎΠ΄Ρ‹ΠœΠ΅Ρ‚ΠΎΠ΄Ρ‹ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ сгрупированным ΠΏΠΎ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ, Π° Π½Π΅ ΠΏΠΎ области ΠΈΠ»ΠΈ доступности. Для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π° ΠΌΠ΅Ρ‚ΠΎΠ΄ класса private ΠΌΠΎΠΆΠ΅Ρ‚ находится ΠΌΠ΅ΠΆΠ΄Ρƒ двумя public ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌΠΈ экзСмпляра. ЦСль Π² ΠΎΠ±Π»Π΅Π³Ρ‡Π΅Π½ΠΈΠΈ чтСния ΠΈ понимания ΠΊΠΎΠ΄Π°.

    Π’ качСствС Π΅Π΄ΠΈΠ½ΠΈΡ†Ρ‹ отступов слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»Π°. Вочная конструкция отступа (ΠΏΡ€ΠΎΠ±Π΅Π»Ρ‹ ΠΈΠ»ΠΈ символы табуляции) Π½Π΅ ΡƒΠΊΠ°Π·Π°Π½Π°. Вабуляция Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ установлСна Ρ€ΠΎΠ²Π½ΠΎ ΠΊΠ°ΠΆΠ΄Ρ‹Π΅ 8 ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² (Π° Π½Π΅ 4).

    4.1 Π”Π»ΠΈΠ½Π° строки

    Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ строк Π΄Π»ΠΈΠ½Π½Π΅Π΅ 80 символов, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ ΠΎΠ½ΠΈ Π½Π΅ ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°ΡŽΡ‚ΡΡ ΠΌΠ½ΠΎΠ³ΠΈΠΌΠΈ Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°ΠΌΠΈ ΠΈ инструмСнтами.

    4.2 ΠŸΠ΅Ρ€Π΅Π½ΠΎΡ строки

    Если Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π½Π΅ помСщаСтся Π½Π° ΠΎΠ΄Π½ΠΎΠΉ строкС, Ρ€Π°Π·Π±Π΅ΠΉΡ‚Π΅ Π΅Π³ΠΎ Π² соотвСтствии с этими ΠΎΠ±Ρ‰ΠΈΠΌΠΈ ΠΏΡ€ΠΈΠ½Ρ†ΠΈΠΏΠ°ΠΌΠΈ:

    НСсколько ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ² пСрСноса строки Π² Π²Ρ‹Π·ΠΎΠ²Π°Ρ… ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ²:

    НиТС ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Ρ‹ Π΄Π²Π° ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π° пСрСноса арифмСтичСского выраТСния. ΠŸΠ΅Ρ€Π²ΠΎΠ΅ ΠΏΡ€Π΅Π΄ΠΏΠΎΡ‡Ρ‚ΠΈΡ‚Π΅Π»ΡŒΠ½Π΅Π΅, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ Ρ€Π°Π·Ρ€Ρ‹Π² происходит Π²Π½Π΅ выраТСния Π² скобках, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ находится Π½Π° Π±ΠΎΠ»Π΅Π΅ высоком ΡƒΡ€ΠΎΠ²Π½Π΅.

    ΠžΡ‚ΡΡ‚ΡƒΠΏΡ‹ Π² строках с ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ if слСдуСт ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΡ‚ΡŒ ΠΏΠΎ ΠΏΡ€Π°Π²ΠΈΠ»Ρƒ 8-ΠΌΠΈ ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ², Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ Ссли ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ стандартныС 4-Ρ€Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»Π°, Ρ‚ΠΎ поиск Ρ‚Π΅Π»Π° ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° Π±ΡƒΠ΄Π΅Ρ‚ Π·Π°Ρ‚Ρ€ΡƒΠ΄Π½ΠΈΡ‚Π΅Π»Π΅Π½. НапримСр:

    Π’ΠΎΡ‚ Ρ‚Ρ€ΠΈ ΠΏΡ€ΠΈΠ΅ΠΌΠ»Π΅ΠΌΡ‹Ρ… способа форматирования Ρ‚Π΅Ρ€Π½Π°Ρ€Π½Ρ‹Ρ… Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ:

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΊΠΎΠ΄Π° ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ для описания ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Ρ… строк/Π±Π»ΠΎΠΊΠΎΠ² ΠΊΠΎΠ΄Π° ΠΈΠ»ΠΈ Ρ†Π΅Π»ΠΎΠ³ΠΎ Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΠ°. ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для докумСнтирования ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠΏΠΈΡΠ°Ρ‚ΡŒ ΡΠΏΠ΅Ρ†ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΡŽ ΠΊΠΎΠ΄Π° (Π΅Π³ΠΎ интСрфСйс), Π½Π΅ Π·Π°Π²ΠΈΡΡΡ‰ΡƒΡŽ ΠΎΡ‚ Π΅Π³ΠΎ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ. ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для докумСнтирования Π΄Π΅Π»Π°ΡŽΡ‚ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΎΠ², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±ΡƒΠ΄ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ваши ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ (Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ классов) Π½Π΅ имСя ΠΈΡ… исходного ΠΊΠΎΠ΄Π°.

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π½ΡƒΠΆΠ½Ρ‹, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΊΠΎΠ΄ ΠΈΠ»ΠΈ ΠΏΠΎΡΡΠ½ΠΈΡ‚ΡŒ ΠΌΠΎΠΌΠ΅Π½Ρ‚Ρ‹, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ слоТно ΠΏΠΎΠ½ΡΡ‚ΡŒ нСпосрСдствСнно ΠΈΠ· ΠΊΠΎΠ΄Π°. ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ лишь Ρ‚Ρƒ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ, которая Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠ° для чтСния ΠΈ понимания ΠΊΠΎΠ΄Π° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹. НапримСр ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΎ Ρ‚ΠΎΠΌ, ΠΊΠ°ΠΊ ΠΎΡ‚ΠΊΠΎΠΌΠΏΠΈΠ»ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ связанный ΠΏΠ°ΠΊΠ΅Ρ‚ ΠΈΠ»ΠΈ Π² ΠΊΠ°ΠΊΠΎΠΉ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΎΡ€ΠΈΠΈ ΠΎΠ½ находится Π½Π΅ стоит ΠΎΠΏΠΈΡΡ‹Π²Π°Ρ‚ΡŒ Π² ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ.

    ΠžΠ±ΡΡƒΠΆΠ΄Π΅Π½ΠΈΠ΅ Π½Π΅Ρ‚Ρ€ΠΈΠ²ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΈΠ»ΠΈ Π½Π΅ΠΎΡ‡Π΅Π²ΠΈΠ΄Π½Ρ‹Π΅ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠΉ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ, Π½ΠΎ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ ΠΎΠΏΠΈΡΡ‹Π²Π°Ρ‚ΡŒ Ρ‚ΠΎ, Ρ‡Ρ‚ΠΎ ΠΈ Ρ‚Π°ΠΊ ясно ΠΈΠ· ΠΊΠΎΠ΄Π°. Π’Π°ΠΊΠΈΠ΅ «ΠΈΠ·Π±Ρ‹Ρ‚ΠΎΡ‡Π½Ρ‹Π΅» ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΎΡ‡Π΅Π½ΡŒ быстро ΠΌΠΎΠ³ΡƒΡ‚ ΡΡ‚Π°Ρ‚ΡŒ Π½Π΅Π°ΠΊΡ‚ΡƒΠ°Π»ΡŒΠ½Ρ‹ΠΌΠΈ. Π’ ΠΎΠ±Ρ‰Π΅ΠΌ, слСдуСт ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ Π»ΡŽΠ±Ρ‹Ρ… ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ ΡΡ‚Π°Ρ‚ΡŒ Π½Π΅Π°ΠΊΡ‚ΡƒΠ°Π»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΏΠΎ ΠΌΠ΅Ρ€Π΅ развития ΠΊΠΎΠ΄Π°.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: ЧастоС использованиС ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² ΠΈΠ½ΠΎΠ³Π΄Π° Π³ΠΎΠ²ΠΎΡ€ΠΈΡ‚ ΠΎ Π½ΠΈΠ·ΠΊΠΎΠΌ качСство ΠΊΠΎΠ΄Π°. Когда Π²Ρ‹ чувствуСтС Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎΡΡ‚ΡŒ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ, ΠΏΠΎΠΏΡ€ΠΎΠ±ΡƒΠΉΡ‚Π΅ ΠΏΠ΅Ρ€Π΅ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΊΠΎΠ΄, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ½ стал понятнСС.

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ Π·Π°ΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ Π² большиС ΠΊΠ²Π°Π΄Ρ€Π°Ρ‚Ρ‹, ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½Π½Ρ‹Π΅ Π·Π²Π΅Π·Π΄ΠΎΡ‡ΠΊΠ°ΠΌΠΈ ΠΈΠ»ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ символами. НапримСр:

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… символов, Ρ‚Π°ΠΊΠΈΡ… ΠΊΠ°ΠΊ символ ΠΊΠΎΠ½Ρ†Π° страницы ΠΈΠ»ΠΈ backspace.

    5.1 Π€ΠΎΡ€ΠΌΠ°Ρ‚ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²

    Π’ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°Ρ… ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡΡ 4 Π²ΠΈΠ΄Π° ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²: Π±Π»ΠΎΡ‡Π½Ρ‹Π΅, однострочныС, ΠΏΡ€ΠΈΡ†Π΅ΠΏΠ½Ρ‹Π΅ ΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π΄ΠΎ ΠΊΠΎΠ½Ρ†Π° строки.

    5.1.1 Π‘Π»ΠΎΠΊ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²

    Π‘Π»ΠΎΡ‡Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ для описания Ρ„Π°ΠΉΠ»ΠΎΠ², ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ², структур Π΄Π°Π½Π½Ρ‹Ρ… ΠΈ Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΠΎΠ². Π’Π°ΠΊ ΠΆΠ΅ ΠΈΡ… слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π² Π½Π°Ρ‡Π°Π»Π΅ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΈ ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠΌ. Они Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… мСстах, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Π²Π½ΡƒΡ‚Ρ€ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ². Π‘Π»ΠΎΡ‡Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π²Π½ΡƒΡ‚Ρ€ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΠΌΠ΅Ρ‚ΡŒ отступ Π½Π° Ρ‚ΠΎΠΌ ΠΆΠ΅ ΡƒΡ€ΠΎΠ²Π½Π΅, Ρ‡Ρ‚ΠΎ ΠΈ ΠΊΠΎΠ΄, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΠ½ΠΈ ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‚.

    ΠŸΠ΅Ρ€Π΅Π΄ Π±Π»ΠΎΡ‡Π½Ρ‹ΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ слСдуСт ΠΎΡΡ‚Π°Π²Π»ΡΡ‚ΡŒ ΠΏΡƒΡΡ‚ΡƒΡŽ строку, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½ΠΎ ΠΎΡ‚Π΄Π΅Π»ΠΈΡ‚ΡŒ Π΅Π³ΠΎ ΠΎΡ‚ ΠΊΠΎΠ΄Π°. КаТдая строка Π±Π»ΠΎΡ‡Π½ΠΎΠ³ΠΎ коммСнтария (ΠΊΡ€ΠΎΠΌΠ΅ ΠΏΠ΅Ρ€Π²ΠΎΠΉ) Π΄ΠΎΠ»ΠΆΠ½Π° Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с символа «*«.

    Если Π±Π»ΠΎΡ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ начинаСтся с «/*-«, это ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚ Π² Π΄Π°Π½Π½ΠΎΠΌ Π±Π»ΠΎΠΊΠ΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ особоС Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ нСльзя ΠΏΠΎΡ‚Π΅Ρ€ΡΡ‚ΡŒ (Π’Π°ΠΊΠΎΠΉ Π±Π»ΠΎΠΊ Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΠ΅Ρ€Π΅Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ срСдствами автоформатирования). НапримСр:

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: Если Π²Ρ‹ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚Π΅ срСдства автоформатирования, Π²Π°ΠΌ Π½Π΅ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ «/*-» Π² ΠΊΠΎΠ΄Π΅, Π½ΠΎ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ это Π½Π° случай Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎ ΠΊΡ‚ΠΎ-Ρ‚ΠΎ Π΄Ρ€ΡƒΠ³ΠΎΠΉ ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°ΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ срСдства автоформатирования Π½Π° вашСм ΠΊΠΎΠ΄Π΅.

    5.1.2 ΠžΠ΄Π½ΠΎΡΡ‚Ρ€ΠΎΡ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ

    ΠžΠ΄Π½ΠΎΡΡ‚Ρ€ΠΎΡ‡Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ (ΠΊΠΎΡ€ΠΎΡ‚ΠΊΠΈΠ΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ) ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΈΡΠ°Ρ‚ΡŒ Π² ΠΎΠ΄Π½ΠΎΠΉ строкС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ отступ Π½Π° ΡƒΡ€ΠΎΠ²Π½Π΅ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π³ΠΎ Π±Π»ΠΎΠΊΠ° ΠΊΠΎΠ΄Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΠ½ описываСт. Если ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π΅ помСщаСтся Π² ΠΎΠ΄Π½Ρƒ строку, слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π±Π»ΠΎΡ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ (смотритС «Π‘Π»ΠΎΠΊ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²»). ΠžΠ΄Π½ΠΎΡΡ‚Ρ€ΠΎΡ‡Π½ΠΎΠΌΡƒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΡŽ Π΄ΠΎΠ»ΠΆΠ½Π° ΠΏΡ€Π΅Π΄ΡˆΠ΅ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ пустая строка. Π’ΠΎΡ‚ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ однострочного коммСнтария Π² Java-ΠΊΠΎΠ΄Π΅ (смотритС «ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ»):

    5.1.3 ΠŸΡ€ΠΈΡ†Π΅ΠΏΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ

    ΠžΡ‡Π΅Π½ΡŒ ΠΊΠΎΡ€ΠΎΡ‚ΠΊΠΈΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ ΠΌΠΎΠΆΠ½ΠΎ Ρ€Π°ΡΠΏΠΎΠ»ΠΎΠΆΠΈΡ‚ΡŒ Π½Π° Ρ‚ΠΎΠΉ ΠΆΠ΅ строкС, Ρ‡Ρ‚ΠΎ ΠΈ описываСмый ΠΊΠΎΠ΄. ΠŸΡ€ΠΈ этом Π΅Π³ΠΎ слСдуСт ΡΠ΄Π²ΠΈΠ½ΡƒΡ‚ΡŒ Π²ΠΏΡ€Π°Π²ΠΎ Π½Π°ΡΡ‚ΠΎΠ»ΡŒΠΊΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ½ Π½Π΅ сливался с ΠΊΠΎΠ΄ΠΎΠΌ. Если Π² ΠΎΠ΄Π½ΠΎΠΌ Π±Π»ΠΎΠΊΠ΅ ΠΊΠΎΠ΄Π° присутствуСт Π±ΠΎΠ»Π΅Π΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ Ρ‚Π°ΠΊΠΎΠ³ΠΎ коммСнтария, ΠΈΡ… Π½Π°Ρ‡Π°Π»ΠΎ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ Π½Π° ΠΎΠ΄Π½ΠΎΠΌ ΡƒΡ€ΠΎΠ²Π½Π΅.

    Π‘Ρ‚Π°Ρ€Π°ΠΉΡ‚Π΅ΡΡŒ ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ коммСнтирования ΠΊΠ°ΠΆΠ΄ΠΎΠΉ строчки ΠΊΠΎΠ΄Π° ΠΏΠΎΠ΄ΠΎΠ±Π½Ρ‹ΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΏΡ€ΠΈΡ†Π΅ΠΏΠ½Ρ‹Ρ… ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² Π² Java ΠΊΠΎΠ΄Π΅ (смотритС Ρ‚Π°ΠΊΠΆΠ΅ «ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для докумСнтирования»):

    5.1.4 ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π² ΠΊΠΎΠ½Ρ†Π΅ строки

    Π‘ΠΈΠΌΠ²ΠΎΠ»Π°ΠΌΠΈ // начинаСтся ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ продолТится Π΄ΠΎ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ строки (Π½ΠΎΠ²ΠΎΠΉ строки). Он ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°Π½ΠΈΠΌΠ°Ρ‚ΡŒ всю строку ΠΈΠ»ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π΅Π΅ Ρ‡Π°ΡΡ‚ΡŒ. Π•Π³ΠΎ Π½Π΅ слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ для многострочных ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π², ΠΎΠ΄Π½Π°ΠΊΠΎ Π΅Π³ΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π·Π°ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ нСсколько строк ΠΊΠΎΠ΄Π°. Рассмотрим ΠΏΡ€ΠΈΠΌΠ΅Ρ€ всСх Ρ‚Ρ€Π΅Ρ… Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ΠΎΠ² Π΅Π³ΠΎ использования:

    5.2 ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для докумСнтирования

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: смотритС «ΠŸΡ€ΠΈΠΌΠ΅Ρ€ Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java» для ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ² Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΎΠ² ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π², описанных здСсь.

    Для получСния Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΉ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ смотритС «ΠšΠ°ΠΊ Π½Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΊ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Ρƒ для Javadoc«, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ Π² сСбя ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΎ Ρ‚Π΅Π³Π°Ρ… ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π° (@return, @param, @see):

    Для получСния большСй ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ ΠΎ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΡ… коммСнтариях ΠΈ Javadoc, посСтитС домашнюю страницу Javadoc:

    Π”ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠ΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‚ Java классы, интСрфСйсы, конструкторы, ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ ΠΈ поля. ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ помСщаСтся Π² ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΡ‚Π΅Π»ΠΈ /**. */, ΠΎΠ΄ΠΈΠ½ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π° ΠΎΠ΄ΠΈΠ½ элСмСнт API. Π’Π°ΠΊΠΎΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π΄ΠΎΠ»ΠΆΠ΅Π½ Ρ€Π°ΡΠΏΠΎΠ»Π°Π³Π°Ρ‚ΡŒΡΡ нСпосрСдствСнно ΠΏΠ΅Ρ€Π΅Π΄ объявлСниСм:

    ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ классы ΠΈ интСрфСйсы Π½Π΅ ΠΈΠΌΠ΅ΡŽΡ‚ отступов, Π² ΠΎΡ‚Π»ΠΈΡ‡ΠΈΠΈ ΠΎΡ‚ ΠΈΡ… Ρ‡Π»Π΅Π½ΠΎΠ². ΠŸΠ΅Ρ€Π²Π°Ρ строка Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ коммСнтария (/**) для классов ΠΈ интСрфСйсов Π½Π΅ ΠΈΠΌΠ΅Π΅Ρ‚ отступов; каТдая ΠΏΠΎΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π°Ρ строка Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ коммСнтария ΠΈΠΌΠ΅Π΅Ρ‚ 1 ΠΏΡ€ΠΎΠ±Π΅Π» (для Π²Π΅Ρ€Ρ‚ΠΈΠΊΠ°Π»ΡŒΠ½ΠΎΠ³ΠΎ выравнивания Π·Π²Π΅Π·Π΄ΠΎΡ‡Π΅ΠΊ). Π§Π»Π΅Π½Ρ‹ класса, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ конструкторы, ΠΈΠΌΠ΅ΡŽΡ‚ 4 ΠΏΡ€ΠΎΠ±Π΅Π»Π° для ΠΏΠ΅Ρ€Π²ΠΎΠΉ строки Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ коммСнтария ΠΈ 5 для ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Ρ….

    Если Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΏΡ€Π΅Π΄ΠΎΡΡ‚Π°Π²ΠΈΡ‚ΡŒ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΎ классС, интСрфСйсС, ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π΅, Π½Π΅ ΠΏΡ€ΠΈΠ½Π°Π΄Π»Π΅ΠΆΠ°Ρ‰ΡƒΡŽ ΠΊ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π±Π»ΠΎΡ‡Π½Ρ‹ΠΉ (смотритС Ρ€Π°Π·Π΄Π΅Π» 5.1.1) ΠΈΠ»ΠΈ однострочный (смотритС Ρ€Π°Π·Π΄Π΅Π» 5.1.2) ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ нСпосрСдствСнно послС объявлСния. НапримСр, Π΄Π΅Ρ‚Π°Π»ΠΈ ΠΎ Ρ€Π΅Π°Π»ΠΈΠ·ΡƒΠ΅ΠΌΠΎΠΌ классС Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΠ΄Ρ‚ΠΈ Π² Ρ‚Π°ΠΊΠΎΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π² Π±Π»ΠΎΠΊΠ΅ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ, Π° Π½Π΅ Π² Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅ΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ.

    Π”ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ Ρ€Π°ΡΠΏΠΎΠ»Π°Π³Π°Ρ‚ΡŒΡΡ Π²Π½ΡƒΡ‚Ρ€ΠΈ Π±Π»ΠΎΠΊΠ° Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° ΠΈΠ»ΠΈ конструктора, ΠΏΠΎΡ‚ΠΎΠΌΡƒ Ρ‡Ρ‚ΠΎ Java связываСт Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ с ΠΏΠ΅Ρ€Π²Ρ‹ΠΌ послС Π½Π΅Π³ΠΎ объявлСниСм.

    6.1 ΠšΠΎΠ»ΠΈΡ‡Π΅ΡΡ‚Π²ΠΎ объявлСний Π² строкС

    РСкомСндуСтся ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΎΠ΄Π½ΠΎ объявлСниС Π½Π° строку, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ это ΠΎΠ±Π»Π΅Π³Ρ‡Π°Π΅Ρ‚ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅. Π”Ρ€ΡƒΠ³ΠΈΠΌΠΈ словами:

    Ни Π² ΠΊΠΎΠ΅ΠΌ случаС нСльзя ΠΎΠ±ΡŠΡΠ²Π»ΡΡ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π² ΠΎΠ΄Π½ΠΎΠΉ строкС. НапримСр:

    НС ΠΏΠΎΠΌΠ΅Ρ‰Π°ΠΉΡ‚Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Ρ€Π°Π·Π½Ρ‹Ρ… Ρ‚ΠΈΠΏΠΎΠ² (имССтся Π² Π²ΠΈΠ΄Ρƒ Π½Π΅ Ρ‚ΠΈΠΏ самих ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…, Π° Ρ‚ΠΈΠΏ Π΄Π°Π½Π½Ρ‹Ρ… ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π² Π½ΠΈΡ… хранятся) Π² ΠΎΠ΄Π½Ρƒ строку. НапримСр:

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: Π’ ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Π½Ρ‹Ρ… Π²Ρ‹ΡˆΠ΅ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°Ρ… ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ ΠΎΠ΄ΠΈΠ½ ΠΏΡ€ΠΎΠ±Π΅Π» ΠΌΠ΅ΠΆΠ΄Ρƒ Ρ‚ΠΈΠΏΠΎΠΌ ΠΈ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ΠΎΠΌ. Π”Ρ€ΡƒΠ³ΠΎΠΉ ΠΏΡ€ΠΈΠ΅ΠΌΠ»Π΅ΠΌΠΎΠΉ Π°Π»ΡŒΡ‚Π΅Ρ€Π½Π°Ρ‚ΠΈΠ²ΠΎΠΉ являСтся использованиС табуляции для выравнивания ΠΈΠ½Π΅Π΄Π½Ρ‚ΠΈΠ²ΠΈΠΊΡ‚ΠΎΡ€ΠΎΠ² Π² ΠΎΠ΄ΠΈΠ½Ρƒ линию (использованиС клавиши Tab которая Ρ€Π°Π²Π½Π° ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ 4-ΠΌ ΠΏΡ€ΠΎΠ±Π΅Π»Π°ΠΌ), Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€:

    6.2 Π Π°Π·ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅

    Π Π°Π·ΠΌΠ΅Ρ‰Π°ΠΉΡ‚Π΅ объявлСния Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² Π½Π°Ρ‡Π°Π»Π΅ Π±Π»ΠΎΠΊΠΎΠ² (Π±Π»ΠΎΠΊΠΎΠΌ являСтся любой ΠΊΠΎΠ΄, Π·Π°ΠΊΠ»ΡŽΡ‡Π΅Π½Π½Ρ‹ΠΉ Π² Ρ„ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки «<«» ΠΈ «>«). НС ΠΆΠ΄ΠΈΡ‚Π΅ объявлСния ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… Π΄ΠΎ ΠΈΡ… ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ использования; Π­Ρ‚ΠΎ ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°ΠΏΡƒΡ‚Π°Ρ‚ΡŒ Π½Π΅ΠΎΠΏΡ‹Ρ‚Π½ΠΎΠ³ΠΎ программиста ΠΈ Π·Π°Ρ‚Ρ€ΡƒΠ΄Π½ΠΈΡ‚ΡŒ ΠΏΠ΅Ρ€Π΅Π½ΠΎΡΠΈΠΌΠΎΡΡ‚ΡŒ ΠΊΠΎΠ΄Π° Π² ΠΏΡ€Π΅Π΄Π΅Π»Π°Ρ… области.

    ЕдинствСнным ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ ΠΈΠ· этого ΠΏΡ€Π°Π²ΠΈΠ»Π° ΡΠ²Π»ΡΡŽΡ‚ΡΡ индСксы Ρ†ΠΈΠΊΠ»ΠΎΠ² for, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π² Java ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΠΎΠ±ΡŠΡΠ²Π»Π΅Π½Ρ‹ Π² ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π΅ for:

    Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… объявлСний, ΠΏΠ΅Ρ€Π΅ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰ΠΈΡ… объявлСния Π±ΠΎΠ»Π΅Π΅ высокого уровня. НапримСр, Π½Π΅ ΠΎΠ±ΡŠΡΠ²Π»ΡΠΉΡ‚Π΅ ΠΎΠ΄Π½Ρƒ ΠΈ Ρ‚Ρƒ ΠΆΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ ΠΏΠ΅Ρ€Π΅Π΄ Π±Π»ΠΎΠΊΠΎΠΌ ΠΊΠΎΠ΄Π° ΠΈ Π²ΠΎ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΌ Π±Π»ΠΎΠΊΠ΅:

    6.3 Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΡ

    Π‘Ρ‚Π°Ρ€Π°ΠΉΡ‚Π΅ΡΡŒ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Ρ‚Π°ΠΌ, Π³Π΄Π΅ Π²Ρ‹ ΠΈΡ… ΠΎΠ±ΡŠΡΠ²Π»ΡΠ΅Ρ‚Π΅. ЕдинствСнная ΠΏΡ€ΠΈΡ‡ΠΈΠ½Π° Π½Π΅ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ Π² мСстС Π΅Ρ‘ объявлСния β€” Ссли Π΅Ρ‘ Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ зависит ΠΎΡ‚ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… ΠΏΡ€Π΅Π΄Π²Π°Ρ€ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… вычислСний.

    6.4 ОбъявлСния классов ΠΈ интСрфСйсов

    ΠŸΡ€ΠΈ написании Java классов ΠΈ интСрфСйсов Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΡΠΎΠ±Π»ΡŽΠ΄Π°Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ ΠΏΡ€Π°Π²ΠΈΠ»Π° форматирования:

    7.1 ΠŸΡ€ΠΎΡΡ‚Ρ‹Π΅ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹

    КаТдая строка Π΄ΠΎΠ»ΠΆΠ½Π° ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ Π½Π΅ Π±ΠΎΠ»Π΅Π΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π°. НапримСр:

    НС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π·Π°ΠΏΡΡ‚ΡƒΡŽ для Π³Ρ€ΡƒΠΏΠΏΠΈΡ€ΠΎΠ²ΠΊΠΈ Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ², Π΄Π°ΠΆΠ΅ Ссли это Π²ΠΈΠ΄Π½ΠΎ Π½Π΅Π²ΠΎΠΎΡ€ΡƒΠΆΠ΅Π½Π½Ρ‹ΠΌ Π³Π»Π°Π·ΠΎΠΌ. НапримСр:

    7.2 БоставныС ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹
    7.3 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ return

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ return, Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅, Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ скобки, Ссли Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΈΡ… использованиС Π½Π΅ сдСлаСт Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π±ΠΎΠ»Π΅Π΅ понятным. НапримСр:

    7.4 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ if, if-else, if-else-if-else

    Π“Ρ€ΡƒΠΏΠΏΠ° ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ² (ΠΊΠ°ΠΊ ΠΈ Π΅Π΄Π΅Π½ΠΈΡ‡Π½ΠΎΠ΅ использованиС) if-else Π΄ΠΎΠ»ΠΆΠ½Π° ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ if всСгда Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡΡ с Ρ„ΠΈΠ³ΡƒΡ€Π½Ρ‹ΠΌΠΈ скобками » «. Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ Ρ„ΠΎΡ€ΠΌΡ‹:

    7.5 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° for

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° for Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    ΠŸΡƒΡΡ‚ΠΎΠΉ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° for (Ρ‚ΠΎΡ‚, Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ вся Ρ€Π°Π±ΠΎΡ‚Π° выполняСтся Π² ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ, условии ΠΈ ΠΈΡ‚Π΅Ρ€Π°Ρ†ΠΈΠΈ) Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    ΠŸΡ€ΠΈ использовании ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° запятой Π² Π±Π»ΠΎΠΊΠ΅ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΈΠ»ΠΈ ΠΈΡ‚Π΅Ρ€Π°Ρ†ΠΈΠΈ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π° Ρ†ΠΈΠΊΠ»Π° for ΠΈΠ·Π±Π΅Π³Π°ΠΉΡ‚Π΅ использования Π±ΠΎΠ»Π΅Π΅ Ρ‡Π΅ΠΌ Ρ‚Ρ€Π΅Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…. Если Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ ΠΏΠ΅Ρ€Π΅Π΄ Ρ†ΠΈΠΊΠ»ΠΎΠΌ for (для случая Π±Π»ΠΎΠΊΠ° ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ) ΠΈΠ»ΠΈ Π² ΠΊΠΎΠ½Ρ†Π΅ Ρ†ΠΈΠΊΠ»Π° (для случая Π±Π»ΠΎΠΊΠ° ΠΈΡ‚Π΅Ρ€Π°Ρ†ΠΈΠΈ).

    7.6 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° while

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° while Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    ΠŸΡƒΡΡ‚ΠΎΠΉ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° while Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    7.7 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° do-while

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ†ΠΈΠΊΠ»Π° do-while Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄:

    7.8 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ switch

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ switch Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ Ρ„ΠΎΡ€ΠΌΡƒ:

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ€Π°Π·, ΠΊΠΎΠ³Π΄Π° Π²Ρ‹Π±ΠΎΡ€ проваливаСтся (Π½Π΅ Π²ΠΊΠ»ΡŽΡ‡Π°Ρ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ break), Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ, Π³Π΄Π΅ ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ находится ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ break. Π­Ρ‚ΠΎ ΠΏΠΎΠΊΠ°Π·Π°Π½ΠΎ Π² ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΌ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅ ΠΊΠΎΠ΄Π° с ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ /* ΠΏΡ€ΠΎΠ²Π°Π» */.

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ switch Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²ΠΊΠ»ΡŽΡ‡Π°Ρ‚ΡŒ Π²Ρ‹Π±ΠΎΡ€ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ (default). ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ break Π² Π²Ρ‹Π±ΠΎΡ€Π΅ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ лишний, Π½ΠΎ ΠΎΠ½ ΠΏΡ€Π΅Π΄ΠΎΡ‚Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ Π²ΠΎΠ·Π½ΠΈΠΊΠ½ΠΎΠ²Π΅Π½ΠΈΠ΅ ошибки, Ссли ΠΏΠΎΠ·ΠΆΠ΅ Π΅Ρ‰Π΅ ​​один Π²Ρ‹Π±ΠΎΡ€ добавится.

    7.9 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ try-catch

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ try-catch Π΄ΠΎΠ»ΠΆΠ½ ΠΈΠΌΠ΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚:

    8.1 ΠŸΡƒΡΡ‚Ρ‹Π΅ строки

    ΠŸΡƒΡΡ‚Ρ‹Π΅ строки ΡƒΠ»ΡƒΡ‡ΡˆΠ°ΡŽΡ‚ Ρ‡ΠΈΡ‚Π°Π±Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ, выдСляя Ρ€Π°Π·Π΄Π΅Π»Ρ‹ ΠΊΠΎΠ΄Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ логичСски связаны ΠΌΠ΅ΠΆΠ΄Ρƒ собой.

    Π”Π²Π΅ пустыС строки всСгда Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… случаях:

    Одна пустая строка всСгда Π΄ΠΎΠ»ΠΆΠ½Π° ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… случаях:

    8.2 Расстановка ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ²

    Π Π°Π·Π΄Π΅Π»ΡΡŽΡ‰ΠΈΠ΅ ΠΏΡ€ΠΎΠ±Π΅Π»Ρ‹ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΡ‚Π°Π²ΠΈΡ‚ΡŒΡΡ ΠΏΡ€ΠΈ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… ΠΎΠ±ΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΡΡ‚Π²Π°Ρ…:

    ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ ΠΏΡ€ΠΎΠ±Π΅Π» Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ ΠΌΠ΅ΠΆΠ΄Ρƒ ΠΈΠΌΠ΅Π½Π΅ΠΌ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° ΠΈ Π΅Π³ΠΎ ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰Π΅ΠΉ скобкой. Π­Ρ‚ΠΎ ΠΏΠΎΠΌΠΎΠ³Π°Π΅Ρ‚ ΠΎΡ‚Π»ΠΈΡ‡Π°Ρ‚ΡŒ ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹Π΅ слова ΠΎΡ‚ Π²Ρ‹Π·ΠΎΠ²ΠΎΠ² ΠΌΠ΅Ρ‚ΠΎΠ΄Π°.

    ΠŸΡ€Π°Π²ΠΈΠ»Π°, ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Π½Ρ‹Π΅ Π² Π΄Π°Π½Π½ΠΎΠΌ Ρ€Π°Π·Π΄Π΅Π»Π΅, ΡΠ²Π»ΡΡŽΡ‚ΡΡ ΠΎΡΠ½ΠΎΠ²ΠΎΠΏΠΎΠ»Π°Π³Π°ΡŽΡ‰ΠΈΠΌΠΈ. Π‘ΠΎΠ»Π΅Π΅ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½Ρ‹Π΅ ΠΏΡ€Π°Π²ΠΈΠ»Π° ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Ρ‹ Π² Ρ‚Π°Π±Π»ΠΈΡ†Π΅:

    10.1 ΠžΠ±Π΅ΡΠΏΠ΅Ρ‡Π΅Π½ΠΈΠ΅ доступа ΠΊ экзСмпляру ΠΈ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ класса

    Одним ΠΈΠ· ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ² умСстного использования public ΠΏΠΎΠ»Π΅ΠΉ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ случай, ΠΊΠΎΠ³Π΄Π° класс описываСт лишь структуру Π΄Π°Π½Π½Ρ‹Ρ…, Π±Π΅Π· ΠΊΠ°ΠΊΠΎΠ³ΠΎ-Π»ΠΈΠ±ΠΎ повСдСния. Π”Ρ€ΡƒΠ³ΠΈΠΌΠΈ словами, Ссли Π±Ρ‹ Π²Ρ‹ ΠΌΠΎΠ³Π»ΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ struct вмСсто class (Ссли Π±Ρ‹ Java ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π» struct), Ρ‚ΠΎΠ³Π΄Π° ΠΌΠΎΠΆΠ½ΠΎ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ экзСмпляра класса public.

    10.2 ΠžΠ±Ρ€Π°Ρ‰Π΅Π½ΠΈΠ΅ ΠΊ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌ класса

    Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ использованиС ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° для доступа ΠΊ статичСским полям ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌ класса. ВмСсто этого ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ имя класса. НапримСр:

    10.3 ΠšΠΎΠ½ΡΡ‚Π°Π½Ρ‚Ρ‹

    ЧислСнныС константы (Π»ΠΈΡ‚Π΅Ρ€Π°Π»Ρ‹) Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ, Π·Π° ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ -1, 0 ΠΈ 1, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² Ρ†ΠΈΠΊΠ»Π°Ρ… для управлСния счСтчиком.

    10.4 ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ присваивания Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ ΠΈ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π°ΠΌ ΠΈ Ρ‚.Π΄.

    Π˜Π·Π±Π΅Π³Π°ΠΉΡ‚Π΅ присваивания значСния Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ Π² ΠΎΠ΄Π½ΠΎΠΌ Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠΈ. Π­Ρ‚ΠΎ услоТняСт Ρ‡Ρ‚Π΅Π½ΠΈΠ΅. НапримСр:

    НС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ присваивания Π² мСстах, Π³Π΄Π΅ ΠΎΠ½ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ Π»Π΅Π³ΠΊΠΎ спутан с ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ сравнСния. НапримСр:

    Π»ΡƒΡ‡ΡˆΠ΅ Π½Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Π°ΠΊ:

    НС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Π΅ присваивания, ΠΏΡ‹Ρ‚Π°ΡΡΡŒ ΡƒΡΠΊΠΎΡ€ΠΈΡ‚ΡŒ ΡΠΊΠΎΡ€ΠΎΡΡ‚ΡŒ выполнСния ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹. Π­Ρ‚ΠΎ Ρ€Π°Π±ΠΎΡ‚Π° компилятора, ΠΈ, ΠΊΡ€ΠΎΠΌΠ΅ Ρ‚ΠΎΠ³ΠΎ, Π½Π° самом Π΄Π΅Π»Π΅ Ρ€Π΅Π΄ΠΊΠΎ ΠΏΠΎΠΌΠΎΠ³Π°Π΅Ρ‚. НапримСр:

    Π΄ΠΎΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ написано Ρ‚Π°ΠΊ:

    10.5 Π Π°Π·Π»ΠΈΡ‡Π½Ρ‹Π΅ ΠΏΡ€ΠΈΡ‘ΠΌΡ‹ программирования
    10.5.1 ΠšΡ€ΡƒΠ³Π»Ρ‹Π΅ скобки
    10.5.2 Π’ΠΎΠ·Π²Ρ€Π°Ρ‚ значСния

    ΠŸΠΎΠΏΡ€ΠΎΠ±ΡƒΠΉΡ‚Π΅ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ структуру вашСй ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ понятной. НапримСр:

    вмСсто этого слСдуСт Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Π°ΠΊ:

    Π»ΡƒΡ‡ΡˆΠ΅ Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Π°ΠΊ:

    10.5.3 ВыраТСния ΠΏΠ΅Ρ€Π΅Π΄ ‘?’ Π² условном ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π΅

    Если Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ содСрТит Π±ΠΈΠ½Π°Ρ€Π½Ρ‹ΠΉ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€, находящийся ΠΏΠ΅Ρ€Π΅Π΄ Ρ‚Π΅Ρ€Π½Π°Ρ€Π½Ρ‹ΠΌ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ ?:, ΠΎΠ½ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Π·Π°ΠΊΠ»ΡŽΡ‡Π΅Π½ Π² скобки. НапримСр:

    10.5.4 Π‘ΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ

    Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ XXX Π² ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎ этот ΠΊΠΎΠ΄ Π½Π΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ, Π½ΠΎ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚. Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ FIXME для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎ ΠΊΠΎΠ΄ Π½Π΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ ΠΈ Π½Π΅ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚.

    11.1 ΠŸΡ€ΠΈΠΌΠ΅Ρ€ Ρ„Π°ΠΉΠ»Π° с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java

    Π‘Π»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ ΠΊΠ°ΠΊ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Ρ„Π°ΠΉΠ» с исходным ΠΊΠΎΠ΄ΠΎΠΌ Java, содСрТащим ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ класс. Π˜Π½Ρ‚Π΅Ρ€Ρ„Π΅ΠΉΡΡ‹ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ΡΡ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ. Для Π±ΠΎΠ»Π΅Π΅ ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½ΠΎΠ³ΠΎ изучСния ΠΏΡ€ΠΎΡ‡Ρ‚ΠΈΡ‚Π΅ «ΠžΠ±ΡŠΡΠ²Π»Π΅Π½ΠΈΠ΅ классов ΠΈ интСрфСйсов» ΠΈ «Π”ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠ΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ«.

    Π’Π΅Ρ€ΡΠΈΡŽ для ΠΎΡ„Ρ„Π»Π°ΠΉΠ½ чтСния ΠΌΠΎΠΆΠ½ΠΎ Π½Π°ΠΉΡ‚ΠΈ Π² ΠΌΠΎΠ΅ΠΌ Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΈ Github

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Guidelines, Patterns, and code for end-to-end Java applications

    Naming Conventions for Enterprise Applications Early Access 2

    This document describes the naming conventions that the BluePrints team uses for its sample applications. These conventions pertain to the various components and modules in the Java 2 Platform, Enterprise Edition (J2EE). By applying these conventions, your modules and components will be easier to identify and organize, thus enhancing their maintenance and promoting better coordination on large projects.

    All conventions described here are compliant to Code Conventions for the Java Programming Language.

    J2EE Application, Module, and Component Names

    Description

    References in the Code Conventions
    Application NameThe application name is used as the application archive name. By default, the application name should be indicative of the application and should be written in all-lowercase ASCII letters. In case of conflict, the application name should be a more specific and descriptive version:

    petstore.ear // enterprise archive

    or (in case of conflict):

    bppetstore.ear // enterprise archive

    The application display name (in the application deployment descriptor) is the expanded 1 application name written in mixed cases:

    or (in case of conflict):

    Follows naming conventions for packages
    Enterprise JavaBeans (EJB) Module NameThe module name is used as the EJB archive name. By default, the module name should be based on the package name and should be written in all-lowercase ASCII letters. In case of conflict, the module name should be a more specific version (including other part of the package name):

    com.sun.j2ee.blueprints. petstore petstore-ejb.jar // EJB archive petstore-ejb-client.jar // EJB client archive

    or (in case of conflict):

    bppetstore-ejb.jar // EJB archive bppetstore-ejb-client.jar // EJB client archive

    The module display name (in the EJB deployment descriptor) is the expanded module name written in mixed cases:

    or (in case of conflict):

    BluePrintsPetStoreJAR

    Web Module NameThe module name is used as the web archive name. By default, the module name should be based on the package name and should be written in all-lowercase ASCII letters. In case of conflict, the module name should be a more specific version (including other part of the package name):

    Midlet client archive:

    com.sun.j2ee.blueprints. petstore petstore.war // Web archive petstore-applet-client.jar // Applet archive

    or (in case of conflict):

    bppetstore.war // Web archive

    bppetstore-applet-client.jar // Applet archive

    The module display name (in the Web deployment descriptor) is the expanded module name written in mixed cases:

    or (in case of conflict):

    Follows naming conventions for packages
    Component NameThe component is the base name of the EJB or web component class name and should be written in mixed case with the first letter of each internal word capitalized.

    ContactInfoBean

    Follows naming conventions for classes

    2. EJB Component Names

    This includes naming conventions for the different parts of an enterprise bean. Wherever these names go in the deployment descriptor, it has been specified. The conventions listed here does not mention the type of the bean explicitly, except for the display name in the deployment descriptor.

    References in the Code Conventions

    Entity BeanLocal interface: or Local

    Local home interface: Home or LocalHome

    Remote interface: Remote

    Remote home interface: RemoteHome

    Implementation class: Bean

    Primary key implementation:

    Name in the EJB deployment descriptor: Bean

    Display name in the EJB deployment descriptor:

    Follows naming conventions for classes
    Session BeanLocal interface: or Local

    Local home interface: Home or LocalHome

    Remote interface: Remote

    Remote home interface: RemoteHome

    Implementation class: Bean

    Name in the EJB deployment descriptor: Bean

    Display name in the EJB deployment descriptor: SB

    Follows naming conventions for classes
    Message Driven BeanImplementation class: Bean

    Name in the deployment descriptor: Bean

    Display name in the EJB deployment descriptor: MDB

    Follows naming conventions for classes

    3. Web Component Names

    This includes naming conventions for Servlets and JavaServer Pages TM and their related artifacts like Servlet filters and JavaServer Pages TM tags

    References in the Code Conventions

    ServletImplementation class: Servlet

    Name in the Web deployment descriptor: component-name

    Display name in the Web deployment descriptor: Servlet

    FilterImplementation: Filter

    Name in the Web deployment descriptor: component-name

    Display name in the Web deployment descriptor: Filter

    ListenerFor classes implement following listener interfaces:

    Name in the Web deployment descriptor: component-name

    Display name in the Web deployment descriptor: Listener

    JavaServer Pages TMJSP (file) name should always begin with a lower-case letter. The name may consists of multiple words, in which case the words are placed immediately adjacent and each word commences with an upper-case letter. A JSP name can be just a simple noun or a short sentence. A verb-only JSP name should be avoided, as it does not convey sufficient information to developers.

    Here’re conventions for other file types.

    4. Web service Names

    This includes naming conventions for Web service clients and endpoints and the necessary configuration files.

    References in the Code Conventions

    Service NameThe service name is the base name of the EJB or JAX-RPC endpoint class name and should be written in mixed case with the first letter of each internal word capitalized.

    WeatherService

    Follows naming conventions for classes
    EJB service endpointService endpoint interface : SEI

    Service implementation class : Bean

    Follows naming conventions for classes
    JAX-RPC service endpointService endpoint interface : SEI

    Service implementation class : Impl

    Follows naming conventions for classes
    JAX-RPC message handlerClient side handler : ClientHandler

    Server side handler : ServerHandler

    Follows naming conventions for classes
    Configuration filesWSDL file :

    5. Reference Names

    EJB reference name is the logical name you use in your source code for a JNDI lookup of the home interface of the referenced bean. This name also apperas as the value of the ejb-ref-name element within the ejb-ref element in the deployment decriptor of the referencing component.

    Web service reference name is the name used by Web service clients for a JNDI lookup to obtain a reference to a Web service. This name also apperas as the value of the service-ref-name element within the service-ref element in the deployment decriptor of the referencing component.

    Environment entry names are the names used by a component for a JNDI lookup of some customizable parameters. T his name also apperas as the value of the env-entry-name element within the env-entry element in the deployment decriptor of the component.

    All the reference names are relative to java:comp/env.

    DescriptionReferences in the Code Conventions
    EJB ReferencesBy default, the EJB reference name should be based on the component name. The component name should be written in mixed case with the first letter of each internal word capitalized

    If you have only the local or the remote interface, you may want to use just ejb/ and leave out the suffixes. If you have both kind of interfaces, you may want to use the suffix only for the remote interfaces since typically you will have fewer of them.

    In case of conflict, the EJB reference name should be a more specific version of the component name.

    Say you have a Customer EJB module ( customer-ejb.jar ) which contains the ContactInfoBean component ( ContactInfoBean.class). In this case, the Customer module will refer to the ContactInfo module in the following way:

    In case, the Customer module had two ContactInfo objects: one for customer, and one for supplier; the names will be:

    ejb/CustomerContactInfo ejb/SupplierContactInfo

    Web service referencesThe Web service reference name should be based on the service name. The service name should be written in mixed case with the first letter of each internal word capitalized

    service/CreditCardService

    Resource References

    6. Database Names

    This applies to the databases that map to CMP entity beans. This convention does not apply when you are mapping CMP entities to a prexisting schema, since the database entities already have names.

    References in the Code Conventions

    DatabaseIf your organization already has a convention for database naming, follow that. Otherwise, name CMP databases after the application.

    For example: PetStore DB

    7. XML Document Names

    DescriptionReferences in the Code Conventions
    XML DocumentsOne possible notation:

    Element names follow the code convention of class names and should be written in mixed case with the first letter of each internal word capitalized.

    Attribute names follow the code convention of variable names and should be written in mixed case with a lower case first letter.

    Enumerated Attribute values follow the code convention of constants and should be written in upper case with words seperated by underscores.

    Another possible notation:

    Element names are written in lower case with words separeted by a hyphen ‘-‘.

    Attribute names follow the code convention of variable names and should be written in mixed case with a lower case first letter.

    Enumerated attribute values follow the code convention of constants and should be written in upper case with words seperated by underscores.

    Any other notation as long as it is consistent across your application

    Follows Classes, Variable, Constant

    8. Deployment Descriptor Names

    Deployment Descriptors 2

    J2EE application deployment descriptor: application.xml

    J2EE application client deployment descriptor: application-client.xml

    Web services deployment descriptor: webservices.xml

    Sun Java System Application Server specific EJB deployment descriptor: sun-ejb-jar.xml

    Sun Java System Application Server specific Web deployment descriptor: sun-web.xml

    1 All abbreviations expanded, like β€œOrderProcessingCenter” for OPC.

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Руководство Google ΠΏΠΎ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΡŽ ΠΊΠΎΠ΄Π° Π½Π° Java

    Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ Java code conventions. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ Java code conventions. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ Java code conventions. Π€ΠΎΡ‚ΠΎ Java code conventions

    1. Π’Π²Π΅Π΄Π΅Π½ΠΈΠ΅

    Π’ Π΄Π°Π½Π½ΠΎΠΌ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π΅ описаны стандарты написания ΠΊΠΎΠ΄Π° Π½Π° языкС программирования Java Π² ΠΊΠΎΡ€ΠΏΠΎΡ€Π°Ρ†ΠΈΠΈ Google. Π˜ΡΡ…ΠΎΠ΄Π½Ρ‹ΠΉ ΠΊΠΎΠ΄ Java считаСтся ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ этим стандартам Ρ‚ΠΎΠ³Π΄Π° ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρ‚ΠΎΠ³Π΄Π°, ΠΊΠΎΠ³Π΄Π° ΠΎΠ½ удовлСтворяСт всСм описанным Π² Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π΅ ΠΏΡ€Π°Π²ΠΈΠ»Π°ΠΌ.

    Π—Π°Ρ‚Ρ€ΠΎΠ½ΡƒΡ‚Ρ‹Π΅ Π² руководствС Ρ‚Π΅ΠΌΡ‹ ΠΊΠ°ΡΠ°ΡŽΡ‚ΡΡ Π½Π΅ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ эстСтичСской стороны форматирования ΠΊΠΎΠ΄Π°, Π½ΠΎ ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΡ… Ρ‚ΠΈΠΏΠΎΠ² соглашСний ΠΈΠ»ΠΈ стандартов кодирования. Π’Π΅ΠΌ Π½Π΅ ΠΌΠ΅Π½Π΅Π΅, Π΄Π°Π½Π½Ρ‹ΠΉ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ концСнтрируСтся Π² ΠΏΠ΅Ρ€Π²ΡƒΡŽ ΠΎΡ‡Π΅Ρ€Π΅Π΄ΡŒ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠΈ строгих ΠΏΡ€Π°Π²ΠΈΠ», ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ ΠΌΡ‹ повсСмСстно слСдуСм, ΠΈ Π½Π΅ Π΄Π°Π΅Ρ‚ Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄Π°Ρ†ΠΈΠΉ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ Π½Π΅Π²Π΅Ρ€Π½ΠΎ Ρ€Π΅Π°Π»ΠΈΠ·ΠΎΠ²Π°Π½Ρ‹ (ΠΊΠ°ΠΊ Ρ‡Π΅Π»ΠΎΠ²Π΅ΠΊΠΎΠΌ, Ρ‚Π°ΠΊ ΠΈ ΠΌΠ°ΡˆΠΈΠ½Π½Ρ‹ΠΌΠΈ инструмСнтами).

    1.1 ВСрминология

    Π’ Ρ€Π°ΠΌΠΊΠ°Ρ… этого руководства ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ Ρ‚Π΅Ρ€ΠΌΠΈΠ½Ρ‹:

    1.2 ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅ ΠΊ руководству

    ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ ΠΊΠΎΠ΄Π° Π² Π΄Π°Π½Π½ΠΎΠΌ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π΅ Π½Π΅ Π΄Π΅ΠΌΠΎΠ½ΡΡ‚Ρ€ΠΈΡ€ΡƒΡŽΡ‚ СдинствСнно Π²Π΅Ρ€Π½Ρ‹ΠΉ стилистичСский ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ ΠΊ Π΅Π³ΠΎ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΡŽ, хотя ΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ Π² нашСм руководствС.

    2. Π˜ΡΡ…ΠΎΠ΄Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ». ΠžΡΠ½ΠΎΠ²Ρ‹

    2.1 Имя Ρ„Π°ΠΉΠ»Π°

    2.2 ΠšΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ° Ρ„Π°ΠΉΠ»Π°: UTF-8

    Для Ρ„Π°ΠΉΠ»ΠΎΠ² с ΠΊΠΎΠ΄ΠΎΠΌ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ° UTF-8.

    2.3 Π‘ΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅ символы

    2.3.1 Π‘ΠΈΠΌΠ²ΠΎΠ»Ρ‹ ΠΏΡ€ΠΎΠ±Π΅Π»Π°

    Помимо ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ символов ΠΊΠΎΠ½Ρ†Π° строки, Π³ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½Ρ‹ΠΉ символ ΠΏΡ€ΠΎΠ±Π΅Π»Π° ASCII (0Γ—20) являСтся СдинствСнным символом-Ρ€Π°Π·Π΄Π΅Π»ΠΈΡ‚Π΅Π»Π΅ΠΌ, Π²ΡΡ‚Ρ€Π΅Ρ‡Π°ΡŽΡ‰ΠΈΠΌΡΡ Π² исходном Ρ„Π°ΠΉΠ»Π΅. Π­Ρ‚ΠΎ ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚, Ρ‡Ρ‚ΠΎ:

    2.3.2 Π‘ΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅ ΡΠΊΡ€Π°Π½ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠ΅ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ

    Для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ символа, для ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ сущСствуСт ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Π°Ρ ΡΠΊΡ€Π°Π½ΠΈΡ€ΡƒΡŽΡ‰Π°Ρ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ (\b, \t, \n, \f, \r, \», \’ ΠΈ \\), ΠΏΡ€Π΅Π΄ΠΏΠΎΡ‡Ρ‚ΠΈΡ‚Π΅Π»ΡŒΠ½Π΅Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΌΠ΅Π½Π½ΠΎ Π΅Π΅ вмСсто ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π³ΠΎ Π΅ΠΉ Π²ΠΎΡΡŒΠΌΠ΅Ρ€ΠΈΡ‡Π½ΠΎΠ³ΠΎ значСния (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, \012) ΠΈΠ»ΠΈ ΠΊΠΎΠ΄Π° Unicode (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, \u000a).

    2.3.3 Π‘ΠΈΠΌΠ²ΠΎΠ»Ρ‹ Π½Π΅ ΠΈΠ· Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ ASCII

    Для символов Π½Π΅ ΠΈΠ· Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ ASCII ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ символ Unicode (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ∞) ΠΈΠ»ΠΈ эквивалСнтная ΡΠΊΡ€Π°Π½ΠΈΡ€ΡƒΡŽΡ‰Π°Ρ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, \u221e). Π’Ρ‹Π±ΠΎΡ€ отдаСтся Π² ΠΏΠΎΠ»ΡŒΠ·Ρƒ Ρ‚Π΅Ρ… символов, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π΄Π΅Π»Π°ΡŽΡ‚ ΠΊΠΎΠ΄ Π±ΠΎΠ»Π΅Π΅ понятным ΠΈ Ρ‡ΠΈΡ‚Π°Π΅ΠΌΡ‹ΠΌ.

    ΠŸΡ€ΠΈ использовании символов экранирования Π² ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ΅ Unicode ΠΈ Π² Ρ‚Π΅Ρ… случаях, ΠΊΠΎΠ³Π΄Π° ΠΏΡ€ΠΈΠΌΠ΅Π½ΡΡŽΡ‚ΡΡ Π΄Π΅ΠΉΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠ΅ символы Unicode, ΡƒΠ±Π΅Π΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄ΡƒΠ΅ΠΌ Ρ‚Π°ΠΊΠΎΠΉ ΠΊΠΎΠ΄ ΡΠΎΠΏΡ€ΠΎΠ²ΠΎΠΆΠ΄Π°Ρ‚ΡŒ ΠΎΠ±ΡŠΡΡΠ½ΡΡŽΡ‰ΠΈΠΌΠΈ коммСнтариями

    ΠŸΡ€ΠΈΠΌΠ΅Ρ€ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅
    String unitAbbrev = «ΞΌs»ΠžΡ‚Π»ΠΈΡ‡Π½ΠΎ: прСкрасно воспринимаСтся Π΄Π°ΠΆΠ΅ Π±Π΅Π· коммСнтария
    String unitAbbrev = «\u03bcs» // «ΞΌs»Π”опускаСтся, Π½ΠΎ Π½Π΅Ρ‚ ΠΏΡ€ΠΈΡ‡ΠΈΠ½ Ρ‚Π°ΠΊ Π΄Π΅Π»Π°Ρ‚ΡŒ
    String unitAbbrev = «\u03bcs» // ГрСчСская Π±ΡƒΠΊΠ²Π° mu, Β«s»ДопускаСтся, Π½ΠΎ Π½Π΅ΡƒΠΊΠ»ΡŽΠΆΠ΅ ΠΈ ΠΌΠΎΠΆΠ΅Ρ‚ привСсти ΠΊ ошибкам
    String unitAbbrev = «\u03bcs»ΠŸΠ»ΠΎΡ…ΠΎ: Ρ‡ΠΈΡ‚Π°ΡŽΡ‰ΠΈΠΉ понятия Π½Π΅ ΠΈΠΌΠ΅Π΅Ρ‚, Ρ‡Ρ‚ΠΎ это Ρ‚Π°ΠΊΠΎΠ΅
    return ‘\ufeff’ + content // Π·Π½Π°ΠΊ порядка Π±Π°ΠΉΡ‚ΠΎΠ²Π₯ΠΎΡ€ΠΎΡˆΠΎ: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ экранированиС для Π½Π΅ΠΏΠ΅Ρ‡Π°Ρ‚Π°Π΅ΠΌΡ‹Ρ… символов ΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ ΠΏΡ€ΠΈ нСобходимости

    Никогда Π½Π΅ Π΄Π΅Π»Π°ΠΉΡ‚Π΅ ваш ΠΊΠΎΠ΄ ΠΌΠ΅Π½Π΅Π΅ Ρ‡ΠΈΡ‚Π°Π΅ΠΌΡ‹ΠΌ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΈΠ· опасСния, Ρ‡Ρ‚ΠΎ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ Π½Π΅ смогут ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ символы Π½Π΅ ΠΈΠ· Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ ASCII. Если Ρ‚Π°ΠΊΠΎΠ΅ происходит, Ρ‚Π°ΠΊΠΈΠ΅ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ Ρ€Π°Π±ΠΎΡ‚Π°ΡŽΡ‚ Π½Π΅Π²Π΅Ρ€Π½ΠΎ ΠΈ ΠΈΡ… Π½ΡƒΠΆΠ½ΠΎ ΠΈΡΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ

    3. Π‘Ρ‚Ρ€ΡƒΠΊΡ‚ΡƒΡ€Π° исходного Ρ„Π°ΠΉΠ»Π°

    Π˜ΡΡ…ΠΎΠ΄Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ» состоит ΠΈΠ· ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… элСмСнтов (Π² ΡƒΠΊΠ°Π·Π°Π½Π½ΠΎΠΌ порядкС):

    3.1 Π˜Π½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡ ΠΎ Π»ΠΈΡ†Π΅Π½Π·ΠΈΠΈ ΠΈΠ»ΠΈ авторских ΠΏΡ€Π°Π²Π°Ρ…, Ссли имССтся

    Π˜Π½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡ ΠΎ Π»ΠΈΡ†Π΅Π½Π·ΠΈΠΈ ΠΈΠ»ΠΈ авторских ΠΏΡ€Π°Π²Π°Ρ… Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·ΠΌΠ΅Ρ‰Π΅Π½Π° Π² Ρ‚ΠΎΠΌ Ρ„Π°ΠΉΠ»Π΅, ΠΊ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌΡƒ ΠΎΠ½Π° относится.

    3.2 ОбъявлСниС ΠΏΠ°ΠΊΠ΅Ρ‚Π°

    ΠŸΠ°ΠΊΠ΅Ρ‚ ΠΎΠ±ΡŠΡΠ²Π»ΡΠ΅Ρ‚ΡΡ Π±Π΅Π· пСрСноса строки. ΠžΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠ΅ Π½Π° ΡˆΠΈΡ€ΠΈΠ½Ρƒ строки (Π Π°Π·Π΄Π΅Π» 4.4) Π½Π° объявлСниС ΠΏΠ°ΠΊΠ΅Ρ‚Π° Π½Π΅ распространяСтся.

    3.3 ОбъявлСния ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΎΠ²

    3.3.1 Π‘ΠΈΠΌΠ²ΠΎΠ» подстановки ΠΏΡ€ΠΈ объявлСнии ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΎΠ²

    Π‘ΠΈΠΌΠ²ΠΎΠ» * (подстановки) ΠΏΡ€ΠΈ объявлСнии ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΎΠ², статичСских ΠΈΠ»ΠΈ Π½Π΅Ρ‚, Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ.

    3.3.2 ΠŸΠ΅Ρ€Π΅Π½ΠΎΡ строки

    Π˜ΠΌΠΏΠΎΡ€Ρ‚Ρ‹ ΠΎΠ±ΡŠΡΠ²Π»ΡΡŽΡ‚ΡΡ Π±Π΅Π· пСрСноса строки. ΠžΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠ΅ Π½Π° ΡˆΠΈΡ€ΠΈΠ½Ρƒ строки Π½Π° Π½ΠΈΡ… Π½Π΅ распространяСтся.

    3.3.3 УпорядочиваниС ΠΈ ΠΈΠ½Ρ‚Π΅Ρ€Π²Π°Π»

    Π˜ΠΌΠΏΠΎΡ€Ρ‚Ρ‹ ΡƒΠΏΠΎΡ€ΡΠ΄ΠΎΡ‡ΠΈΠ²Π°ΡŽΡ‚ΡΡ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ:

    Π’Π½ΡƒΡ‚Ρ€ΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Π±Π»ΠΎΠΊΠ° ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠ΅ΠΌΡ‹Π΅ классы ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ Π² порядкС сортировки ASCII-символов.

    3.3.4 БтатичСский ΠΈΠΌΠΏΠΎΡ€Ρ‚ Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Ρ… классов

    БтатичСский ΠΈΠΌΠΏΠΎΡ€Ρ‚ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ для статичСских Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Ρ… классов. Π’Π°ΠΊΠΈΠ΅ классы ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ΡΡ с объявлСниСм ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠ³ΠΎ ΠΈΠΌΠΏΠΎΡ€Ρ‚Π°.

    3.4 ОбъявлСниС класса

    3.4.1 ΠžΠ±ΡŠΡΠ²Π»ΡΠ΅Ρ‚ΡΡ Ρ€ΠΎΠ²Π½ΠΎ ΠΎΠ΄ΠΈΠ½ класс Π²Π΅Ρ€Ρ…Π½Π΅Π³ΠΎ уровня

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ класс Π²Π΅Ρ€Ρ…Π½Π΅Π³ΠΎ уровня располагаСтся Π² своСм исходном Ρ„Π°ΠΉΠ»Π΅.

    3.4.2 УпорядочиваниС содСрТимого класса

    ΠŸΠΎΡ€ΡΠ΄ΠΎΠΊ, Π²Ρ‹Π±ΠΈΡ€Π°Π΅ΠΌΡ‹ΠΉ ΠΏΡ€ΠΈ располоТСнии Ρ‡Π»Π΅Π½ΠΎΠ² ΠΈ Π±Π»ΠΎΠΊΠΎΠ² ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ класса, ΠΌΠΎΠΆΠ΅Ρ‚ ΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ большоС влияниС Π½Π° Π»Π΅Π³ΠΊΠΎΡΡ‚ΡŒ понимания ΠΊΠΎΠ΄Π°. Π’Π°ΠΊ ΠΈΠ»ΠΈ ΠΈΠ½Π°Ρ‡Π΅, для этого Π½Π΅ сущСствуСт простого ΠΈ ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎΠ³ΠΎ Ρ€Π΅Ρ†Π΅ΠΏΡ‚Π°; Ρ€Π°Π·Π½Ρ‹Π΅ классы ΠΌΠΎΠ³ΡƒΡ‚ ΡƒΠΏΠΎΡ€ΡΠ΄ΠΎΡ‡ΠΈΠ²Π°Ρ‚ΡŒ своС содСрТимоС ΠΏΠΎ-Ρ€Π°Π·Π½ΠΎΠΌΡƒ.

    Π’Π°ΠΆΠ½ΠΎ Ρ‚ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Ρƒ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ класса Π±Ρ‹Π» Ρ‚Π°ΠΊΠΎΠΉ логичСский порядок располоТСния содСрТимого, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΏΠΎΠ·Π²ΠΎΠ»ΠΈΠ» Π±Ρ‹ программисту, Ρ‡ΠΈΡ‚Π°ΡŽΡ‰Π΅ΠΌΡƒ ΠΊΠΎΠ΄, ΠΎΠ±ΡŠΡΡΠ½ΠΈΡ‚ΡŒ Π΅Π³ΠΎ.

    3.4.2.1 ΠŸΠ΅Ρ€Π΅Π³Ρ€ΡƒΠΆΠ΅Π½Π½Ρ‹ΠΉ ΠΊΠΎΠ΄ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·Π΄Π΅Π»Π΅Π½

    Когда Ρƒ класса Π΅ΡΡ‚ΡŒ нСсколько конструкторов ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² с ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ ΠΈΠΌΠ΅Π½Π΅ΠΌ, ΠΎΠ½ΠΈ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Ρ€Π°ΡΠΏΠΎΠ»Π°Π³Π°Ρ‚ΡŒΡΡ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ, Π±Π΅Π· вставок Π΄Ρ€ΡƒΠ³ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° ΠΌΠ΅ΠΆΠ΄Ρƒ Π½ΠΈΠΌΠΈ.

    4. Π€ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅

    ВСрминология

    Π’Π΅Π»ΠΎ класса, ΠΌΠ΅Ρ‚ΠΎΠ΄Π° ΠΈΠ»ΠΈ конструктора относится ΠΊ Π±Π»ΠΎΡ‡Π½ΠΎΠΉ конструкции.

    ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ согласно Π Π°Π·Π΄Π΅Π»Ρƒ 4.8.3.1, любой ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€ массива Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ Ρ€Π°ΡΡΠΌΠ°Ρ‚Ρ€ΠΈΠ²Π°Ρ‚ΡŒΡΡ ΠΊΠ°ΠΊ блочная конструкция.

    4.1 Π€ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки

    4.1.1 Π€ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ Π²Π΅Π·Π΄Π΅, Π³Π΄Π΅ ΠΎΠ½ΠΈ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Π½Ρ‹

    Π€ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ Π² if, else, for, while ΠΈ do-while, Π΄Π°ΠΆΠ΅ Ссли Ρ‚Π΅Π»ΠΎ выраТСния пустоС ΠΈΠ»ΠΈ содСрТит лишь ΠΎΠ΄Π½Ρƒ строку ΠΊΠΎΠ΄Π°.

    4.1.2 НСпустыС Π±Π»ΠΎΠΊΠΈ: ΡΡ‚ΠΈΠ»ΡŒ K & R

    Π€ΠΈΠ³ΡƒΡ€Π½Ρ‹Π΅ скобки ставятся согласно ΡΡ‚ΠΈΠ»ΡŽ ΠšΠ΅Ρ€Π½ΠΈΠ³Π°Π½Π° ΠΈ Π ΠΈΡ‚Ρ‡ΠΈ («ЕгипСтскиС скобки») для нСпустых Π±Π»ΠΎΠΊΠΎΠ² ΠΈ Π±Π»ΠΎΡ‡Π½Ρ‹Ρ… конструкций (для наглядности ΠΌΡ‹ Ρ€Π΅ΡˆΠΈΠ»ΠΈ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π½Π΅ΠΌΠ½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π°, Π΄Π΅ΠΌΠΎΠ½ΡΡ‚Ρ€ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ Π΄Π°Π½Π½Ρ‹Π΅ ΠΏΡ€Π°Π²ΠΈΠ»Π° β€” ΠΏΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄Ρ‡ΠΈΠΊΠ°):

    НСкоторыС ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ для пСрСчислСний ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½Ρ‹ Π² Π Π°Π·Π΄Π΅Π»Π΅ 4.8.1

    4.1.3 ΠŸΡƒΡΡ‚Ρ‹Π΅ Π±Π»ΠΎΠΊΠΈ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ сТатыми

    ΠŸΡƒΡΡ‚ΠΎΠΉ Π±Π»ΠΎΠΊ ΠΈΠ»ΠΈ пустая блочная конструкция ΠΌΠΎΠΆΠ΅Ρ‚ ΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚ΡŒ ΡΡ‚ΠΈΠ»ΡŽ K & R (ΠΊΠ°ΠΊ описано Π² Π Π°Π·Π΄Π΅Π»Π΅ 4.1.2). Π’Π°ΠΊΠΆΠ΅ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Ρ‚Π°ΠΊΠΎΠΉ Π±Π»ΠΎΠΊ Π±Ρ‹Π» Π·Π°ΠΊΡ€Ρ‹Ρ‚ сразу ΠΆΠ΅ послС открытия, Π±Π΅Π· символов ΠΈΠ»ΠΈ Ρ€Π°Π·Ρ€Ρ‹Π²Π° строки Π²Π½ΡƒΡ‚Ρ€ΠΈ <>. Π­Ρ‚ΠΎ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ Π½Π΅ относится ΠΊ ΡΠ»ΡƒΡ‡Π°ΡŽ, ΠΊΠΎΠ³Π΄Π° Π±Π»ΠΎΠΊ являСтся Ρ‡Π°ΡΡ‚ΡŒΡŽ ΠΌΠ½ΠΎΠ³ΠΎΠ±Π»ΠΎΡ‡Π½ΠΎΠ³ΠΎ выраТСния, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ содСрТит if-else ΠΈΠ»ΠΈ try-catch-finally.

    4.2 Π”Π²Π° ΠΏΡ€ΠΎΠ±Π΅Π»Π° для отступа

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ€Π°Π·, ΠΊΠΎΠ³Π΄Π° открываСтся Π½ΠΎΠ²Ρ‹ΠΉ Π±Π»ΠΎΠΊ ΠΈΠ»ΠΈ блочная конструкция, смСщСниС Π²ΠΏΡ€Π°Π²ΠΎ увСличиваСтся Π½Π° Π΄Π²Π° ΠΏΡ€ΠΎΠ±Π΅Π»Π°. Когда Π±Π»ΠΎΠΊ заканчиваСтся, Π½Π°Ρ‡Π°Π»ΠΎ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ строки ΠΊΠΎΠ΄Π° смСщаСтся Π½Π° ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠΉ ΡƒΡ€ΠΎΠ²Π΅Π½ΡŒ смСщСния. Π£Ρ€ΠΎΠ²Π΅Π½ΡŒ смСщСния примСняСтся ΠΊΠ°ΠΊ ΠΊ Π±Π»ΠΎΠΊΡƒ, Ρ‚Π°ΠΊ ΠΈ ΠΊ коммСнтариям Π² этом Π±Π»ΠΎΠΊΠ΅ (см. ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π² Π Π°Π·Π΄Π΅Π»Π΅ 4.1.2).

    4.3 Одно Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π½Π° ΠΊΠ°ΠΆΠ΄ΡƒΡŽ строку

    КаТдоС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅Ρ‚ΡΡ ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄ΠΎΠΌ Π½Π° Π½ΠΎΠ²ΡƒΡŽ строку.

    4.4 ΠžΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠ΅ ΡˆΠΈΡ€ΠΈΠ½Ρ‹ строки Π² 100 символов

    Java-ΠΊΠΎΠ΄ ΠΈΠΌΠ΅Π΅Ρ‚ ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠ΅ Π² 100 символов ΠΏΠΎ ΡˆΠΈΡ€ΠΈΠ½Π΅ строки. Под «символом» понимаСтся любой ΠΈΠ· элСмСнтов Unicode. Π—Π° ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ случаСв, описанных Π½ΠΈΠΆΠ΅, каТдая строка с ΠΏΡ€Π΅Π²Ρ‹ΡˆΠ΅Π½ΠΈΠ΅ΠΌ ограничСния ΠΏΠΎ ΡˆΠΈΡ€ΠΈΠ½Π΅, Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ пСрСнСсСна Ρ‚Π°ΠΊ, ΠΊΠ°ΠΊ это объяснСно Π² Π Π°Π·Π΄Π΅Π»Π΅ 4.5.

    4.5 ΠŸΠ΅Ρ€Π΅Π½ΠΎΡ строки

    ВСрминология

    Когда ΠΊΠΎΠ΄, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π² Π΄Ρ€ΡƒΠ³ΠΎΠΌ случаС ΠΌΠΎΠ³ Π±Ρ‹ Π±Ρ‹Ρ‚ΡŒ располоТСн Π½Π° ΠΎΠ΄Π½ΠΎΠΉ строкС, раздСляСтся Π½Π° нСсколько строк, это явлСниС называСтся пСрСносом строки.

    НС сущСствуСт общСпринятой ΠΎΠ΄Π½ΠΎΠ·Π½Π°Ρ‡Π½ΠΎΠΉ Ρ„ΠΎΡ€ΠΌΡƒΠ»Ρ‹, ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‰Π΅ΠΉ, ΠΊΠ°ΠΊ ΠΈΠΌΠ΅Π½Π½ΠΎ Π½Π°Π΄ΠΎ Π΄Π΅Π»Π°Ρ‚ΡŒ пСрСнос строки Π² ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ситуации. ΠžΡ‡Π΅Π½ΡŒ часто сущСствуСт нСсколько способов пСрСноса строки с ΠΎΠ΄Π½ΠΈΠΌ ΠΈ Ρ‚Π΅ΠΌ ΠΆΠ΅ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚ΠΎΠΌ ΠΊΠΎΠ΄Π°.

    ΠžΠ±Ρ‹Ρ‡Π½ΠΎ пСрСнос дСлаСтся Π²ΠΎ ΠΈΠ·Π±Π΅ΠΆΠ°Π½ΠΈΠ΅ пСрСполнСния строки ΠΏΠΎ ΡˆΠΈΡ€ΠΈΠ½Π΅. Но Π΄Π°ΠΆΠ΅ Ссли ΠΊΠΎΠ΄ остался Π±Ρ‹ Π² ΠΏΡ€Π΅Π΄Π΅Π»Π°Ρ… Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½Π½ΠΎΠΉ ΡˆΠΈΡ€ΠΈΠ½Ρ‹, Ρ‚ΠΎ ΠΈ ΠΎΠ½, ΠΏΠΎ Ρ€Π΅ΡˆΠ΅Π½ΠΈΡŽ Π°Π²Ρ‚ΠΎΡ€Π°, ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ пСрСнСсСн Π½Π° Π½ΠΎΠ²ΡƒΡŽ строку.

    Π’Ρ‹Π΄Π΅Π»Π΅Π½ΠΈΠ΅ Π²ΡΠΏΠΎΠΌΠΎΠ³Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° ΠΈΠ»ΠΈ локальной ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΠΌΠΎΠΆΠ΅Ρ‚ Ρ€Π΅ΡˆΠΈΡ‚ΡŒ ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡƒ пСрСполнСния строки ΠΏΠΎ ΡˆΠΈΡ€ΠΈΠ½Π΅ Π±Π΅Π· пСрСноса ΠΊΠΎΠ΄Π°

    4.5.1 Π“Π΄Π΅ Π΄Π΅Π»Π°Ρ‚ΡŒ пСрСнос

    ΠŸΠ΅Ρ€Π²ΠΎΠ΅ ΡƒΠΊΠ°Π·Π°Π½ΠΈΠ΅ ΠΏΠΎ пСрСносу строки гласит: ΠΏΡ€Π΅Π΄ΠΏΠΎΡ‡Ρ‚ΠΈΡ‚Π΅Π»ΡŒΠ½Π΅Π΅ Π΄Π΅Π»Π°Ρ‚ΡŒ пСрСнос Π½Π° Π±ΠΎΠ»Π΅Π΅ высоком синтаксичСском ΡƒΡ€ΠΎΠ²Π½Π΅. Π’Π°ΠΊΠΆΠ΅:

    1. Когда строка разрываСтся Π½Π΅ Π½Π° ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π΅ присваивания, Ρ€Π°Π·Ρ€Ρ‹Π² дСлаСтся ΠΏΠ΅Ρ€Π΅Π΄ символом.

    Π­Ρ‚ΠΎ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ Ρ‚Π°ΠΊΠΆΠ΅ ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠΌΠΎ ΠΊ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΌ Β«ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΏΠΎΠ΄ΠΎΠ±Π½Ρ‹ΠΌΒ» символам:

    Π­Ρ‚ΠΎ Ρ‚Π°ΠΊΠΆΠ΅ ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠΌΠΎ ΠΊ Π΄Π²ΠΎΠ΅Ρ‚ΠΎΡ‡ΠΈΡŽ для Ρ†ΠΈΠΊΠ»Π° for-each.

    3. Имя ΠΌΠ΅Ρ‚ΠΎΠ΄Π° ΠΈΠ»ΠΈ конструктора ΠΏΡ€ΠΈ пСрСносС строки остаСтся присоСдинСнным ΠΊ ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰Π΅ΠΉ скобкС Β«(Β»

    4. Запятая Β«,Β» ΠΏΡ€ΠΈ пСрСносС строки остаСтся с элСмСнтом, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π΅ΠΉ ΠΏΡ€Π΅Π΄ΡˆΠ΅ΡΡ‚Π²ΡƒΠ΅Ρ‚

    5. Π‘Ρ‚Ρ€ΠΎΠΊΠ° Π½ΠΈΠΊΠΎΠ³Π΄Π° Π½Π΅ пСрСносится нСпосрСдствСнно Ρƒ стрСлки лямбда-выраТСния, ΠΊΡ€ΠΎΠΌΠ΅ случаСв, ΠΊΠΎΠ³Π΄Π° Π΅Π³ΠΎ Ρ‚Π΅Π»ΠΎ состоит ΠΈΠ· ΠΎΠ΄Π½ΠΎΠ³ΠΎ выраТСния Π±Π΅Π· Ρ„ΠΈΠ³ΡƒΡ€Π½Ρ‹Ρ… скобок:

    Главная Ρ†Π΅Π»ΡŒ пСрСноса строки β€” Π΄ΠΎΠ±ΠΈΡ‚ΡŒΡΡ ясности ΠΊΠΎΠ΄Π°, Π½ΠΎ Π½Π΅ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ наимСньшСго количСства строк

    4.5.2 Π‘ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅ продолТСния строки Π½Π° 4 ΠΈ Π±ΠΎΠ»Π΅Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ²

    ΠŸΡ€ΠΈ пСрСносС строки каТдая ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π°Ρ Π΅Π΅ подстрока (ΠΊΠ°ΠΆΠ΄ΠΎΠ΅ ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΈΠ΅ строки) смСщаСтся ΠΊΠ°ΠΊ ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌ Π½Π° 4 ΠΏΡ€ΠΎΠ±Π΅Π»Π° ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΉ.

    Когда ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΈΠΉ строки нСсколько, смСщСниС ΠΌΠΎΠΆΠ΅Ρ‚ Π²Π°Ρ€ΡŒΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² ΠΏΡ€Π΅Π΄Π΅Π»Π°Ρ… 4 ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² ΠΏΠΎ ТСланию Π°Π²Ρ‚ΠΎΡ€Π°. По ΠΎΠ±Ρ‰Π΅ΠΌΡƒ ΠΏΡ€Π°Π²ΠΈΠ»Ρƒ, Π΄Π²Π° продолТСния строки ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΠΌΠ΅Ρ‚ΡŒ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΠΎΠ΅ смСщСниС Ρ‚ΠΎΠ³Π΄Π° ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρ‚ΠΎΠ³Π΄Π°, ΠΊΠΎΠ³Π΄Π° ΠΎΠ½ΠΈ Π½Π°Ρ‡ΠΈΠ½Π°ΡŽΡ‚ΡΡ с синтаксичСски ΠΏΠ°Ρ€Π°Π»Π»Π΅Π»ΡŒΠ½Ρ‹Ρ… элСмСнтов.

    Π’ Π Π°Π·Π΄Π΅Π»Π΅ 4.6.3 Π΄Π°ΡŽΡ‚ΡΡ указания ΠΏΠΎ использованию Ρ€Π°Π·Π»ΠΈΡ‡Π½ΠΎΠ³ΠΎ количСства ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² для выравнивания элСмСнтов ΠΊΠΎΠ΄Π° ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΡ… строк.

    4.6 ΠŸΡ€ΠΎΠ±Π΅Π»Ρ‹ ΠΈ отступы

    4.6.1 ΠžΡ‚ΡΡ‚ΡƒΠΏΡ‹

    Одна пустая строка всСгда ставится:

    1. ΠœΠ΅ΠΆΠ΄Ρƒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΌΠΈ Π΄Ρ€ΡƒΠ³ Π·Π° Π΄Ρ€ΡƒΠ³ΠΎΠΌ Ρ‡Π»Π΅Π½Π°ΠΌΠΈ ΠΈΠ»ΠΈ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Π°ΠΌΠΈ класса: полями, конструкторами, ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌΠΈ, Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹ΠΌΠΈ классами, статичСскими ΠΈ динамичСскими Π±Π»ΠΎΠΊΠ°ΠΌΠΈ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ

    ΠŸΡƒΡΡ‚Π°Ρ строка Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ использована повсСмСстно для ΠΏΠΎΠ²Ρ‹ΡˆΠ΅Π½ΠΈΡ читаСмости ΠΊΠΎΠ΄Π°, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ΠΌΠ΅ΠΆΠ΄Ρƒ выраТСниями для ΠΎΡ€Π³Π°Π½ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΊΠΎΠ΄Π° Π² логичСскиС ΠΏΠΎΠ΄Ρ€Π°Π·Π΄Π΅Π»Ρ‹. ΠŸΡƒΡΡ‚Π°Ρ строка ΠΏΠ΅Ρ€Π΅Π΄ ΠΏΠ΅Ρ€Π²Ρ‹ΠΌ Ρ‡Π»Π΅Π½ΠΎΠΌ класса, ΠΈΠ»ΠΈ Π±Π»ΠΎΠΊΠΎΠΌ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ, ΠΈΠ»ΠΈ послС послСднСго Ρ‡Π»Π΅Π½Π°, ΠΈΠ»ΠΈ Π±Π»ΠΎΠΊΠ° ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ класса Π½Π΅ привСтствуСтся, Π½ΠΎ ΠΈ Π½Π΅ возбраняСтся.

    НСсколько ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… пустых строк Π΄Π΅Π»Π°Ρ‚ΡŒ Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ΡΡ, Π½ΠΎ это Π½Π΅ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΈ Π½Π΅ привСтствуСтся.

    4.6.2 ΠŸΡ€ΠΎΠ±Π΅Π»Ρ‹

    Помимо Ρ‚Ρ€Π΅Π±ΠΎΠ²Π°Π½ΠΈΠΉ самого языка ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΡ‡ΠΈΡ… ΠΏΡ€Π°Π²ΠΈΠ» Π΄Π°Π½Π½ΠΎΠ³ΠΎ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°, Π° Ρ‚Π°ΠΊΠΆΠ΅ Π½Π΅ считая Π»ΠΈΡ‚Π΅Ρ€Π°Π»ΠΎΠ² ΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² (Π² Ρ‚.Ρ‡. Javadoc), ΠΎΠ΄ΠΈΠ½ΠΎΡ‡Π½Ρ‹Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»Ρ‹ ΠΈΠ· Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ ASCII ΠΌΠΎΠ³ΡƒΡ‚ ΠΏΡ€ΠΈΡΡƒΡ‚ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΡ… мСстах:

    1. ΠŸΡ€ΠΈ Ρ€Π°Π·Π΄Π΅Π»Π΅Π½ΠΈΠΈ любого Π·Π°Ρ€Π΅Π·Π΅Ρ€Π²ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ слова, Ρ‚Π°ΠΊΠΎΠ³ΠΎ ΠΊΠ°ΠΊ if, for ΠΈΠ»ΠΈ catch, ΠΈ ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰Π΅ΠΉ ΠΊΡ€ΡƒΠ³Π»ΠΎΠΉ скобки Β«(Β», которая слСдуСт Π·Π° Π½ΠΈΠΌ

    2. ΠŸΡ€ΠΈ Ρ€Π°Π·Π΄Π΅Π»Π΅Π½ΠΈΠΈ любого Π·Π°Ρ€Π΅Π·Π΅Ρ€Π²ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ слова, Ρ‚Π°ΠΊΠΎΠ³ΠΎ ΠΊΠ°ΠΊ else ΠΈΠ»ΠΈ catch, ΠΈ Π·Π°ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰Π΅ΠΉ Ρ„ΠΈΠ³ΡƒΡ€Π½ΠΎΠΉ скобки Β«>Β», которая слСдуСт Π·Π° Π½ΠΈΠΌ

    3. ΠŸΠ΅Ρ€Π΅Π΄ любой ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‰Π΅ΠΉ Ρ„ΠΈΠ³ΡƒΡ€Π½ΠΎΠΉ скобкой Β«<Β», Π·Π° ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ Π΄Π²ΡƒΡ… ситуаций:

    Π­Ρ‚ΠΎ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ Ρ‚Π°ΠΊΠΆΠ΅ ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠΌΠΎ ΠΊ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΌ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π°ΠΌ:

    6. По ΠΎΠ±Π΅ стороны ΠΎΡ‚ Π΄Π²ΠΎΠΉΠ½ΠΎΠΉ косой Ρ‡Π΅Ρ€Ρ‚Ρ‹ Β«//Β» ΠΏΡ€ΠΈ создании коммСнтария Π² Ρ‚ΠΎΠΉ ΠΆΠ΅ строкС ΠΊΠΎΠ΄Π°. Π—Π΄Π΅ΡΡŒ Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½Ρ‹, Π½ΠΎ Π½Π΅ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡ‹ нСсколько ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ²

    7. ΠœΠ΅ΠΆΠ΄Ρƒ объявлСниСм Ρ‚ΠΈΠΏΠ° ΠΈ ΠΈΠΌΠ΅Π½Π΅ΠΌ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ:
    8. ΠžΠΏΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎ: Π²Π½ΡƒΡ‚Ρ€ΠΈ скобок ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Π° массива
    new int[] <5, 6>ΠΈ new int[] < 5, 6 >β€” ΠΎΠ±Π° Π²Π°Ρ€ΠΈΠ°Π½Ρ‚Π° Π²Π΅Ρ€Π½Ρ‹Π΅

    9. ΠœΠ΅ΠΆΠ΄Ρƒ Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠ΅ΠΉ Ρ‚ΠΈΠΏΠ° ΠΈ [] или…

    Π­Ρ‚ΠΎ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ Π½Π΅ Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ наличия ΠΈΠ»ΠΈ отсутствия ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² Π² Π½Π°Ρ‡Π°Π»Π΅ ΠΈΠ»ΠΈ ΠΊΠΎΠ½Ρ†Π΅ строки; ΠΎΠ½ΠΎ относится лишь ΠΊ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΌ ΠΏΡ€ΠΎΠ±Π΅Π»Π°ΠΌ.

    4.6.3 Π“ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½ΠΎΠ΅ Π²Ρ‹Ρ€Π°Π²Π½ΠΈΠ²Π°Π½ΠΈΠ΅ Π½Π΅ трСбуСтся Π½ΠΈΠΊΠΎΠ³Π΄Π°

    ВСрминология

    Π“ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½ΠΎΠ΅ Π²Ρ‹Ρ€Π°Π²Π½ΠΈΠ²Π°Π½ΠΈΠ΅ β€” это ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ° добавлСния Ρ€Π°Π·Π»ΠΈΡ‡Π½ΠΎΠ³ΠΎ числа Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² Π² вашСм ΠΊΠΎΠ΄Π΅ с Ρ†Π΅Π»ΡŒΡŽ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Ρ‚Π°ΠΊ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½Ρ‹Π΅ элСмСнты Π±Ρ‹Π»ΠΈ располоТСны ΠΏΠΎΠ΄ Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ элСмСнтами с ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΉ строки.

    Π­Ρ‚Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ° Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½Π°, Π½ΠΎ Π΅Π΅ использованиС Π½Π΅ трСбуСтся Π΄Π°Π½Π½Ρ‹ΠΌ руководством. Π’Π°ΠΊΠΆΠ΅ Π½Π΅Ρ‚ нСобходимости ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Ρ‚ΡŒ соблюдСниС выравнивания Π² Ρ‚Π΅Ρ… участках ΠΊΠΎΠ΄Π°, Π³Π΄Π΅ ΠΎΠ½ΠΎ ΡƒΠΆΠ΅ Π±Ρ‹Π»ΠΎ ΠΏΡ€ΠΈΠΌΠ΅Π½Π΅Π½ΠΎ.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ€ с Π²Ρ‹Ρ€Π°Π²Π½ΠΈΠ²Π°Π½ΠΈΠ΅ΠΌ ΠΈ Π±Π΅Π· Π½Π΅Π³ΠΎ:

    Π’Ρ‹Ρ€Π°Π²Π½ΠΈΠ²Π°Π½ΠΈΠ΅ способствуСт читаСмости ΠΊΠΎΠ΄Π°, Π½ΠΎ создаСт ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡ‹ с ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΎΠΉ Ρ‚Π°ΠΊΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° Π² Π±ΡƒΠ΄ΡƒΡ‰Π΅ΠΌ. Допустим, трСбуСтся ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄Π½Ρƒ строку. Π­Ρ‚ΠΎ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΡΠΊΠ°Π·ΠΈΡ‚ΡŒ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Ρ€Π°Π½Π΅Π΅ принятого ΠΊΠΎΠ΄Π°, Ρ‡Ρ‚ΠΎ допускаСтся. Но, скорСС всСго, программист (Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, Π²Ρ‹) Π½Π°Ρ‡Π½Π΅Ρ‚ ΠΊΠΎΡ€Ρ€Π΅ΠΊΡ‚ΠΈΡ€ΠΎΠ²ΠΊΡƒ количСства ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² Π½Π° рядом стоящих строках, Ρ‡Ρ‚ΠΎ, Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, запустит Ρ†Π΅Π»ΡƒΡŽ Ρ‡Π΅Ρ€Π΅Π΄Ρƒ исправлСний. ИзмСнСниС ΠΎΠ΄Π½ΠΎΠΉ строки ΠΌΠΎΠΆΠ΅Ρ‚ Π°ΠΊΡ‚ΠΈΠ²ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Β«Π²Π·Ρ€Ρ‹Π²Π½ΡƒΡŽ Π²ΠΎΠ»Π½ΡƒΒ» ΠΈΠ· бСссмыслСнного Ρ‚Ρ€ΡƒΠ΄Π° (Π² Ρ…ΡƒΠ΄ΡˆΠ΅ΠΌ случаС). Или, Π² Π»ΡƒΡ‡ΡˆΠ΅ΠΌ случаС, ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Ρ‚ ΠΊ искаТСнию ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ Π² истории вСрсий, ΡƒΡ…ΡƒΠ΄ΡˆΠΈΡ‚ Ρ‡Ρ‚Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ΄Π° ΠΈ обострит ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚Ρ‹ слияния.

    4.7 Π“Ρ€ΡƒΠΏΠΏΠΈΡ€ΡƒΡŽΡ‰ΠΈΠ΅ скобки Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄ΠΎΠ²Π°Π½Ρ‹

    ДопускаСтся Π½Π΅ ΡΡ‚Π°Π²ΠΈΡ‚ΡŒ Π³Ρ€ΡƒΠΏΠΏΠΈΡ€ΡƒΡŽΡ‰ΠΈΠ΅ скобки Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρ‚ΠΎΠ³Π΄Π°, ΠΊΠΎΠ³Π΄Π° Π°Π²Ρ‚ΠΎΡ€ ΠΊΠΎΠ΄Π° ΠΈ Ρ€Π΅Ρ†Π΅Π½Π·Π΅Π½Ρ‚ согласны Π² Ρ‚ΠΎΠΌ, Ρ‡Ρ‚ΠΎ Π½Π΅Ρ‚ Ρ€Π°Π·ΡƒΠΌΠ½ΠΎΠΉ вСроятности, Ρ‡Ρ‚ΠΎ ΠΊΠΎΠ΄ Π±ΡƒΠ΄Π΅Ρ‚ Π½Π΅Π²Π΅Ρ€Π½ΠΎ истолкован Π±Π΅Π· скобок, ΠΈ ΠΏΡ€ΠΈ этом скобки Π½Π΅ ΠΎΠ±Π»Π΅Π³Ρ‡ΠΈΠ»ΠΈ Π±Ρ‹ Π΅Π³ΠΎ Ρ‡Ρ‚Π΅Π½ΠΈΠ΅. НСт ΠΏΡ€ΠΈΡ‡ΠΈΠ½Ρ‹ ΠΏΠΎΠ»Π°Π³Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ, ΠΊΡ‚ΠΎ Ρ‡ΠΈΡ‚Π°Π΅Ρ‚ ΠΊΠΎΠ΄, ΠΏΠΎΠΌΠ½ΠΈΡ‚ Π½Π°ΠΈΠ·ΡƒΡΡ‚ΡŒ всю Ρ‚Π°Π±Π»ΠΈΡ†Ρƒ ΠΏΡ€ΠΈΠΎΡ€ΠΈΡ‚Π΅Ρ‚ΠΎΠ² использования ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ² Java.

    4.8 ΠžΡΠΎΠ±Ρ‹Π΅ конструкции

    4.8.1 ΠšΠ»Π°ΡΡΡ‹-пСрСчислСния

    ПослС ΠΊΠ°ΠΆΠ΄ΠΎΠΉ запятой, которая слСдуСт Π·Π° константой пСрСчислСния, Ρ€Π°Π·Ρ€Ρ‹Π² строки нСобязатСлСн. Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ пустыС строки (ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄Π½Π°) Ρ‚Π°ΠΊΠΆΠ΅ Π΄ΠΎΠΏΡƒΡΠΊΠ°ΡŽΡ‚ΡΡ. Π’ΠΎΡ‚ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Ρ‚Π°ΠΊΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π°:

    Код класса-пСрСчислСния Π±Π΅Π· ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² ΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π², ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‰ΠΈΡ… Π΅Π³ΠΎ константы, ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ прСдставлСн, ΠΊΠ°ΠΊ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€ массива (см. Π Π°Π·Π΄Π΅Π» 4.8.3.1):

    Π’Π°ΠΊ ΠΊΠ°ΠΊ пСрСчислСния β€” это классы, для Π½ΠΈΡ… слСдуСт ΠΏΡ€ΠΈΠΌΠ΅Π½ΡΡ‚ΡŒ всС ΠΏΡ€ΠΎΡ‡ΠΈΠ΅ ΠΏΡ€Π°Π²ΠΈΠ»Π°, ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠΌΡ‹Π΅ ΠΊ классам.

    4.8.2 ОбъявлСния ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…

    4.8.2.1 Одна пСрСмСнная Π½Π° ΠΎΠ΄Π½ΠΎ объявлСниС

    КаТдая пСрСмСнная (ΠΏΠΎΠ»Π΅ ΠΈΠ»ΠΈ локальная) ΠΎΠ±ΡŠΡΠ²Π»ΡΠ΅Ρ‚ΡΡ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΉ Π·Π° Ρ€Π°Π·: Ρ‚Π°ΠΊΠΈΠ΅ объявлСния, ΠΊΠ°ΠΊ int a, b; Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ.

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: ΠœΠ½ΠΎΠΆΠ΅ΡΡ‚Π²Π΅Π½Π½Ρ‹Π΅ объявлСния ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… Π΄ΠΎΠΏΡƒΡΠΊΠ°ΡŽΡ‚ΡΡ Π² Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠ΅ Ρ†ΠΈΠΊΠ»Π° for.

    4.8.2.2 ΠžΠ±ΡŠΡΠ²Π»ΡΠΉΡ‚Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Ρ‚ΠΎΠ³Π΄Π°, ΠΊΠΎΠ³Π΄Π° ΠΎΠ½ΠΈ Π½ΡƒΠΆΠ½Ρ‹

    Π›ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΎΠ±ΡŠΡΠ²Π»ΡΡ‚ΡŒΡΡ Π² Π½Π°Ρ‡Π°Π»Π΅ Π±Π»ΠΎΠΊΠ° ΠΈΠ»ΠΈ Π±Π»ΠΎΡ‡Π½ΠΎΠΉ конструкции. Наоборот, Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΎΠ±ΡŠΡΠ²Π»ΡΡ‚ΡŒ нСпосрСдствСнно ΠΏΠ΅Ρ€Π΅Π΄ мСстом ΠΈΡ… ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ использования, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΌΠΈΠ½ΠΈΠΌΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΎΠ±Π»Π°ΡΡ‚ΡŒ ΠΈΡ… дСйствия. ΠžΠ±Ρ‹Ρ‡Π½ΠΎ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΡŽΡ‚ΡΡ Π² ΠΌΠΎΠΌΠ΅Π½Ρ‚ объявлСния, ΠΈΠ»ΠΈ ΠΆΠ΅ сразу послС Π½Π΅Π³ΠΎ.

    4.8.3 ΠœΠ°ΡΡΠΈΠ²Ρ‹

    4.8.3.1 Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Ρ‹ массивов ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ Β«Π±Π»ΠΎΡ‡Π½Ρ‹ΠΌΠΈΒ»

    Π›ΡŽΠ±ΠΎΠΉ массив ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ Ρ‚Π°ΠΊ, ΠΊΠ°ΠΊ Ссли Π±Ρ‹ ΠΎΠ½ Π±Ρ‹Π» Π±Π»ΠΎΡ‡Π½ΠΎΠΉ конструкциСй. К ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρƒ, вСсь ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ ΠΊΠΎΠ΄ допустим (список ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ² Π½Π΅ ΠΏΠΎΠ»Π½Ρ‹ΠΉ):

    4.8.3.2 Никаких объявлСний массивов Π² стилС языка Π‘

    ΠšΠ²Π°Π΄Ρ€Π°Ρ‚Π½Ρ‹Π΅ скобки ставятся послС Ρ‚ΠΈΠΏΠ°, Π° Π½Π΅ послС ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ: String[] args, Π° Π½Π΅ String args[].

    4.8.4 ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ switch

    ВСрминология

    Π’Π½ΡƒΡ‚Ρ€ΠΈ Π±Π»ΠΎΠΊΠ° switch располагаСтся ΠΎΠ΄Π½Π° ΠΈΠ»ΠΈ Π±ΠΎΠ»Π΅Π΅ Π³Ρ€ΡƒΠΏΠΏ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ². КаТдая Π³Ρ€ΡƒΠΏΠΏΠ° состоит ΠΈΠ· ΠΎΠ΄Π½ΠΎΠΉ ΠΈΠ»ΠΈ Π±ΠΎΠ»Π΅Π΅ ΠΌΠ΅Ρ‚ΠΎΠΊ (ΠΊΠ°ΠΊ case FOO:, Ρ‚Π°ΠΊ ΠΈ default:), Π·Π° ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌΠΈ слСдуСт ΠΎΠ΄ΠΈΠ½ ΠΈΠ»ΠΈ Π±ΠΎΠ»Π΅Π΅ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ² (ΠΈΠ»ΠΈ, Π² случаС послСднСй Π³Ρ€ΡƒΠΏΠΏΡ‹, Π½ΠΈ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ»ΠΈ Π±ΠΎΠ»Π΅Π΅).

    4.8.4.1 Π‘ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅

    Как ΠΈ Π² случаС с Π»ΡŽΠ±Ρ‹ΠΌ Π΄Ρ€ΡƒΠ³ΠΈΠΌ Π±Π»ΠΎΠΊΠΎΠΌ, содСрТимоС Π±Π»ΠΎΠΊΠ° switch смСщаСтся Π½Π° 2 ΠΏΡ€ΠΎΠ±Π΅Π»Π°.

    ПослС ΠΌΠ΅Ρ‚ΠΊΠΈ Π±Π»ΠΎΠΊΠ° switch дСлаСтся пСрСнос строки, Π° смСщСниС увСличиваСтся Π½Π° 2 ΠΏΡ€ΠΎΠ±Π΅Π»Π°, Ρ‚Π°ΠΊ ΠΆΠ΅ ΠΊΠ°ΠΊ ΠΏΡ€ΠΈ ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΠΈΠΈ Π±Π»ΠΎΠΊΠ°. КаТдая ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π°Ρ ΠΌΠ΅Ρ‚ΠΊΠ° возвращаСтся Π½Π° ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠΉ ΡƒΡ€ΠΎΠ²Π΅Π½ΡŒ смСщСния, ΠΊΠ°ΠΊ ΠΏΡ€ΠΈ Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΈΠΈ Π±Π»ΠΎΠΊΠ°.

    4.8.4.2 Π‘ΠΊΠ²ΠΎΠ·Π½ΠΎΠΉ ΠΏΡ€ΠΎΡ…ΠΎΠ΄ коммСнтируСтся

    Π’Π½ΡƒΡ‚Ρ€ΠΈ Π±Π»ΠΎΠΊΠ° каТдая Π³Ρ€ΡƒΠΏΠΏΠ° ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ² Π»ΠΈΠ±ΠΎ Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅Ρ‚ досрочно switch (с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ break, continue, return ΠΈΠ»ΠΈ выбросом ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ), Π»ΠΈΠ±ΠΎ помСчаСтся ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ±ΠΎΠ·Π½Π°Ρ‡ΠΈΡ‚ΡŒ, Ρ‡Ρ‚ΠΎ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ΄Π° Π±ΡƒΠ΄Π΅Ρ‚ ΠΈΠ»ΠΈ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΎ Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ Π³Ρ€ΡƒΠΏΠΏΠ΅. Достаточно любого коммСнтария, ΠΏΠ΅Ρ€Π΅Π΄Π°ΡŽΡ‰Π΅Π³ΠΎ идСю сквозного ΠΏΡ€ΠΎΡ…ΠΎΠ΄Π° (ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ // fall through). Π’Π°ΠΊΠΎΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π΅ трСбуСтся Π² послСднСй Π³Ρ€ΡƒΠΏΠΏΠ΅ Π±Π»ΠΎΠΊΠ° switch. ΠŸΡ€ΠΈΠΌΠ΅Ρ€:

    ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ ставится Π½Π΅ послС case 1, Π° лишь Π² ΠΊΠΎΠ½Ρ†Π΅ Π³Ρ€ΡƒΠΏΠΏΡ‹ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ².

    4.8.4.3 ВсСгда ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ default

    ΠžΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ switch Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ ΠΌΠ΅Ρ‚ΠΊΡƒ default, Π΄Π°ΠΆΠ΅ Ссли Π² Π½Π΅ΠΉ Π½Π΅ присутствуСт ΠΊΠΎΠ΄.

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: Π±Π»ΠΎΠΊ switch для Ρ‚ΠΈΠΏΠ° enum ΠΌΠΎΠΆΠ΅Ρ‚ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ default, Ссли ΠΎΠ½ содСрТит явныС случаи, ΠΎΡ…Π²Π°Ρ‚Ρ‹Π²Π°ΡŽΡ‰ΠΈΠ΅ всС Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹Π΅ значСния этого Ρ‚ΠΈΠΏΠ°. Π­Ρ‚ΠΎ позволяСт срСдС Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈΠ»ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΠΌ инструмСнтам статичСского Π°Π½Π°Π»ΠΈΠ·Π° Π²Ρ‹Π΄Π°Π²Π°Ρ‚ΡŒ ΠΏΡ€Π΅Π΄ΡƒΠΏΡ€Π΅ΠΆΠ΄Π΅Π½ΠΈΠ΅ ΠΎ Ρ‚ΠΎΠΌ, Ρ‡Ρ‚ΠΎ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ случаи Π½Π΅ ΠΎΡ…Π²Π°Ρ‡Π΅Π½Ρ‹.

    4.8.5 Аннотации

    Аннотации, примСняСмыС ΠΊ классу, ΠΌΠ΅Ρ‚ΠΎΠ΄Ρƒ ΠΈΠ»ΠΈ конструктору, ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ нСпосрСдствСнно послС Π±Π»ΠΎΠΊΠ° Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ. КаТдая аннотация указываСтся Π½Π° собствСнной строкС (Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΉ Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠΈ Π½Π° строку). Π­Ρ‚ΠΈ Ρ€Π°Π·Ρ€Ρ‹Π²Ρ‹ строки Π½Π΅ ΡΠ²Π»ΡΡŽΡ‚ΡΡ пСрСносами строки (см. Π Π°Π·Π΄Π΅Π» 4.5), поэтому ΡƒΡ€ΠΎΠ²Π΅Π½ΡŒ отступа Π½Π΅ увСличиваСтся. ΠŸΡ€ΠΈΠΌΠ΅Ρ€:

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: одиночная аннотация Π±Π΅Π· ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² ΠΌΠΎΠΆΠ΅Ρ‚ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Ρ‚ΡŒΡΡ вмСстС с ΠΏΠ΅Ρ€Π²ΠΎΠΉ строкой сигнатуры, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€:

    Аннотации, примСняСмыС ΠΊ полю, Ρ‚Π°ΠΊΠΆΠ΅ ΠΏΠΎΡΠ²Π»ΡΡŽΡ‚ΡΡ сразу послС Π±Π»ΠΎΠΊΠ° Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ, Π½ΠΎ Π² этом случаС нСсколько Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠΉ (Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΈΠ·ΠΎΠ²Π°Π½Π½Ρ‹Ρ…) ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ пСрСчислСны Π² ΠΎΠ΄Π½ΠΎΠΉ строкС, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€:

    НС сущСствуСт особых ΠΏΡ€Π°Π²ΠΈΠ» для форматирования Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠΉ ΠΊ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌ, Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΌ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΌ ΠΈΠ»ΠΈ Ρ‚ΠΈΠΏΠ°ΠΌ.

    4.8.6 ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ

    Π­Ρ‚ΠΎΡ‚ Ρ€Π°Π·Π΄Π΅Π» посвящСн коммСнтариям Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ. Javadoc рассматриваСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ Π² Π Π°Π·Π΄Π΅Π»Π΅ 7.

    Π›ΡŽΠ±ΠΎΠΌΡƒ Ρ€Π°Π·Ρ€Ρ‹Π²Ρƒ строки ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΡ€Π΅Π΄ΡˆΠ΅ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ»ΡŒΠ½ΠΎΠ΅ количСство ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ², Π·Π° ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ слСдуСт ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ. Π’Π°ΠΊΠΎΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π΄Π΅Π»Π°Π΅Ρ‚ строку нСпустой.

    4.8.6.1 Π‘Ρ‚ΠΈΠ»ΡŒ Π±Π»ΠΎΡ‡Π½ΠΎΠ³ΠΎ коммСнтария

    Π£Ρ€ΠΎΠ²Π΅Π½ΡŒ отступа Π±Π»ΠΎΡ‡Π½ΠΎΠ³ΠΎ коммСнтария совпадаСт с ΠΎΠΊΡ€ΡƒΠΆΠ°ΡŽΡ‰ΠΈΠΌ ΠΊΠΎΠ΄ΠΎΠΌ. Π‘Π»ΠΎΡ‡Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΠΊΠ°ΠΊ /* … */, Ρ‚Π°ΠΊ ΠΈ // … Для многострочных ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² Π²ΠΈΠ΄Π° /* … */ ΠΏΠΎΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ строки Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с символа *, Π²Ρ‹Ρ€Π°Π²Π½Π΅Π½Π½ΠΎΠ³ΠΎ с символом * с ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΉ строки.

    ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π½Π΅ Π·Π°ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‚ΡΡ Π² ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΈ, ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½Π½Ρ‹Π΅ Π·Π²Π΅Π·Π΄ΠΎΡ‡ΠΊΠ°ΠΌΠΈ ΠΈΠ»ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ символами.

    ΠŸΡ€ΠΈ написании многострочных ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΡΡ‚ΠΈΠ»ΡŒ /* … */, Ссли Ρ…ΠΎΡ‚ΠΈΡ‚Π΅, Ρ‡Ρ‚ΠΎΠ±Ρ‹ срСдства автоматичСского форматирования ΠΊΠΎΠ΄Π° Π΄Π΅Π»Π°Π»ΠΈ пСрСнос строки ΠΏΡ€ΠΈ нСобходимости (Π² стилС ΠΏΠ°Ρ€Π°Π³Ρ€Π°Ρ„ΠΎΠ²). Π‘ΠΎΠ»ΡŒΡˆΠΈΠ½ΡΡ‚Π²ΠΎ срСдств форматирования Π½Π΅ ΠΌΠΎΠ³ΡƒΡ‚ Π΄Π΅Π»Π°Ρ‚ΡŒ этого с Π±Π»ΠΎΠΊΠ°ΠΌΠΈ однострочных ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π² // …

    4.8.7 ΠœΠΎΠ΄ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€Ρ‹

    ΠœΠΎΠ΄ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€Ρ‹ класса ΠΈ ΠΏΠΎΠ»Π΅ΠΉ, Ссли ΠΎΠ½ΠΈ ΠΏΡ€ΠΈΡΡƒΡ‚ΡΡ‚Π²ΡƒΡŽΡ‚, ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°ΡŽΡ‚ΡΡ Π² порядкС, Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄ΠΎΠ²Π°Π½Π½ΠΎΠΌ спСцификациСй языка Java:

    4.8.8 ЧисловыС Π»ΠΈΡ‚Π΅Ρ€Π°Π»Ρ‹

    Π’ΠΈΠΏ long ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ ΠΏΡ€ΠΎΠΏΠΈΡΠ½ΡƒΡŽ Π±ΡƒΠΊΠ²Ρƒ L, Π° Π½Π΅ ΡΡ‚Ρ€ΠΎΡ‡Π½ΡƒΡŽ (Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π½Π΅ ΠΏΠ΅Ρ€Π΅ΠΏΡƒΡ‚Π°Ρ‚ΡŒ с Ρ†ΠΈΡ„Ρ€ΠΎΠΉ 1). НапримСр, 300_000_000L вмСсто 300_000_000l.

    5. ИмСнованиС

    5.1 ΠžΠ±Ρ‰ΠΈΠ΅ ΠΏΡ€Π°Π²ΠΈΠ»Π° для всСх ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ΠΎΠ²

    Π˜Π΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π±ΡƒΠΊΠ²Ρ‹ ΠΈ Ρ†ΠΈΡ„Ρ€Ρ‹ ASCII ΠΈ, Π² Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… ΠΎΡ‚ΠΌΠ΅Ρ‡Π΅Π½Π½Ρ‹Ρ… Π½ΠΈΠΆΠ΅ случаях, подчСркивания.

    Π’Π°ΠΊΠΈΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ, ΠΊΠ°ΠΆΠ΄ΠΎΠΌΡƒ Π΄Π΅ΠΉΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΌΡƒ ΠΈΠΌΠ΅Π½ΠΈ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€Π° соотвСтствуСт рСгулярноС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ \w+ (Π±ΡƒΠΊΠ²Π΅Π½Π½ΠΎ-Ρ†ΠΈΡ„Ρ€ΠΎΠ²ΠΎΠΉ символ, Π²ΡΡ‚Ρ€Π΅Ρ‡Π°ΡŽΡ‰ΠΈΠΉΡΡ ΠΎΠ΄ΠΈΠ½ ΠΈΠ»ΠΈ Π±ΠΎΠ»Π΅Π΅ Ρ€Π°Π·).

    Π‘Ρ‚ΠΈΠ»ΡŽ Π΄Π°Π½Π½ΠΎΠ³ΠΎ руководства Π½Π΅ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‚ ΠΈΠΌΠ΅Π½Π°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‰ΠΈΠ΅ ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅ суффиксы ΠΈΠ»ΠΈ прСфиксы, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€: name_, mName, s_name ΠΈΠ»ΠΈ kName.

    5.2 ΠŸΡ€Π°Π²ΠΈΠ»Π° для Ρ€Π°Π·Π½Ρ‹Ρ… Ρ‚ΠΈΠΏΠΎΠ² ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ΠΎΠ²

    5.2.1 ИмСна ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠ²

    ИмСна ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠ² Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ записаны Π² Π½ΠΈΠΆΠ½Π΅ΠΌ рСгистрС, Π±Π΅Π· использования camelCase ΠΈΠ»ΠΈ ΠΏΠΎΠ΄Ρ‡Π΅Ρ€ΠΊΠΈΠ²Π°Π½ΠΈΠΉ.

    ΠŸΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ: com.example.deepspace
    ΠΠ΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ: com.example.deepSpace ΠΈΠ»ΠΈ com.example.deep_space

    5.2.2 ИмСна классов

    ИмСна классов ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² стилС UpperCamelCase (с Π·Π°Π³Π»Π°Π²Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π²ΠΎΠΉ Π±ΡƒΠΊΠ²ΠΎΠΉ).

    ИмСна классов ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ ΡΠ²Π»ΡΡŽΡ‚ΡΡ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΈΠ»ΠΈ словосочСтаниями с ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ. НапримСр, Character ΠΈΠ»ΠΈ ImmutableList.

    ИмСна интСрфСйсов Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΈΠ»ΠΈ словосочСтаниями с ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, List), Π½ΠΎ ΠΈΠ½ΠΎΠ³Π΄Π° ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ ΠΈ ΠΏΡ€ΠΈΠ»Π°Π³Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΈΠ»ΠΈ сочСтаниями ΠΏΡ€ΠΈΠ»Π°Π³Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Readable).

    НС сущСствуСт ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½Ρ‹Ρ… ΠΏΡ€Π°Π²ΠΈΠ» ΠΈΠ»ΠΈ Π΄Π°ΠΆΠ΅ ΡƒΡΡ‚ΠΎΡΠ²ΡˆΠΈΡ…ΡΡ соглашСний для имСнования Ρ‚ΠΈΠΏΠΎΠ² Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠΉ.

    ВСстовыС классы носят имя, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ начинаСтся с ΠΈΠΌΠ΅Π½ΠΈ класса, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΠ½ΠΈ Ρ‚Π΅ΡΡ‚ΠΈΡ€ΡƒΡŽΡ‚, ΠΈ заканчиваСтся словом Test. НапримСр, HashTest ΠΈΠ»ΠΈ HashIntegrationTest.

    5.2.3 ИмСна ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ²

    ИмСна ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² стилС lowerCamelCase.

    ИмСна ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ ΡΠ²Π»ΡΡŽΡ‚ΡΡ Π³Π»Π°Π³ΠΎΠ»Π°ΠΌΠΈ ΠΈΠ»ΠΈ словосочСтаниями с Π³Π»Π°Π³ΠΎΠ»Π°ΠΌΠΈ. НапримСр, sendMessage ΠΈΠ»ΠΈ stop.

    ΠŸΠΎΠ΄Ρ‡Π΅Ρ€ΠΊΠΈΠ²Π°Π½ΠΈΡ ΠΌΠΎΠ³ΡƒΡ‚ ΠΏΡ€ΠΈΡΡƒΡ‚ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ Π² ΠΈΠΌΠ΅Π½Π°Ρ… тСстовых ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² JUnit для раздСлСния логичСских ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ² Π² ΠΈΠΌΠ΅Π½ΠΈ. ΠŸΡ€ΠΈ этом ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΏΠΈΡˆΠ΅Ρ‚ΡΡ Π² стилС lowerCamelCase. Π’ΠΈΠΏΠΈΡ‡Π½Ρ‹ΠΌ шаблоном являСтся:

    НС сущСствуСт СдинствСнно Π²Π΅Ρ€Π½ΠΎΠ³ΠΎ ΠΏΡƒΡ‚ΠΈ Π² ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Π½ΠΈΠΈ тСстовых ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ².

    5.2.4 ИмСна констант

    ΠšΠΎΠ½ΡΡ‚Π°Π½Ρ‚Ρ‹ ΠΈΠΌΠ΅Π½ΡƒΡŽΡ‚ΡΡ Π² стилС CONSTANT_CASE: всС Π±ΡƒΠΊΠ²Ρ‹ Π² Π²Π΅Ρ€Ρ…Π½Π΅ΠΌ рСгистрС, ΠΊΠ°ΠΆΠ΄ΠΎΠ΅ слово ΠΎΡ‚Π΄Π΅Π»Π΅Π½ΠΎ ΠΎΡ‚ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅Π³ΠΎ ΠΏΠΎΠ΄Ρ‡Π΅Ρ€ΠΊΠΈΠ²Π°Π½ΠΈΠ΅ΠΌ. Но Ρ‡Ρ‚ΠΎ ΠΈΠΌΠ΅Π½Π½ΠΎ являСтся константой?

    ΠšΠΎΠ½ΡΡ‚Π°Π½Ρ‚Ρ‹ β€” это статичСскиС Ρ„ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹Π΅ поля, содСрТимоС ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… являСтся Π½Π΅ΠΈΠ·ΠΌΠ΅Π½Π½Ρ‹ΠΌ, ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π½Π΅ ΠΈΠΌΠ΅ΡŽΡ‚ Π²ΠΈΠ΄ΠΈΠΌΡ‹Ρ… ΠΏΠΎΠ±ΠΎΡ‡Π½Ρ‹Ρ… эффСктов. Π­Ρ‚ΠΎ относится ΠΊ ΠΏΡ€ΠΈΠΌΠΈΡ‚ΠΈΠ²Π°ΠΌ, String, нСизмСняСмым Ρ‚ΠΈΠΏΠ°ΠΌ ΠΈ нСизмСняСмым коллСкциям нСизмСняСмых Ρ‚ΠΈΠΏΠΎΠ². Если ΠΊΠ°ΠΊΠΎΠ΅-Π»ΠΈΠ±ΠΎ наблюдаСмоС состояниС ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒΡΡ, ΠΎΠ½ Π½Π΅ являСтся константой. ΠŸΡ€ΠΎΡΡ‚ΠΎΠ³ΠΎ намСрСния Π½ΠΈΠΊΠΎΠ³Π΄Π° Π½Π΅ ΠΈΠ·ΠΌΠ΅Π½ΡΡ‚ΡŒ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ нСдостаточно.

    ИмСна констант ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ ΡΠ²Π»ΡΡŽΡ‚ΡΡ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΈΠ»ΠΈ словосочСтаниями с ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ.

    5.2.5 ИмСна Π½Π΅ константных ΠΏΠΎΠ»Π΅ΠΉ

    ИмСна ΠΏΠΎΠ»Π΅ΠΉ, Π½Π΅ ΡΠ²Π»ΡΡŽΡ‰ΠΈΡ…ΡΡ константами (статичСских ΠΈΠ»ΠΈ Π½Π΅Ρ‚), ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² стилС lowerCamelCase.

    ИмСна Ρ‚Π°ΠΊΠΈΡ… ΠΏΠΎΠ»Π΅ΠΉ ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ ΡΠ²Π»ΡΡŽΡ‚ΡΡ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΈΠ»ΠΈ словосочСтаниями с ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ. НапримСр, computedValues ΠΈΠ»ΠΈ index.

    5.2.6 ИмСна ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

    ИмСна ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² стилС lowerCamelCase.

    Π’ ΠΏΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹Ρ… ΠΌΠ΅Ρ‚ΠΎΠ΄Π°Ρ… слСдуСт ΠΈΠ·Π±Π΅Π³Π°Ρ‚ΡŒ ΠΈΠΌΠ΅Π½ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ², состоящих ΠΈΠ· ΠΎΠ΄Π½ΠΎΠ³ΠΎ символа.

    5.2.7 ИмСна Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…

    ИмСна Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… ΠΏΠΈΡˆΡƒΡ‚ΡΡ Π² стилС lowerCamelCase.

    Π”Π°ΠΆΠ΅ Π±ΡƒΠ΄ΡƒΡ‡ΠΈ Ρ„ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹ΠΌΠΈ ΠΈ нСизмСняСмыми, Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π½Π΅ ΡΡ‡ΠΈΡ‚Π°ΡŽΡ‚ΡΡ константами ΠΈ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΏΠΈΡΠ°Ρ‚ΡŒΡΡ Π² Ρ‚ΠΎΠΌ ΠΆΠ΅ стилС, Ρ‡Ρ‚ΠΎ ΠΈ константы.

    5.2.8 ИмСна ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… Ρ‚ΠΈΠΏΠ°

    КаТдая пСрСмСнная Ρ‚ΠΈΠΏΠ° имСнуСтся согласно ΠΎΠ΄Π½ΠΎΠΌΡƒ ΠΈΠ· Π΄Π²ΡƒΡ… стилСй:

    5.3 Β«Π’Π΅Ρ€Π±Π»ΡŽΠΆΠΈΠΉΒ» ΡΡ‚ΠΈΠ»ΡŒ (camelCase)

    Иногда сущСствуСт Π±ΠΎΠ»Π΅Π΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ способа ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΠΎΠ²Π°Ρ‚ΡŒ Ρ„Ρ€Π°Π·Ρƒ Π½Π° английском языкС Π² Β«Π²Π΅Ρ€Π±Π»ΡŽΠΆΠΈΠΉΒ» ΡΡ‚ΠΈΠ»ΡŒ, ΠΊΠ°ΠΊ Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π² случаС с Π°Π±Π±Ρ€Π΅Π²ΠΈΠ°Ρ‚ΡƒΡ€Π°ΠΌΠΈ ΠΈΠ»ΠΈ Π½Π΅Ρ‚ΠΈΠΏΠΈΡ‡Π½Ρ‹ΠΌΠΈ выраТСниями Π²Ρ€ΠΎΠ΄Π΅ Β«IPv6Β» ΠΈΠ»ΠΈ Β«iOSΒ».

    Для ΠΏΠΎΠ²Ρ‹ΡˆΠ΅Π½ΠΈΡ прСдсказуСмости, Π΄Π°Π½Π½ΠΎΠ΅ руководство Π·Π°Π΄Π°Π΅Ρ‚ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ (ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π½ΡƒΡŽ) схСму.

    НачинаСм с исходной Ρ„ΠΎΡ€ΠΌΡ‹ ΠΈΠΌΠ΅Π½ΠΈ:

    1. ΠŸΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠΉΡ‚Π΅ Ρ„Ρ€Π°Π·Ρƒ Π² ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ ASCII ΠΈ ΡƒΠ΄Π°Π»ΠΈΡ‚Π΅ всС апострофы. НапримСр, Β«MΓΌller’s algorithmΒ» ΠΌΠΎΠΆΠ½ΠΎ ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΠΎΠ²Π°Ρ‚ΡŒ Π² Β«Muellers algorithmΒ»

    2. Π Π°Π·Π΄Π΅Π»ΠΈΡ‚Π΅ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹ΠΉ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ Π½Π° слова, отбрасывая ΠΏΡ€ΠΎΠ±Π΅Π»Ρ‹ ΠΈ ΠΎΡΡ‚Π°Π²ΡˆΠΈΠ΅ΡΡ Π·Π½Π°ΠΊΠΈ ΠΏΡƒΠ½ΠΊΡ‚ΡƒΠ°Ρ†ΠΈΠΈ (ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ дСфисы):

    ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ рСгистр исходных слов ΠΏΠΎΡ‡Ρ‚ΠΈ ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ игнорируСтся.

    Π˜ΡΡ…ΠΎΠ΄Π½Π°Ρ Ρ„ΠΎΡ€ΠΌΠ°ΠŸΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎΠΠ΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ
    Β«XML HTTP requestΒ»XmlHttpRequestXMLHTTPRequest
    Β«new customer IDΒ»newCustomerIdnewCustomerID
    Β«inner stopwatchΒ»innerStopwatchinnerStopWatch
    Β«supports IPv6 on iOS?Β»supportsIpv6OnIossupportsIPv6OnIOS
    Β«YouTube importerΒ»YouTubeImporter
    YoutubeImporter*

    *ДопускаСтся, Π½ΠΎ Π½Π΅ рСкомСндуСтся.

    ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ слова Π² английском языкС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ дСфис Π½Π΅ΠΎΠ΄Π½ΠΎΠ·Π½Π°Ρ‡Π½ΠΎ: Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ΠΎΠ±Π° слова Β«nonemptyΒ» ΠΈ Β«non-emptyΒ» ΡΠ²Π»ΡΡŽΡ‚ΡΡ ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΌΠΈ, поэтому ΠΈΠΌΠ΅Π½Π° ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² checkNonempty ΠΈ checkNonEmpty Ρ‚Π°ΠΊΠΆΠ΅ ΡΠ²Π»ΡΡŽΡ‚ΡΡ ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΌΠΈ.

    6. ΠŸΡ€Π°ΠΊΡ‚ΠΈΠΊΠ° программирования

    6.1 Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ всСгда Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΡŽ @Override

    ΠœΠ΅Ρ‚ΠΎΠ΄ помСчаСтся Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠ΅ΠΉ @Override всякий Ρ€Π°Π·, ΠΊΠΎΠ³Π΄Π° ΠΎΠ½ Π΄Π΅ΠΉΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ пСрСопрСдСляСтся. Π­Ρ‚ΠΎ относится ΠΊΠ°ΠΊ ΠΊ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρƒ класса-ΠΏΠΎΡ‚ΠΎΠΌΠΊΠ°, ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‰Π΅ΠΌΡƒ ΠΌΠ΅Ρ‚ΠΎΠ΄ класса-родитСля, Ρ‚Π°ΠΊ ΠΈ ΠΊ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρƒ интСрфСйса, ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‰Π΅ΠΌΡƒ ΠΌΠ΅Ρ‚ΠΎΠ΄ супСр-интСрфСйса.

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: аннотация ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΎΠΏΡƒΡ‰Π΅Π½Π°, Ссли Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ ΠΌΠ΅Ρ‚ΠΎΠ΄ ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½ Π°Π½Π½ΠΎΡ‚Π°Ρ†ΠΈΠ΅ΠΉ @Deprecated.

    6.2 НС ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΡƒΠΉΡ‚Π΅ ΠΏΠΎΠΉΠΌΠ°Π½Π½Ρ‹Π΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ

    ΠžΡ‡Π΅Π½ΡŒ Ρ€Π΅Π΄ΠΊΠΎ Π²ΠΎΠ·Π½ΠΈΠΊΠ°ΡŽΡ‚ ситуации, ΠΊΠΎΠ³Π΄Π° Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ ΠΏΡ€Π΅Π΄ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Ρ‚ΡŒ Π½ΠΈ ΠΊΠ°ΠΊΠΈΡ… дСйствий Π² ΠΎΡ‚Π²Π΅Ρ‚ Π½Π° ΠΏΠΎΠΉΠΌΠ°Π½Π½ΠΎΠ΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ (Ρ‚ΠΈΠΏΠΈΡ‡Π½Ρ‹ΠΌ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅ΠΌ являСтся занСсСниС Π² Π»ΠΎΠ³ ΠΈΠ»ΠΈ, Ссли это считаСтся Β«Π½Π΅Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹ΠΌΒ», ΠΏΠ΅Ρ€Π΅Π±Ρ€ΠΎΡΠΈΡ‚ΡŒ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ΠΊΠ°ΠΊ AssertionError).

    НиТС ΠΏΡ€ΠΈΠ²Π΅Π΄Π΅Π½ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ с ΠΏΠΎΡΡΠ½ΡΡŽΡ‰ΠΈΠΌ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ, ΠΊΠΎΠ³Π΄Π° Π΄Π΅ΠΉΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ умСстно Π½Π΅ ΠΏΡ€Π΅Π΄ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Ρ‚ΡŒ Π½ΠΈΠΊΠ°ΠΊΠΈΡ… дСйствий Π² Π±Π»ΠΎΠΊΠ΅ catch:

    Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: Π² тСстах ΠΏΠΎΠΉΠΌΠ°Π½Π½ΠΎΠ΅ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΡ€ΠΎΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΠΎΠ²Π°Π½ΠΎ ΠΈ Π½Π΅ сопровоТдСно ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅ΠΌ, Ссли ΠΈΠΌΠ΅Π½Π΅ΠΌ тСста являСтся expected ΠΈΠ»ΠΈ ΠΆΠ΅, Ссли имя начинаСтся с expected. НиТС приводится ΠΎΡ‡Π΅Π½ΡŒ распространСнная ΠΈΠ΄ΠΈΠΎΠΌΠ°, ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°ΡŽΡ‰Π°Ρ, Ρ‡Ρ‚ΠΎ тСстируСмый ΠΊΠΎΠ΄ Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ΠΎΠΆΠΈΠ΄Π°Π΅ΠΌΠΎΠ³ΠΎ Ρ‚ΠΈΠΏΠ°, поэтому здСсь ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ Π½Π΅ Π½ΡƒΠΆΠ½Ρ‹:

    6.3 Для статичСских Ρ‡Π»Π΅Π½ΠΎΠ² ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ имя класса

    ΠžΠ±Ρ€Π°Ρ‰Π°Ρ‚ΡŒΡΡ ΠΊ Ρ‡Π»Π΅Π½Ρƒ статичСского класса Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ Ρ‡Π΅Ρ€Π΅Π· имя класса, Π° Π½Π΅ ΠΏΠΎ ссылкС Π½Π° ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ класса ΠΈΠ»ΠΈ ΠΏΠΎ Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΡŽ, Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°ΡŽΡ‰Π΅ΠΌΡƒ этот ΠΎΠ±ΡŠΠ΅ΠΊΡ‚:

    6.4 НС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Ρ„ΠΈΠ½Π°Π»ΠΈΠ·Π°Ρ‚ΠΎΡ€Ρ‹

    ΠšΡ€Π°ΠΉΠ½Π΅ΠΉ Ρ€Π΅Π΄ΠΊΠΎ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΠΈΡ‚ΡŒ ΠΌΠ΅Ρ‚ΠΎΠ΄ Object.finalize.

    НС Π΄Π΅Π»Π°ΠΉΡ‚Π΅ этого. Если Π²Π°ΠΌ Π΄Π΅ΠΉΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ это Π½ΡƒΠΆΠ½ΠΎ, сначала ΠΏΡ€ΠΎΡ‡ΠΈΡ‚Π°ΠΉΡ‚Π΅ ΠΈ ΠΎΡ‡Π΅Π½ΡŒ Ρ‚Ρ‰Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ осмыслитС Effective Java Item 7, Β«Avoid FinalizersΒ», Π° Π·Π°Ρ‚Π΅ΠΌ β€” Π½Π΅ Π΄Π΅Π»Π°ΠΉΡ‚Π΅ этого.

    7. Javadoc

    7.1 Π€ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅

    7.1.1 Основная Ρ„ΠΎΡ€ΠΌΠ°

    ΠŸΡ€ΠΎΡΡ‚ΠΎΠ΅ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π±Π»ΠΎΠΊΠΎΠ² Javadoc соотвСтствуСт Π΄Π°Π½Π½ΠΎΠΌΡƒ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρƒ:

    ΠŸΡ€ΠΎΡΡ‚Π°Ρ Ρ„ΠΎΡ€ΠΌΠ° ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠΌΠ° всСгда. ΠžΠ΄Π½ΠΎΡΡ‚Ρ€ΠΎΡ‡Π½Π°Ρ Ρ„ΠΎΡ€ΠΌΠ° ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΡ€ΠΈΠΌΠ΅Π½Π΅Π½Π°, ΠΊΠΎΠ³Π΄Π° вСсь Π±Π»ΠΎΠΊ Javadoc (Π²ΠΊΠ»ΡŽΡ‡Π°Ρ ΠΌΠ°Ρ€ΠΊΠ΅Ρ€Ρ‹ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠ΅Π²) ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΠΎΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒΡΡ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ строкС. ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ это ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠΌΠΎ лишь Ρ‚ΠΎΠ³Π΄Π°, ΠΊΠΎΠ³Π΄Π° Π² Π±Π»ΠΎΠΊΠ΅ Π½Π΅Ρ‚ Ρ‚Π°ΠΊΠΈΡ… тэгов, ΠΊΠ°ΠΊ @return.

    7.1.2 ΠŸΠ°Ρ€Π°Π³Ρ€Π°Ρ„Ρ‹

    нСпосрСдствСнно ΠΏΠ΅Ρ€Π΅Π΄ ΠΏΠ΅Ρ€Π²Ρ‹ΠΌ словом, Π±Π΅Π· ΠΏΡ€ΠΎΠ±Π΅Π»Π° послС.

    7.1.3 Π‘Π»ΠΎΡ‡Π½Ρ‹Π΅ тэги

    ВсС Π±Π»ΠΎΡ‡Π½Ρ‹Π΅ тэги ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ Π² Ρ‚Π°ΠΊΠΎΠΌ порядкС: @param, @return, @throws, @deprecated, ΠΈ эти Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅ Ρ‚ΠΈΠΏΠ° Π½ΠΈΠΊΠΎΠ³Π΄Π° Π½Π΅ ΠΏΡ€ΠΈΡΡƒΡ‚ΡΡ‚Π²ΡƒΡŽΡ‚ с пустым описаниСм. Если Ρ‚Π΅Π³ Π±Π»ΠΎΠΊΠ° Π½Π΅ помСщаСтся Π½Π° ΠΎΠ΄Π½ΠΎΠΉ строкС, строки продолТСния ΠΈΠΌΠ΅ΡŽΡ‚ отступ Π² Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅ (ΠΈΠ»ΠΈ Π±ΠΎΠ»Π΅Π΅) ΠΏΡ€ΠΎΠ±Π΅Π»Π° ΠΎΡ‚ @.

    7.2 Π˜Ρ‚ΠΎΠ³ΠΎΠ²Ρ‹ΠΉ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚

    ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Π±Π»ΠΎΠΊ Javadoc начинаСтся с ΠΊΡ€Π°Ρ‚ΠΊΠΎΠ³ΠΎ ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΠΎΠ³ΠΎ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚Π°. Π­Ρ‚ΠΎΡ‚ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚ ΠΎΡ‡Π΅Π½ΡŒ Π²Π°ΠΆΠ΅Π½: это СдинствСнный тСкст, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ присутствуСт Π² ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΌ контСкстС, Ρ‚Π°ΠΊΠΎΠΌ ΠΊΠ°ΠΊ индСксы классов ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ².

    Π­Ρ‚ΠΎΡ‚ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚ β€” словосочСтаниС с ΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌ ΠΈΠ»ΠΈ Π³Π»Π°Π³ΠΎΠ»ΠΎΠΌ, Π° Π½Π΅ с ΠΏΠΎΠ»Π½Ρ‹ΠΌ ΠΏΡ€Π΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅ΠΌ. Он Π½Π΅ начинаСтся с A <@code Foo>is a… ΠΈΠ»ΠΈ This method returns…, ΠΈ Π½Π΅ ΠΎΠ±Ρ€Π°Π·ΡƒΠ΅Ρ‚ Π·Π°ΠΊΠΎΠ½Ρ‡Π΅Π½Π½ΠΎΠ³ΠΎ ΡƒΡ‚Π²Π΅Ρ€Π΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ прСдлоТСния, ΠΊΠ°ΠΊ Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Save the record. Однако этот Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚ ΠΏΠΈΡˆΠ΅Ρ‚ΡΡ с Π·Π°Π³Π»Π°Π²Π½ΠΎΠΉ Π±ΡƒΠΊΠ²Ρ‹, ΠΈ Π² Π½Π΅ΠΌ ΠΏΡ€ΠΎΡΡ‚Π°Π²Π»ΡΡŽΡ‚ΡΡ Π·Π½Π°ΠΊΠΈ ΠΏΡƒΠ½ΠΊΡ‚ΡƒΠ°Ρ†ΠΈΠΈ, ΠΊΠ°ΠΊ Ссли Π±Ρ‹ это Π±Ρ‹Π»ΠΎ Π·Π°ΠΊΠΎΠ½Ρ‡Π΅Π½Π½ΠΎΠ΅ ΠΏΡ€Π΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅.

    Подсказка: распространСнной ошибкой являСтся написаниС простого Javadoc Π² Π²ΠΈΠ΄Π΅ /** @return the customer ID */. Π­Ρ‚ΠΎ Π½Π΅Π²Π΅Ρ€Π½ΠΎ ΠΈ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ исправлСно Π½Π° /** Returns the customer ID. */.

    7.3 Когда примСняСтся Javadoc

    Javadoc присутствуСт ΠΏΠΎ мСньшСй ΠΌΠ΅Ρ€Π΅ Π² ΠΊΠ°ΠΆΠ΄ΠΎΠΌ public классС ΠΈ Π² ΠΊΠ°ΠΆΠ΄ΠΎΠΌ public ΠΈ protected Ρ‡Π»Π΅Π½Π΅ Ρ‚Π°ΠΊΠΎΠ³ΠΎ класса, Π·Π° ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… случаСв, описанных Π½ΠΈΠΆΠ΅.
    Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ Javadoc ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΡ€ΠΈΡΡƒΡ‚ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ, ΠΊΠ°ΠΊ это Ρ€Π°Π·ΡŠΡΡΠ½Π΅Π½ΠΎ Π² Π Π°Π·Π΄Π΅Π»Π΅ 7.3.4, ΠΠ΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ Javadoc.

    7.3.1 Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹, ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‰ΠΈΠ΅ сСбя

    Javadoc ΠΎΠΏΡ†ΠΈΠΎΠ½Π°Π»Π΅Π½ для простых ΠΈ ΠΎΡ‡Π΅Π²ΠΈΠ΄Π½Ρ‹Ρ… ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ², Ρ‚Π°ΠΊΠΈΡ… ΠΊΠ°ΠΊ getFoo, Π² Ρ‚Π΅Ρ… случаях, ΠΊΠΎΠ³Π΄Π° Π΄Π΅ΠΉΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ нСльзя ΡΠΊΠ°Π·Π°Ρ‚ΡŒ Π½ΠΈΡ‡Π΅Π³ΠΎ Π±ΠΎΠ»Π΅Π΅, Ρ‡Π΅ΠΌ Β«Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ fooΒ».

    Π’Π°ΠΆΠ½ΠΎ: нСумСстно ΡΡΡ‹Π»Π°Ρ‚ΡŒΡΡ Π½Π° это ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠΏΡ€Π°Π²Π΄Π°Ρ‚ΡŒ пропуск ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅ΠΉ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ, ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΠΎΡ‚Ρ€Π΅Π±ΠΎΠ²Π°Ρ‚ΡŒΡΡ ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠΌΡƒ Ρ‡ΠΈΡ‚Π°Ρ‚Π΅Π»ΡŽ.

    НапримСр, для ΠΌΠ΅Ρ‚ΠΎΠ΄Π° с Π½Π°Π·Π²Π°Π½ΠΈΠ΅ΠΌ getCanonicalName Π½Π΅ опускайтС Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΡŽ (с Ρ‚Π΅ΠΌ основаниСм, Ρ‡Ρ‚ΠΎ имя ΠΌΠ΅Ρ‚ΠΎΠ΄Π° Π³ΠΎΠ²ΠΎΡ€ΠΈΡ‚ лишь /** Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ каноничСскоС имя. */), Ссли ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ Ρ‡Π΅Π»ΠΎΠ²Π΅ΠΊ, Ρ‡ΠΈΡ‚Π°ΡŽΡ‰ΠΈΠΉ ΠΊΠΎΠ΄, ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈ Π½Π΅ ΠΏΠΎΠ΄ΠΎΠ·Ρ€Π΅Π²Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎ ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚ Ρ‚Π΅Ρ€ΠΌΠΈΠ½ «каноничСскоС имя»!

    7.3.2 Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅: ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅

    Javadoc Π½Π΅ всСгда сопровоТдаСт ΠΌΠ΅Ρ‚ΠΎΠ΄, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ пСрСопрСдСляСт ΠΌΠ΅Ρ‚ΠΎΠ΄ ΠΈΠ· супСр-класса (ΠΈΠ»ΠΈ супСр-интСрфСйса).

    7.3.4 ΠΠ΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ Javadoc

    ΠŸΡ€ΠΎΡ‡ΠΈΠ΅ классы ΠΈ Ρ‡Π»Π΅Π½Ρ‹ ΡΠΎΠΏΡ€ΠΎΠ²ΠΎΠΆΠ΄Π°ΡŽΡ‚ΡΡ Javadoc ΠΏΠΎ нСобходимости ΠΈΠ»ΠΈ ΠΏΠΎ ТСланию.

    Всякий Ρ€Π°Π·, ΠΊΠΎΠ³Π΄Π° ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ Π±ΡƒΠ΄Π΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ для опрСдСлСния ΠΎΠ±Ρ‰Π΅ΠΉ Ρ†Π΅Π»ΠΈ ΠΈΠ»ΠΈ повСдСния класса ΠΈΠ»ΠΈ Ρ‡Π»Π΅Π½Π°, этот ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ записываСтся ΠΊΠ°ΠΊ Javadoc (с использованиСм /**).

    ΠΠ΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ Javadoc Π½Π΅ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΡ€Π°Π²ΠΈΠ»Π°ΠΌ форматирования Π Π°Π·Π΄Π΅Π»ΠΎΠ² 7.1.2, 7.1.3 ΠΈ 7.2, хотя это, ΠΊΠΎΠ½Π΅Ρ‡Π½ΠΎ, рСкомСндуСтся.

    Π”Π°Π½Π½Ρ‹ΠΉ ΠΏΠ΅Ρ€Π΅Π²ΠΎΠ΄ Ρ‚Π°ΠΊ ΠΆΠ΅ доступСн Π² нашСм Π±Π»ΠΎΠ³Π΅

    Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

    Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ

    Π’Π°Ρˆ адрСс email Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Π½. ΠžΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ поля ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½Ρ‹ *