Friday, February 3, 2017

LISP - Overview

John McCarthy invented LISP in 1958, shortly after the development of FORTRAN. It was first implement by Steve Russell on an IBM 704 computer.

LISP - Environment Setup

Try it Option Online

You really do not need to set up your own environment to start learning LISP programming language. Reason is very simple, we already have set up Lisp Programming environment online, so that you can execute all the available examples online at the same time when you are doing your theory work.

LISP - Program Structure

LISP expressions are called symbolic expressions or s-expressions. The s-expressions are composed of three valid objects, atoms, lists and strings.
Any s-expression is a valid program.

LISP - Basic Syntax

Basic Building Blocks in LISP

LISP programs are made up of three basic building blocks:
  • atom
  • list
  • string

LISP - Data Types

In LISP, variables are not typed, but data objects are.
LISP data types can be categorized as.
  • Scalar types - for example, number types, characters, symbols etc.
  • Data structures - for example, lists, vectors, bit-vectors, and strings.

LISP - Macros

Macros allow you to extend the syntax of standard LISP.
Technically, a macro is a function that takes an s-expression as arguments and returns a LISP form, which is then evaluated.

LISP - Variables

In LISP, each variable is represented by a symbol. The variable's name is the name of the symbol and it is stored in the storage cell of the symbol.

LISP - Constants

In LISP, constants are variables that never change their values during program execution. Constants are declared using the defconstant construct.

LISP - Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. LISP allows numerous operations on data, supported by various functions, macros and other constructs.
The operations allowed on data could be categorized as:

LISP - Decision Making

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

LISP - Loops

There may be a situation, when you need to execute a block of code numbers of times. A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages.

LISP - Functions

A function is a group of statements that together perform a task.
You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is so each function performs a specific task.

LISP - Predicates

Predicates are functions that test their arguments for some specific conditions and returns nil if the condition is false, or some non-nil value is the condition is true.
The following table shows some of the most commonly used predicates:

LISP - Numbers

Common Lisp defines several kinds of numbers. The number data type includes various kinds of numbers supported by LISP.
The number types supported by LISP are:

LISP - Characters

In LISP, characters are represented as data objects of type character.
You can denote a character object preceding #\ before the character itself. For example, #\a means the character a.

LISP - Arrays

LISP allows you to define single or multiple-dimension arrays using the make-array function. An array can store any LISP object as its elements.
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

LISP - Strings

