Program Components
Identifiers
Identifiers are lexical tokens to identify entities in a program, query or request.
It could be a combination of characters (string) which uniquely identifies a resource or entity in a given domain/scope.
Qualifiers
In cases where there could be an ambiguity in identifying an entity, qualifiers serve as the distinguishing factor to uniquely and unambiguously identify an entity.
Qualifiers are also identifiers, which help remove ambiguity. But not all identifiers are qualifiers.
In addition to being used, where its not possible to interpret identifiers unambiguously, qualifiers can be used to –
- Override a default context: If the default context is the current class or default database, qualifier can be used to override that.
- Provide missing context: We can explicitly state the default context too to clearly indicate the intended context.
Qualified Identifiers
Qualified Identifiers are used in case where there an ambiguity as to which entity an identifier can refer to. In such cases, the identifier is paired with a dev.lingo.identifiers.qualifier.
An identifier can be "fully qualified" by combining all possible qualifiers. For example, a complete file path.
Unqualified Identifier
In cases where there is no ambiguity in the entity being referred to, we can simply use dev.lingo.identifierss. Such identifiers are called unqualified since there is no need for a dev.lingo.identifiers.qualifier.
Statements
Statements are just instructions for the computer to do something.
A program is just a sequence of statements.
Expression
A bit of code that produces a value.
Literals
Literals are specific values that appear directly in code.
For example, 2.5
, "Hello"
etc.
Variables
Pointers
Pointer Arithematic
Since pointers are numeric values, you can technically perform arithmetic operations on them.
Advantages of pointers
- Helpful for writing extremely low level code
- dev.memory management.manual
- Useful for some applications (games, device drivers)
Case against pointers
-
Memory access via dev.lingo.variable.pointer.arithmetic — fundamentally unsafe
-
dev.memory management.manual — not worth the effort for general purpose OOP programming
Reference Variables
- References are strongly typed
Type of a reference is much more strictly controlled in Java than the type of a dev.lingo.variable.pointer is in C. In C you can have an int*
and cast it to a char*
and just re-interpret the memory at that location. That re-interpretation doesn’t work in Java: you can only interpret the object at the other end of the reference as something that it already is (i.e. you can cast a Object reference to String reference only if the object pointed to is actually a String).
-
References are not memory addresses per se. They are more like object handles.
-
The object's memory address will change when it's moved. But the object handle will stay the same.
-
For example, JVM is allowed to use moving garbage collectors, which means objects can be relocated by the GC. (In fact, generational GCs frequently relocate objects, when migrating them between generations.)
-
dev.lingo.variable.pointer.arithmetic nlot allowed.
Functions
Anonymous Function
Functions without a name.
There are different ways of creating anonymous functions:
// An anonymous function assigned to a variable
const add = function(x, y) {
return x + y;
};
console.log(add(2, 3)); // Output: 5
// An anonymous function used as a callback
setTimeout(function() {
console.log("Hello, World!");
}, 1000);
Can be created using CS/Paradigms/Functional Programming#Lambda expressions. Such functions are called lambda functions.
# Anonymous (lambda) function passed to map
squared = list(map(lambda x: x ** 2, [1, 2, 3, 4]))
print(squared) # Output: [1, 4, 9, 16]
References
- Statements vs Expressions - Josh W Comeau Pointers
- Pointer Arithmetic in C with examples - GFG
- Why Java doesn't support pointers? — Stack overflow
Reference Variables
- C/C++ Pointers vs Java References — Geeks for geeks
- If Java uses references and references are just memory addresses, can I perform arithmetic operations on the addresses they point to? — Quora
Qualifier
- Joop Eggen's comment on 'What does "qualified this" construct mean in java?' - StackOverflow
- Spring @Qualifier annotation - Baeldung
- Database Object Names and Qualifiers - Oracle Database
Qualified Identifier
- [11.2.2. Identifier Qualifiers - MySQL 8.0 Reference Manual Including MySQL NDB Cluster 8.0 - Oracle Docs](https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/identifier-qualifiers.html
- Identifier Qualifiers - MariaDB Knowledge Base
- Identifier Qualifiers - MySQL 8.0 Reference Manual