julia_introduction
julia_introduction
One of the facts about scientific programming is that it requires high performance flexible
dynamic programming language. Unfortunately, to a great extent, the domain experts
have moved to slower dynamic programming languages. There can be many good reasons for
using such dynamic programming languages and, in fact, their use cannot be diminished
as well. On the flip side, what can we expect from modern language design and compiler
techniques? Some of the expectations are as follows:
The Julia programming language fulfills these expectations. It is a general purpose high-
performance flexible programming language which can be used to write any application.
It is well-suited for scientific and numerical computing.
HistoryofJulia
Let us see the history of Julia programming language in the following points:
• Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and Alan Edelman has started to work on Julia in
2009.
• The developer’s team of above four has launched a website on 14th February 2012. This website
had a blog post primarily explaining the mission of Julia programming language.
• Later in April 2012, Stefan Karpinski, in an interview with a magazine named InfoWorld,
gave the name “Julia” for their programming language.
• In 2014, the annual academic conference named ‘The JuliaCon’ for Julia; users and developers
has been started and since then it was regularly held every year.
• In August 2014, Julia Version 0.3 was released for use.
• In October 2015, Julia Version 0.4 was released for use.
• In October 2016, Julia Version 0.5 was released for use.
• In June 2017 Julia Version 0.6 was released for use.
• Julia Version 0.7 and Version 1.0 were both released on the same date 8th August 2018. Among
them Julia version 0.7 was particularly useful for testing packages as well as for the users who
wants to upgrade to version 1.0.
• Julia versions 1.0.x are the oldest versions which are still supported.
• In January 2019, Julia Version 1.1 was released for use.
• In August 2019, Julia Version 1.2 was released for use.
• In November 2019, Julia Version 1.3 was released for use.
• In March 2020, Julia Version 1.4 was released for use.
• In August 2020, Julia Version 1.5 was released for use.
FeaturesofJulia
Following are some of the features and capabilities offered by Julia:
Python:
• Julia compiles the Python-like code into machine code that gives the programmer same performance as C
programming language.
• If we compare the performance of Julia and Python, Julia is ahead with a factor of 10 to 30 times.
• With the help of PyCall package, we can call Python functions in Julia.
R:
• As we know, in statistical domain, R is one of the best development languages, but with a performance
increase of a factor of 10 to 1,000 times, Julia is as usable as R in statistical domain.
• MATLAB is not a fit for doing statistics and R is not a fit for doing linear algebra, but Julia is perfect for
doing both statistics and linear algebra.
• Julia’s type system with R, the Juia has much richer type system.
InstallingJulia
Let us see how we can install Julia on various platforms:
• You can also create a symbolic link to Julia programming language. The link should be inside a folder which
is on your system PATH.
• You can add Julia’s bin folder with full path to system PATH environment variable by editing the
~/.bashrc or ~/.bash_profile file. It can be done by opening the file in any of the editors and adding
the line given below:
To invoke Julia programming language by simply typing Julia in cmd, we must add Julia executable
directory to system PATH. You need to follow the following steps according to your windows
specifications:
On Windows 10
• First open Run by using the shortcut Windows key + R.
• Now, type rundll32 sysdm.cpl, EditEnvironmentVariables and press enter.
• We will now find the row with “Path” under “User Variable” or “System Variable”.
• Now click on edit button to get the “Edit environment variable” UI.
• Now, click on “New” and paste in the directory address we have noted while installation
(C:\Users\Ga\AppData\Local\Programs\Julia1.5.1\bin).
• Finally click OK and Julia is ready to be run from command line by typing Julia.
Building Julia from source
To build Julia from source rather than binaries, we need to follow the below given steps.
Here we will be outlining the procedure for Ubuntu OS.
• Julia has built-in package manager named pkg.jl for package installation.
• The package manager handles installation, removal, and updates of packages.
• The package manager works only if the packages are in REPL.
Installing packages
Step 1: First open the Julia command line.
Step 2: Now open the Julia package management environment by pressing, ]. You will get the following
console:
Adding a package
For adding a package in Julia environment, we need to use add command with the name of the package. For
example, we will be adding the package named Graphs which is uses for working with graphs in Julia.
Removing a package
For removing a package from Julia, we need to use rm command with the name of the of
the package. For example, we will be removing the package named Graphs as follows:
Julia Programming
To update a Julia package, either you can use update command, which will update all the
Julia packages, or you can use up command along with the name of the package, which
will update specific package.
Testing a package
Use test command to test a Julia package. For example, below we have tested JSON
package:
InstallingIJulia
To install IJulia, use add IJulia command in Julia package environment. We need to make sure that
you have preinstalled Anaconda on your machine. Once it gets installed, open Jupyter notebook and
choose Julia1.5.1 as follows:
Now you will be able to write Julia programs using IJulia as follows:
If you have added Julia to your path, the same script can be saved in a file say hello.jl
and can be run by typing Julia hello.jl at command prompt. Alternatively the same can
also be run from Julia REPL by typing include(“hello.jl”). This command will evaluate all
valid expressions and return the last output.
Variables
What can be the simplest definition of a computer program? The simplest one may be that a computer
program is a series of instructions to be executed on a variety of data.
Here the data can be the name of a person, place, the house number of a person, or even a list of things you
have made. In computer programming, when we need to label such information, we give it a name (say
A) and call it a variable. In this sense, we can say that a variable is a box containing data.
Let us see how we can assign data to a variable. It is quite simple, just type it. For example,
student_name = “Ram”
roll_no = 15
marks_math = 9.5
Here, the first variable i.e. student_name contains a string, the second variable i.e.
roll_no contains a number, and the third variable i.e. marks_math contains a floating-
point number. We see, unlike other programming languages such as C++, Python, etc.,
Comments
Writing comments in Julia is quite same as Python. Based on the usage, comments are of
two types:
Example
Multi-line Comments
In Julia, the multi-line comment is a piece of text, like single line comment, but it is
enclosed in a delimiter #= on the start of the comment and enclosed in a delimiter =# on
the end of the comment. Example
julia> #= This is an example to demonstrate the multi-line comments that tells
us about tutorialspoint.com. At this website you can browse the best resource
for Online Education.=#