In this post, we will see enum in Java | Enumeration - enum in Java Programming Tutorial | enums Java | enum in java, enums java, enum in java language, enum in java language
In this post, we will see Exception Handling in Java with Example Programs | try catch throw throws finally in Java | exceptions in java, exception handling in java, exception handling, exception handling in java interview questions, exception handling in java with example program, exception handling in java with realtime examples, exception handling in java with examples, try throw catch java, try catch throw throws finally java, explain try catch throw throws finally in java
In this post, we will see Exception Handling in C++ with Examples | C++ Exception Handling | exception handling in c++, exception handling, c++ exception handling, c++ exception, c++ exception class, c++ exception handling interview questions, c++ exception base class, c++ custom exception, c++ standard exceptions
In this post, we will see Checked and Unchecked Exceptions in Java with Examples | Checked vs Unchecked Exceptions Java | checked and unchecked exceptions in java, checked exception and unchecked exception, checked vs unchecked exceptions java, checked exception in java
In this post, we will see Difference Between Error and Exception in Java, difference between error and exception in java, difference between error and exception
In this post, we will see Dynamic Method Dispatch | Runtime Polymorphism in Java | Virtual & Pure Virtual Function | Abstract | runtime polymorphism, runtime polymorphism in java, runtime polymorphism vs compile time polymorphism, runtime polymorphism and compile time polymorphism, dynamic method dispatch in java, dynamic method dispatch, dynamic method, dynamic method binding, virtual function, pure virtual function, abstract class, abstract class and abstract method, abstract class in java
In this post, we will see Virtual and Pure Virtual Function in C++ | Abstract Class | Runtime vs Compile Time Polymorphism | virtual function in c++, pure virtual function, pure virtual function in c++, abstract class, abstract class in c++, runtime polymorphism, runtime polymorphism vs compile time polymorphism, runtime polymorphism and compile time polymorphism
In this post, we will see this Keyword in Java with Example Program | Java this Keyword | this keyword in java, this keyword, this keyword in java with example program, java this keyword
In this post, we will see Java Input From User | How To Take Input From User in Java Using Scanner | Java Input From Keyboard | how to take input from user in java, how to take input from user in java using scanner, java input from user, java input output tutorial, java input output stream tutorial, java input output stream, java input and output, java inputstream, java input output statements, java input statement, java input method, java input string, java input from keyboard
In this post, we will see Hello World Program in Java | Hello World Program in Java Code | Hello World Program in Java cmd | hello world program in java, hello world program in java notepad, hello world program in java in ubuntu, hello world program in java code, hello world program in java cmd
In this post, we will see Functional and Logic Programming Languages | Functional Programming Paradigm | Logic or Rule Based | functional and logic programming languages, functional and logic model, functional and logic programming, functional programming, functional programming paradigm, applicative programming language, logic and rule based programming
In this post, we will see Imperative and Declarative Programming Paradigms | Imperative vs Declarative Programming | PPL | imperative and declarative programming paradigms, imperative and declarative programming, imperative vs declarative programming, declarative vs imperative programming, imperative programming vs declarative programming, ppl, principles of programming languages
In this post, we will see Statement Level Control Structures | Selection Statements | Iterative Statements | Unconditional Branching | PPL | Sebesta | statement level control structures, selection statements, iterative statements, unconditional branching, ppl, sebesta
Two linguistic mechanisms which are necessary to
make the computations in programs flexible and powerful: some
means of selecting among alternative control flow paths (of statement
execution) and some means of causing the repeated execution of
statements or sequences of statements.
Statements that provide these kinds of capabilities are
called control statements.
It was proven that all algorithms that can be
expressed by flowcharts can be coded in a programming language with only
two control statements:
one for choosing between two
control flow paths and one for logically controlled iterations (Böhm and
Jacopini, 1966).
A control structure is a control
statement and the collection of statements whose execution it
controls.
e.g.
if(a>b)
{
---
---
}
else
{
---
---
}
1. Selection Statements
A selection statement provides the means of
choosing between two or more execution paths in a program.
e.g.
simple if
if else
Nested if
else if ladder
switch
2. Iterative Statements
An iterative statement is one that causes a
statement or collection of statements to be executed zero, one, or more
times.
An iterative statement is often called a loop.
e.g.
for
while
do while
3. Unconditional Branching
An unconditional branch statement transfers
execution control to a specified location in the program.
Without restrictions on use, imposed by either language
design or programming standards, goto statements
can make programs very
difficult to read, and as a result, highly
unreliable and costly to maintain.
A few languages have been designed without a goto for
example, Java, Python, and Ruby.
The relatively new language, C#, includes a goto, even
though one of the languages on which it is based, Java, does not.
In this post, we will see Pointer and Reference Types | PPL | Sebesta | Data Types in Programming Language | data types in ppl, data types ppl, elementary data types in programming language, ppl, sebesta, pointer and reference types
9. Pointer and reference
Type
Definition:
A pointer type is one in which the variables
have a range of values that consists of memory addresses and a special
value, nil.
A pointer can be used to access a location in an
area where storage is dynamically allocated called a heap.
Variables that are dynamically allocated from the heap
are called heap-dynamic variables.
Dangling Pointer
A dangling pointer, or dangling reference,
is a pointer that contains the address of a heap-dynamic variablethat
has been deallocated.
Example from C++ Language:
int * ptr1;
int * ptr2 = new int[100];
ptr1 = ptr2;
delete [] ptr2;
Here, ptr1
and ptr2, both will be dangling pointers.
Java class instances are implicitly deallocated
(there is no explicit deallocation operator), there cannot be dangling
references in Java.
Reference Type:
A reference type variable is similar to a
pointer, with one important and fundamental difference: A pointer
refers to an address in memory, while a reference refers to an
object or a value in memory.
Example:
int a = 0;
int &b = a;
b = 100;
In this code segment, variables a and b are aliases. b
is reference to a.
In this post, we will see Union Types | Discriminated Union vs Free Union With Example | PPL | Sebesta | Data Types in Programming Language | data types in ppl, data types ppl, elementary data types in programming language, ppl, sebesta, union types,discriminated union, union, tagged union, free union, discriminated vs free union
8. Union Types
A union is a type whose variables may store different
type values at different times during program execution.
Record vs Union
struct sample
{
int x;
float y;
char z;
};
union sample
{
int x;
float y;
char z;
};
union sample x;
Free Unions vs
Discriminated Unions
C and C++ provide union constructs in which there is no
language support for type checking.
The unions in these languages are called free unions,
because programmers are allowed complete freedom from type checking in their
use.
Type checking of unions requires that each union
construct include a type indicator. Such an indicator is called a
tag, or discriminant, and a union with a discriminant
is called a discriminated union.
The first language to provide discriminated unions was ALGOL
68. They are now supported by Ada, ML, Haskell, and F#.
Unions in Ada
e.g.
type Shape is (Circle,
Triangle, Rectangle);
type Colors is (Red, Green,
Blue);
type Figure (Form : Shape) is
record
Filled : Boolean;
Color : Colors;
case Form is
when Circle =>
Diameter : Float;
when Triangle =>
Left_Side : Integer;
Right_Side : Integer;
Angle : Float;
when Rectangle =>
Side_1 : Integer;
Side_2 : Integer;
end case;
end record;
Figure_1 : Figure;
Figure_2 : Figure(Form =>
Triangle);
Here,
Figure_1 is unconstrained
variant record.
Figure_2 is constrained
variant record.
Unions in F#
type intReal =
| IntValue of int
| RealValue of float;;
A compile-time descriptor
for a discriminated union