开发者

What are the basic language constructs in java?

I've been asked to "Identify all language constructs in Java. Your list should start with classes:

The body of class declarations"

I was under the impression that a 'language construct' was any allowable command in a langua开发者_JAVA百科ge, but this is clearly not what is meant by the question. If anyone could give me a clearer understanding of what a language construct is in this context, and what kind of thing this list should contain, I would appreciate it.

Thanks in advance!


Well, according to Wikipedia, a language construct is "a syntactically allowable part of a program that may be formed from one or more lexical tokens in accordance with the rules of a programming language"

The phrase "language construct(s)" appears in the JLS once, in the Preface (excluding a mention in the index): "We intend that the behavior of every language construct is specified here..." This implies that every Java "language construct" is cataloged in the JLS. Combined with the Wikipedia definition, that would seem to cover everything from keywords and literal values; types, names, and variables; to packages, classes, interfaces, and class members like methods, fields, and constructors; blocks, statements, expressions... Take your pick. Just take a look through the ToC.


It seems to me that he means to ask "What is allowed within the body of a class declaration?" Which, in normal Java, would be something like this:

  • A class may contain both "members" and static blocks.
  • A member may be public, protected, package private, or private.
  • A member may be either statically or non-statically accessible
  • A member may be one of:
    1. Variable
    2. Method
    3. Inner Class
  • A variable may be followed by an assignment.
  • A method may contain a series of calls to other methods, variable declarations, and variable assignments.
  • Finally, an inner class may contain all the things listed above, as it itself is a normal class.


I hope you would be knowing what a construct is.

Therefore let me tell you the types of constructs that are allowed in Java:

  1. Sequence construct-in this pragram starts at one place and it is executed line by line (each and every line is executed in this part of code).
  2. Selection construct - in this construct we have two or more than two statements or part of code and only a limited or one is executed depending upon the condition (e.g. if else).
  3. Looping construct - in this a set of statements is repeated again and again(part of code that is repeated again and again).

This classification was on basis of the path followed by the the compiler or interpreter while the code is executed.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