Skip to main content

Scala 2.10 : Install

 

Install Scala 2.10.

[1]. Make sure the current enabled version of Scala and Install it.

[root@dlp ~]# dnf module list scala

CentOS-8 - AppStream

Name  Stream   Profiles  Summary

scala 2.10 [d] common [d A hybrid functional/object-oriented language for the JV

               ]         M

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled


# install Scala 2.10

[root@dlp ~]# dnf module -y install scala:2.10

[root@dlp ~]# scala -version

Scala code runner version 2.10.6 -- Copyright 2002-2013, LAMP/EPFL

[2]. Run Scala REPL (Read Eval Print Loop) which is the interactive shell to Test Scala.

[root@dlp ~]# scala

Welcome to Scala version 2.10.6 (OpenJDK 64-Bit Server VM, Java 1.8.0_232).

Type in expressions to have them evaluated.

Type :help for more information.


# print words

scala> println("Hello Scala World")

Hello Scala World


# set constants

scala> val msg:String = "Hello Scala World"

msg: String = Hello Scala World


scala> println(msg)

Hello Scala World


# exit

scala> sys.exit

[3]. Create a sample program to Test Scala.

[root@dlp ~]# vi readfile.scala

import java.io.File

import java.io.FileReader

import java.io.BufferedReader


object readfile {

  def main(args: Array[String]) {

    val reader = new BufferedReader(new FileReader(new File("/etc/passwd")))

    try {

      var line : String = null

        while ({ line = reader.readLine; line != null }) {

          println(line)

        }

    } finally {

      reader.close

    }

  }

}


# run as a script

[root@dlp ~]# scala readfile.scala

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

.....

.....


# compile and run

[root@dlp ~]# scalac readfile.scala

[root@dlp ~]# ll

total 16

-rw-------. 1 root root 1534 Oct 12 22:40  anaconda-ks.cfg

-rw-r--r--. 1 root root 1104 Dec 13 19:10 'readfile$.class'

-rw-r--r--. 1 root root  574 Dec 13 19:10  readfile.class

-rw-r--r--. 1 root root  387 Dec 13 19:10  readfile.scala


[root@dlp ~]# scala readfile

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

.....

.....


Comments

Popular posts from this blog

Unix / Linux - Special Variables

W e will discuss in detail about special variable in Unix. In one of our previous chapters, we understood how to be careful when we use certain nonalphanumeric characters in variable names. This is because those characters are used in the names of special Unix variables. These variables are reserved for specific functions. For example, the  $  character represents the process ID number, or PID, of the current shell − $echo $$ The above command writes the PID of the current shell − 29949 The following table shows a number of special variables that you can use in your shell scripts − Command-Line Arguments The command-line arguments $1, $2, $3, ...$9 are positional parameters, with $0 pointing to the actual command, program, shell script, or function and $1, $2, $3, ...$9 as the arguments to the command. Following script uses various special variables related to the command line − #!/bin/sh echo "File Name: $0" echo "First Parameter : $1" echo "Second Parameter :...

LINUX List files and directories using SSH

In order to list all files and directories using an SSH client, you would need to execute the appropriate command. The command name, in this case, is ls and it accepts various parameters. When using the command alone (without arguments): ls the output will be all visible files and folders without additional formatting or information. In order to view more information about the files (such as their permissions, ownership, last modified date, etc) and at the same time to list the files and directories, you would need to supply additional arguments to the command. The most common arguments are as follows: ls –a(Short from –all) Lists all files and folders including hidden (starting with a dot) files and directories. ls –R (Short from –Recursive) Lists recursively (i.e follows subfolders as well) all files and folders under the current directory. ls -l (Short from –long) Lists all files and folders, each on a separate line, and provides additional information about them (permission...

Initial Settings : Vim Settings

 There are many cases to use text editor on CUI terminal, so it's more convenient to install editors with advanced features like Vim. [1]. Install Vim in this example. [root@dlp ~]# dnf -y install vim-enhanced [2]. Set command alias for your own environment. But for users that has UID 201 or higher, Alias is already set by [/etc/profile.d/vim.sh] file that is included in [vim-enhanced] package. [root@dlp ~]# vi ~/.bashrc # add alias to the end alias vi='vim' # apply changes [root@dlp ~]# source ~/.bashrc [3]. Configure Vim for your own environment. (common settings for all users are in [/etc/vimrc]) [root@dlp ~]# vi ~/.vimrc " use extended function of vim (no compatible with vi) set nocompatible " specify encoding set encoding=utf-8 " specify file encoding set fileencodings=utf-8,iso-2022-jp,sjis,euc-jp " specify file formats set fileformats=unix,dos " take backup " if not, specify [ set nobackup ] set backup " specify backup directo...