Strings in Common Lisp are vectors, i.e., one-dimensional array of characters.
String literals are enclosed in double quotes. Any character supported by the character set can be enclosed within double quotes to make a string, except the double quote character (") and the escape character (\). However, you can include these by escaping them with a backslash (\).

LISP - Sequences

Sequence is an abstract data type in LISP. Vectors and lists are the two concrete subtypes of this data type. All the functionalities defined on sequence data type are actually applied on all vectors and list types.
In this section, we will discuss most commonly used functions on sequences.

LISP - Lists

Lists had been the most important and the primary composite data structure in traditional LISP. Present day's Common LISP provides other data structures like, vector, hash table, classes or structures.
Lists are single linked lists. In LISP, lists are constructed as a chain of a simple record structure named cons linked together.

LISP - Symbols

In LISP, a symbol is a name that represents data objects and interestingly it is also a data object.
What makes symbols special is that they have a component called the property list, or plist.

LISP - Vectors

Vectors are one-dimensional arrays, therefore a subtype of array. Vectors and lists are collectively called sequences. Therefore all sequence generic functions and array functions we have discussed so far, work on vectors.

LISP - Set

Common Lisp does not provide a set data type. However, it provides number of functions that allows set operations to be performed on a list.
You can add, remove, and search for items in a list, based on various criteria. You can also perform various set operations like: union, intersection, and set difference.

LISP - Tree

You can build tree data structures from cons cells, as lists of lists.
To implement tree structures, you will have to design functionalities that would traverse through the cons cells, in specific order, for example, pre-order, in-order, and post-order for binary trees.

LISP - Hash Table

The hash table data structure represents a collection of key-and-value pairs that are organized based on the hash code of the key. It uses the key to access the elements in the collection.

LISP - Input & Output

Common LISP provides numerous input-output functions. We have already used the format function, and print function for output. In this section, we will look into some of the most commonly used input-output functions provided in LISP.

LISP - File I/O

We have discussed about how standard input and output is handled by common LISP. All these functions work for reading from and writing into text and binary files too. Only difference is in this case the stream we use is not standard input or output, but a stream created for the specific purpose of writing into or reading from files.

LISP - Structures

Structures are one of the user-defined data type, which allows you to combine data items of different kinds.
Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book:

LISP - Packages

In general term of programming languages, a package is designed for providing a way to keep one set of names separate from another. The symbols declared in one package will not conflict with the same symbols declared in another. This way packages reduce the naming conflicts between independent code modules.

LISP - Error Handling

In Common LISP terminology, exceptions are called conditions.
In fact, conditions are more general than exceptions in traditional programming languages, because a condition represents any occurrence, error, or not, which might affect various levels of function call stack.

LISP - CLOS

Common LISP predated the advance of object-oriented programming by couple of decades. However, it object-orientation was incorporated into it at a later stage.

LISP - Quick Guide

LISP - Overview

John McCarthy invented LISP in 1958, shortly after the development of FORTRAN. It was first implement by Steve Russell on an IBM 704 computer.
It is particularly suitable for Artificial Intelligence programs, as it processes symbolic information effectively.

LISP - Useful Resources

The following resources contain additional information on LISP. Please use them to get more in-depth knowledge on this topic.

Discuss LISP

Lisp is the second-oldest high-level programming language after Fortran and has changed a great deal since its early days, and a number of dialects have existed over its history. Today, the most widely known general-purpose Lisp dialects are Common Lisp and Scheme.

Small & Simple Programs in C

Let's first start with very small & simple programs to get basic idea of C programming code structure. We shall get the basic idea of variable declaration, scanning and printing etc.

Loop Examples in C

This segment is designed to give the learner an enhanced view of how loops work in c langauges. We shall see simple loops like for, while and do-while, along with nested loops.

Patterns Examples in C

This section is full of examples that uses nested loops in a controlled manner. We may see that the outer loop is controlling the inner one etc. We have taken the simplest examples which are very common too.

Array Example Programs in C

Array is a collection of homogenous data, arranged in sequential format. Learning the concept of arrays in C is very important as it is the basic data structure. Here, in this section, we shall look into some very useful array programs to give you insight of how C programming language deals with arrays.

String Programs in C

Strings are actually one-dimensional array of characters terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise the string followed by a null.

Mathematical Programs in C

This section has been developed to introduce some common mathematical problems that can be solved using c programming language.

Linked List Programs in C

A linked-list is a sequence of data structures which are connected together via links.
Linked List is a sequence of links which contains items. Each link contains a connection to another link. Linked list the second most used data structure after array.

Learn C By Examples - Quick Guide

Small & Simple Programs in C

Let's first start with very small & small programs to get basic idea of C programming code structure. We shall get the basic idea of variable declaration, scanning and printing etc.

Learn C By Examples - Useful Resources

The following resources contain additional information on Learn C By Examples. Please use them to get more in-depth knowledge on this topic.

Discuss Learn C By Examples

C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.

JCL - Overview

When to use JCL

JCL is used in a mainframe environment to act as a communication between a program (Example: COBOL, Assembler or PL/I) and the operating system. In a mainframe environment, programs can be executed in batch and online mode.

JCL - Environment Setup

Installing JCL on Windows/Linux

There are many Free Mainframe Emulators available for Windows which can be used to write and learn sample JCLs.
One such emulator is Hercules, which can be easily installed in Windows by following few simple steps given below:

JCL - JOB Statement

JOB Statement is the first control statement in a JCL. This gives the identity of the job to the Operating System (OS), in the spool and in the scheduler. The parameters in the JOB statement help the Operating Systems in allocating the right scheduler, required CPU time and issuing notifications to the user.

JCL - EXEC Statement

Each JCL can be made of many job steps. Each job step can execute a program directly or can call a procedure, which in turn executes one or more programs (job steps). The statement, which holds the job step program/procedure information is the EXEC statement.

JCL - DD Statement

Datasets are mainframe files with records organised in a specific format. Datasets are stored on the Direct Access Storage Device (DASD) or Tapes of the mainframe and are basic data storage areas. If these data are required to be used/created in a batch program, then the file (i.e., dataset) physical name along with the file format and organisation are coded in a JCL.

JCL - Base Library

Base Library is the Partitioned Dataset (PDS), which holds the load modules of the program to be executed in the JCL or the catalogued procedure, which is called in the program. Base libraries can be specified for the whole JCL in a JOBLIB library or for a particular job step in a STEPLIB statement.

JCL - Procedures

The JCL Procedures are set of statements inside a JCL grouped together to perform a particular function. Usually, the fixed part of the JCL is coded in a procedure. The varying part of the Job is coded within the JCL.

JCL - Conditional Processing

The Job Entry System uses two approaches to perform conditional processing in a JCL. When a job completes, a return code is set based on the status of execution. The return code can be a number between 0 (successful execution) to 4095 (non-zero shows error condition). The most common conventional values are:

JCL - Defining Datasets

A dataset name specifies the name of a file and it is denoted by DSN in JCL. The DSN parameter refers to the physical dataset name of a newly created or existing dataset. The DSN value can be made up of sub-names each of 1 to 8 characters length, separated by periods and of total length of 44 characters

Input-Output Methods

Any batch program executed through a JCL requires data input, which is processed and an output is created. There are different methods of feeding input to the program and writing output received from a JCL. In batch mode, there is no user interaction required but input and output devices and required organisation are defined in JCL and submitted.

Running COBOL Programs using JCL

Compiling COBOL Programs

In order to execute a COBOL program in batch mode using JCL, the program needs to be compiled and a load module is created with all the sub-programs. The JCL uses the load module and not the actual program at the time of execution.

JCL - Utility Programs

IBM Dataset Utilities

Utility programs are pre-written programs, widely used in mainframes by system programmers and application developers to achieve day-to-day requirements, organising and maintaining data. A few of them are listed below with their functionality:

JCL - Basic Sort Tricks

The day-to-day application requirements in a corporate world that can be achieved using Utility Programs are illustrated below:

JCL Questions and Answers

JCL Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations.

JCL - Quick Guide

JCL - Overview

When to use JCL

JCL is used in a mainframe environment to act as a communication between a program (Example: COBOL, Assembler or PL/I) and the operating system. In a mainframe environment, programs can be executed in batch and online mode.

JCL - Useful Resources

If you want to list down your website, book or any other resource on this page, then please contact at webmaster@tutorialspoint.com.

Discuss JCL

Job Control Language (JCL) is the command language of Multiple Virtual Storage (MVS), which is the commonly used Operating System in the IBM Mainframe computers. JCL identifies the program to be executed, the inputs that are required and location of the input/output and informs the Operating System through Job control Statements. In mainframe environment, programs can be executed in batch and online modes. JCL is used for submitting a program for execution in batch mode.

Java BeanUtils - Overview

Description

The Java BeanUtils are the components of the Apache Commons which are derived from JavaAPI and provides component architecture for the Java language. The Java BeanUtils design patterns uses utility classes that helps to get and set the property values on Java classes for retrieving and defining the bean properties.

Java BeanUtils - Background

Description

The standard JavaBeans of Java language can be used to access the property values of beans using the proper getter methods. The Java language supplies the java.beans.Introspector class to inspect a Java class at runtime.

Java BeanUtils - Basic Property Access

Description

You can access the basic properties by using the following ways:
  • Simple Property
  • Indexed Property
  • Mapped Property

Java BeanUtils - Nested Property Access

Description

You can access the value of nested property of the bean by concatenating the property names of the access path by using "." separators.
You can get and set the values of Nested property by using the below methods:

Java BeanUtils - Customizing Introspection

Description

The introspection tool can be used to learn about the properties and operations provided by your class. BeanUtils package is depending on JavaBeans specification that determines the available properties for a particular bean class.

Java BeanUtils - Suppressing Properties

Description

You can suppress the specific properties by using the bean introspection mechanism. The specialized BeanIntrospector interface is implemented by the type called SuppressPropertiesBeanIntrospector which suppresses the special class properties of Java beans.

Java BeanUtils - Background (DynaBeans)

Description

You can give dynamic property access on the existing JavaBean classes without altering with the help of PropertyUtils class. The dynamically calculated property values as JavaBean can also represented by using dynamic property access without writing a Java class to render these properties.

Java BeanUtils - Basic DynaBeans

Description

The implementation of BasicDynaBean and BasicDynaClass specifies the capacity of dynamic property to provide the set of properties dynamically. You can start with DynaClass to establish the set of properties. A newInstance() method will create a new DynaBean instances to DynaClass and occupy its initial values as shown in the below example.

Java BeanUtils - ResultSetDynaClass

Description

The ResultSet can be wrapped in the DynaBeans by using the ResultSetDynaClass which renders the results of SQL query as series of DynaBeans. The most commonly used collection is java.sql.ResultSet which is returned when JDBC driver uses SQL SELECT statement.

Java BeanUtils - RowSetDynaClass

Description

The RowSetDynaClass copies the undisclosed data in the DynaBeans memory while creating an instance which displays the result and using this class, you can close the ResultSet data before proceeding the actual data that was returned.

Java BeanUtils - WrapDynaBean

Description

As we have seen in the previous chapters, DynaBeans APIs provides get() and set() methods to access simple, indexed and mapped properties of DynaBeans dynamically.

Java BeanUtils - Lazy DynaBeans

Description

Lazy DynaBeans is an implementation of DynaBean, which gives the characteristics of Lazy List and Lazy Map this connects the properties of DynaClass. There are four types of Lazy DynaBeans:

Java BeanUtils - Background (Data Type Conversions)

Description

Data type conversion is a process of changing value from one data type to another. In the previous chapters, dynamically accessed properties of data types are recognized and to achieve the type conversions, we can use Java casts. The BeanUtils package gives various types of APIs and design patterns for performing the data type conversions.

Java BeanUtils - BeanUtils and ConvertUtils

Description

The BeanUtils is defined as a utility method for populating JavaBeans properties and ConvertUtils method converts string scalar values to objects, string arrays to arrays of the specified class.

Java BeanUtils - Create Custom Converters

Description

BeanUtils package allows creating your own string object to convert for any java class and the registered converters can be used by all the BeanUtils methods.
The following are the steps to create and register your own converter:

Java BeanUtils - Locale Aware Conversions

Description

The regular classes available in org.apache.commons.beanutils are not assigned for any specific event. These classes provide a clear interface to make use of situations very easily where the locale is not main thing. You can use Locale-aware extensions of beanutils classes which helps localization, from the org.apache.commons.beanutils.locale package.

Java BeanUtils - Utility Objects & Classes

Description

The utility classes such as BeanUtils, ConvertUtils and PropertyUtils can be accessed through utility objects and shares the same caches and registered converters. You can instantiate corresponding class with same functionality for each static utility class.

Java BeanUtils - Comparing Beans

Description

In Apache Commons Beanutils, you can compare the JavaBean objects by using the BeanComparator class based on a specified shared property value. This can be done by using the org.apache.commons.beanutils.BeanComparator comparator.

Java BeanUtils - Operating On Collections

Description

The Commons-Collections are build upon interfaces, implementations and utilities. It contains Closure interface in the code that can be applied on the arbitrary input object and code permits to apply Closures to contents of collection.

Java BeanUtils - Querying Or Filtering Collections

Description

The collections of beans can be filtered in the commons-collections by using the interface Predicate and also provides either true or false value on the evaluation of an input object. There is a Predicate called BeanPropertyValueEqualsPredicate which will assess the set property value against the given value.

Java BeanUtils - Transforming Collections

Description

The conversion from input object to output object is supported in commons-collections with the help of Transformer interface. The Transformers can be applied to get the output collection from input collection with the help of codes available in Commons-collections.

Java 8 - Overview

JAVA 8 (aka jdk 1.8) is a major release of JAVA programming language development. Its initial version was released on 18 March 2014. With the Java 8 release, Java provided support for functional programming, new JavaScript engine, new APIs for date time manipulation, new streaming API, etc.

Java 8 - Environment Setup

Try it Option Online

We have set up the Java Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options.

Java 8 - Lambda Expressions

Lambda expressions are introduced in Java 8 and are touted to be the biggest feature of Java 8. Lambda expression facilitates functional programming, and simplifies the development a lot.

Java 8 - Method References

Method references help to point to methods by their names. A method reference is described using :: (double colon) symbol. A method reference can be used to point the following types of methods −

Java 8 - Functional Interfaces

Functional interfaces have a single functionality to exhibit. For example, a Comparable interface with a single method ‘compareTo’ is used for comparison purpose. Java 8 has defined a lot of functional interfaces to be used extensively in lambda expressions. Following is the list of functional interfaces defined in java.util.Function package.

Java 8 - Default Methods

Java 8 introduces a new concept of default method implementation in interfaces. This capability is added for backward compatibility so that old interfaces can be used to leverage the lambda expression capability of Java 8.

Java 8 - Streams

Stream is a new abstract layer introduced in Java 8. Using stream, you can process data in a declarative way similar to SQL statements. For example, consider the following SQL statement −
SELECT max(salary), employee_id, employee_name FROM Employee

Java 8 - Optional Class

Optional is a container object which is used to contain not-null objects. Optional object is used to represent null with absent value. This class has various utility methods to facilitate code to handle values as ‘available’ or ‘not available’ instead of checking null values. It is introduced in Java 8 and is similar to what Optional is in Guava.

Class Declaration

Following is the declaration for java.util.Optional<T> class −
public final class Optional<T>
extends Object

Class Method

S. No. Method & Description
1 static <T> Optional<T> empty() Returns an empty Optional instance.
2 boolean equals(Object obj) Indicates whether some other object is "equal to" this Optional.
3 Optional<T> filter(Predicate<? super <T> predicate) If a value is present and the value matches a given predicate, it returns an Optional describing the value, otherwise returns an empty Optional.
4 <U> Optional<U> flatMap(Function<? super T,Optional<U>> mapper) If a value is present, it applies the provided Optional-bearing mapping function to it, returns that result, otherwise returns an empty Optional.
5 T get() If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.
6 int hashCode() Returns the hash code value of the present value, if any, or 0 (zero) if no value is present.
7 void ifPresent(Consumer<? super T> consumer) If a value is present, it invokes the specified consumer with the value, otherwise does nothing.
8 boolean isPresent() Returns true if there is a value present, otherwise false.
9 <U>Optional<U> map(Function<? super T,? extends U> mapper) If a value is present, applies the provided mapping function to it, and if the result is non-null, returns an Optional describing the result.
10 static <T> Optional<T> of(T value) Returns an Optional with the specified present non-null value.
11 static <T> Optional<T> ofNullable(T value) Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.
12 T orElse(T other) Returns the value if present, otherwise returns other.
13 T orElseGet(Supplier<? extends T> other) Returns the value if present, otherwise invokes other and returns the result of that invocation.
14 <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) Returns the contained value, if present, otherwise throws an exception to be created by the provided supplier.
15 String toString() Returns a non-empty string representation of this Optional suitable for debugging.
Note − This class inherits methods from the java.lang.Object class.

Optional Example

To understand how Optional is used in practice, let us see the following example. Write the following program, execute and verify result to get more insight of it.

Java8Tester.java

import java.util.Optional;

public class Java8Tester {
   public static void main(String args[]){
   
      Java8Tester java8Tester = new Java8Tester();
      Integer value1 = null;
      Integer value2 = new Integer(10);
  
      //Optional.ofNullable - allows passed parameter to be null.
      Optional<Integer> a = Optional.ofNullable(value1);
  
      //Optional.of - throws NullPointerException if passed parameter is null
      Optional<Integer> b = Optional.of(value2);
      System.out.println(java8Tester.sum(a,b));
   }
 
   public Integer sum(Optional<Integer> a, Optional<Integer> b){
 
      //Optional.isPresent - checks the value is present or not
  
      System.out.println("First parameter is present: " + a.isPresent());
      System.out.println("Second parameter is present: " + b.isPresent());
  
      //Optional.orElse - returns the value if present otherwise returns
      //the default value passed.
      Integer value1 = a.orElse(new Integer(0));
  
      //Optional.get - gets the value, value should be present
      Integer value2 = b.get();
      return value1 + value2;
   }
}

Verify the Result

Compile the class using javac compiler as follows −
$javac Java8Tester.java
Now run the Java8Tester as follows −
$java Java8Tester
It should produce the following output −
First parameter is present: false
Second parameter is present: true
10

Java 8 - Nashorn JavaScript

With Java 8, Nashorn, a much improved javascript engine is introduced, to replace the existing Rhino. Nashorn provides 2 to 10 times better performance, as it directly compiles the code in memory and passes the bytecode to JVM. Nashorn uses invokedynamics feature, introduced in Java 7 to improve performance.

Java 8 - New Date/Time API

With Java 8, a new Date-Time API is introduced to cover the following drawbacks of old date-time API −
  • Not thread safe − java.util.Date is not thread safe, thus developers have to deal with concurrency issue while using date. The new date-time API is immutable and does not have setter methods.

Java 8 - Base64

With Java 8, Base64 has finally got its due. Java 8 now has inbuilt encoder and decoder for Base64 encoding. In Java 8, we can use three types of Base64 encoding −

Java 8 Questions and Answers

Java 8 Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations.

Java 8 - Quick Guide

Java 8 - Overview

JAVA 8 is a major feature release of JAVA programming language development. Its initial version was released on 18 March 2014. With the Java 8 release, Java provided supports for functional programming, new JavaScript engine, new APIs for date time manipulation, new streaming API, etc.

Java 8 - Useful Resources

The following resources contain additional information on Java8. Please use them to get more in-depth knowledge on this tpoic.

Discuss Java 8

Java 8 is the most awaited and is a major feature release of Java programming language. This is an introductory tutorial that explains the basic-to-advanced features of Java 8 and their usage in a simple and intuitive way.