Nested Classes
Nested Classes The Java programming language allows you to define a class within another class. Such a class is called a nested class and is illustrated here: class OuterClass { … class NestedClass { … } } A nested class is a member of its enclosing class and, as such, has access to other members […]
More on Classes
More on Classes This section covers more aspects of classes that depend on using object references and the dot operator that you learned about in the preceding sections on objects: Returning values from methods. The this keyword. Class vs. instance members. Access control.
Objects
Objects A typical Java program creates many objects, which as you know, interact by invoking methods Through these object interactions, a program can carry out various tasks, such as implementing a GUI, running an animation, or sending and receiving information over a network. Once an object has completed the work for which it was created, […]
Classes
Classes The introduction to object-oriented concepts in the lesson titled Object-oriented Programming Concepts used a bicycle class as an example, with racing bikes, mountain bikes, and tandem bikes as subclasses. Here is sample code for a possible implementation of a Bicycle class, to give you an overview of a class declaration. Subsequent sections of this […]
Language Basics
Language Basics Variables You’ve already learned that objects store their state in fields. However, the Java programming language also uses the term “variable” as well. This section discusses this relationship, plus variable naming rules and conventions, basic data types (primitive types, character strings, and arrays), default values, and literals. Operators This section describes the operators […]
Expressions, Statements, and Blocks
Expressions, Statements, and Blocks Now that you understand variables and operators, it’s time to learn about expressions, statements, and blocks. Operators may be used in building expressions, which compute values; expressions are the core components of statements; statements may be grouped into blocks. ExpressionsAn expression is a construct made up of variables, operators, and method […]
Control Flow Statements
Control Flow Statements The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code. This section describes the decision-making statements […]
Operators
Operators Now that you’ve learned how to declare and initialize variables, you probably want to know how to do something with them. Learning the operators of the Java programming language is a good place to start. Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result. […]
Variables
Variables As you learned in the previous lesson, an object stores its state in fields. int cadence = 0;int speed = 0;int gear = 1; The What Is an Object? discussion introduced you to fields, but you probably have still a few questions, such as: What are the rules and conventions for naming a field? […]
Java Language Keywords
Java Language Keywords Here’s a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use […]