Java Identifiers : Java Literal, Reserved keywords, Separator, Punctuation

Java Identifiers

Java Identifiers and names

We will often get embarrassed later on at one point or another Have to give a name, for example, a variable as a placeholder for a To be able to calculate with different values. For this, we have to, however, know how to assign such names in Java. In their simplest form, names consist of a single java Identifiers, this is composed of the following elements in Java:

  • the letters a, b, c, …, x, y, z, A, B, C, …, X, Y, Z of the alphabet (Java differentiates between upper and lower case). Since Java is an international programming language, let the language standard here includes various country-specific extensions. valid letters that are used in a java Identifiers allowed to. We become aware of such characters in this script, however, do without, since the exchange of programs written in this way often causes problems leads. so that source codes without a certain Additional effort are no longer portable. For the translated bytecode – that is, the class files that are generated by the javac compiler a result we don’t have these problems, but we also want to be able to address our Exchange program texts with each other.
  • the underscore “_”
  • the dollar sign “$”
  • the digits 0,1,2, …, 9

Java Identifiers always begin with a letter, an underscore, or the dollar sign – but never with a digit. Furthermore, no reserved Word can be used as a java Identifiers, d. H. Java Identifiers are not allowed to read like one of the “words” we know in the following sections learn. In addition, names can also consist of several java Identifiers with a period (such as the name System.out.println).



The following examples show valid identifiers in Java:

  • Hello World
  • HELLO
  • hello123
  • hello_123

However, the following examples would lead to an error message in Java:

  • 101test                //java Identifiers may not begin with digits.
  • That’s it             // the ‘character is not allowed in java Identifiers.
  • Hello World    //Java Identifiers cannot contain spaces.
  • Class                //class word cannot be used because this is a reserved word.

Java Identifiers Literal:

A literal or a literal constant describes a constant value that is cannot change within a program (and therefore by the Java compiler is usually included directly in the bytecode). Have literals, depending on their type (e.g. whole number or floating-point number), prescribed Spellings. The following types of literals occur in Java:

  • whole numbers (e.g. 23 or -166) 2
  • Floating point numbers (e.g. 3.14)
  • Truth values ​​(true and false)
  • individual characters in single quotes (e.g. ’a’)
  • Strings in quotation marks (eg “Hello World”) and
  • the so-called null literal for references, represented by the literal constant zero.

We will go into the individual points in more detail later. Want right now we just remember that there are so-called literals and that they are part of a Java Program can (and will) be.


Java Identifiers Reserved keywords

As already mentioned, there are certain words that are not used as identifiers in Java may use. On the one hand, there are the literal constants true, false, and null and, on the other hand, a series of words (so-called word symbols) that appear in Java is assigned a predefined symbolic meaning. These will also be called keywords. We will gradually become the latter in their meaning to get to know. in below Table lists these.

 

abstract

 

assert boolean break Byte
case

 

catch char class Const
continue

 

default do double Else
enum

 

extends final finally Float
for

 

goto if implements Import
instanceof

 

int interface long Native
new

 

package private protected Public
return

 

short static strictfp Super
switch

 

synchronized this throw Throws
transient

 

try void volatile while

 

Java Identifiers Separator:

Which horse breed do flower pots belong to? The old preschool joke questions are mostly based on one Basic principle of languages: If you have several words, you have to use them separately them appropriately by pauses otherwise, nobody understands your Sense! If you write down the corresponding words, the pauses become Spaces, dashes, and commas. The Java compiler must also be able to use individual java Identifiers and word symbols to separate from each other. We have several options for doing this Disposal, the so-called separators.

These are:

  • Spaces
  • End-of-line character (pressing the ENTER key)
  • Tab character (the TAB key)
  • Comments
  • Operators (such as + or *)
  • the punctuation marks . , ; ) ({ } [ ]

The latter two groups of characters have in the Java language, however a special meaning. You should therefore only use them where they have belonged. Immediately following word symbols, literals or java Identifiers separated from each other by at least one of the symbols above, provided whose beginning and end cannot be recognized from the context. Here is In Java it doesn’t really matter which separator you use (and how many of them). For example, if there is a bracket between two java Identifiers in the program, so this is already considered a separator symbol. No more spaces insert (but can and should do so). The program line

public static void main (String [] args)

would therefore be completely equivalent to the following lines:

public       // used separators: space and comment static

/ * Use an end-of-line character * /

void

// ..

// ..

// you can also use multiple line feeds

main (// there are now two separators: bracket and comment!

String [] args)


However, this does not make the text clearer. We will therefore later agree on some conventions to make our programs more readable.

Java Punctuation marks:

The semicolon corresponds to the point in Java. Commands (the sentences of the language, so to speak) are always preceded by a semicolon in Java completed. If this is missing, the translator delivers an error message of the form

console

Error.java:10: ’;’ expected.

Here, Fehlerhaft.java is the file name under which the program is saved has been. The specified number stands for the number of the line in which the error occurred. As already mentioned, there are other punctuation marks in Java in addition to the semicolon. Are z. B. summarized several commands in a block, so this is done by putting a curly in front of the first and behind the last command Bracket sets. Here is an example:

{           // start of block

System.out.println (“B1”);              // Command No. 1

System.out.println (“B2”);            // Command No. 2

System.out.println (“B3”);          // Command No. 3

}

Java Operator symbols:

Operators are special symbols that serve up to three different each Link values ​​ the so-called operands to a new value We distinguish the operators according to the number of their operands: Monadic operators are operators that only require one operand. Examples of this are the operators ++ or –.

dyadic operators combine two operands and are the most commonly occurring type of operators. Examples of this are the operators +, – or ==.

triadic operators combine three operands. The only example in Java is the operator?: (question mark colon).

In Java, operators are given so-called priorities, which means that in the language certain sequences in the evaluation (for example point before Line calculation) are specified. We will return to this topic later Deal.



Java import statements

Many of the things that we need in Java are not at the core of the language, For example, screen output or standard mathematical functions like sine or cosine. They were outsourced to so-called classes, which was the first must be loaded if required when the program starts. The translator must know them by name. He knows some of these classes without our intervention (they are in a standard package called java.lang), others must we explicitly make them known by name by having them imported.

In order to instruct the translator to initiate such a process, a so-called import statement is used. This makes the instruction designated class accessible, d. H. he can access them and use them. Examples of this are the scanner class from the Package java.util or the class IOTools, with the help of which you can make entries later from the keyboard. The latter class belongs to one freely available package called Prog1Tools that is not from Sun or. Oracle originates and therefore does not belong to the standard integrated tools heard. If you have installed this package on your computer and want to use the class in one of your programs 3 start your program With

import Prog1Tools.IOTools;

or with

import static Prog1Tools.IOTools. *;

whereby the second variant carries out a static import4, which is only possible from the Java version 5.0 is possible.

Many classes that we need especially at the beginning are automatically created by the system presumed known so it will be a while before in the import statement appears for the first time in our programs. she is nevertheless the basic element of a Java program and should therefore at this point have already been mentioned.


Related Article:

Exception Handling in Java

Java Hello World First Program

 

Recommended For You

About the Author: Fawad

My name is Shahzada Fawad and I am a Programmer. Currently, I am running my own YouTube channel "Expertstech", and managing this Website. My Hobbies are * Watching Movies * Music * Photography * Travelling * gaming and so on...

Leave a Reply

%d bloggers like this: