The Components in a Java Program
That each English and Java are known as languages is not any coincidence. You employ language to specific concepts. English expresses concepts to folks, and Java expresses concepts to computer systems.
What’s extra, each English and Java have issues like phrases, names, and punctuation. In actual fact, the largest distinction between the 2 languages is that Java is less complicated to study than English.
(If English have been simple, then computer systems would perceive English. Sadly, they’ll’t.) Take an bizarre English sentence and evaluate it with the code in Itemizing. Right here’s the sentence: Suzanne says “eh” as a result of, as you already know, she lives in Canada.
Identifiers that you simply or I can outline
I just like the identify Suzanne, however in the event you don’t like conventional names, then make up a brand-new identify. You’re having a brand new child. Name her “Deneen” or “Chris anta.” Title him “Belton” or “Merk.”
A reputation is a phrase that identifies one thing, so I’ll cease calling these items names and begin calling them identifiers. In laptop programming, an identifier is a noun of some sort.
An identifier refers to a price, part of a program, a sure form of construction, or any variety of issues. Itemizing has two identifiers that you simply or I can outline on our personal. They’re the made-up phrases.
Identifiers with agreed-upon meanings
Many individuals are named Suzanne, however just one nation is known as Canada. That’s as a result of there’s a normal, well-known which means for the phrase “Canada.” It’s the nation with a crimson maple leaf on its flag. In case you begin your personal nation,
you need to keep away from naming it Canada, as a result of naming it Canada would simply confuse everybody. (I do know, a city in Kentucky is known as Canada, however that doesn’t depend.
Keep in mind, you need to ignore exceptions like this.) Most programming languages have identifiers with agreed-upon meanings. In Java, nearly all of those identifiers are outlined within the Java API. Itemizing has 5 such identifiers.
A literal is a bit of textual content that appears like no matter worth it represents. In Suzanne’s sentence, “eh” is literal, as a result of “eh” refers back to the phrase “eh.”
Programming languages have literals too. For instance, in Itemizing 4-1, the stuff in quotes is literal.
A typical laptop program has a number of punctuation. For instance, think about this system
Every bracket, every brace, every squiggle of any sort performs a job in making this system significant.
In English, you write all the best way throughout one line, and you then wrap your textual content to the beginning of the subsequent line. In programming, you seldom work this fashion. As a substitute, the code’s punctuation guides the indenting of sure strains. The indentation reveals which components of this system are subordinate to which different components.
A remark is textual content that’s exterior the traditional move. In Determine phrases “A remark:” aren’t a part of the Suzanne sentence. As a substitute, these phrases are in regards to the Suzanne sentence.
The identical is true of feedback in laptop packages. The primary 5 strains in Itemizing type one large remark. The pc doesn’t act on this remark. There are not any directions for the pc to carry out inside this remark.
As a substitute, the remark tells different programmers one thing about your code. Feedback are to your personal profit, too. Think about that you simply put aside your code for some time and work on one thing else. Whenever you return later to work on the code once more, the feedback enable you bear in mind what you have been doing.