SCALA AND JAVA LANGUAGE SHARING IN PROBLEM SOLVING - Студенческий научный форум

XIII Международная студенческая научная конференция Студенческий научный форум - 2021

SCALA AND JAVA LANGUAGE SHARING IN PROBLEM SOLVING

Циртаутас М.А. 1, Койкова Т.И. 1
1ВлГУ
 Комментарии
Текст работы размещён без изображений и формул.
Полная версия работы доступна во вкладке "Файлы работы" в формате PDF

Abstract: This article discusses the sharing of Scala and Java programming languages in solving problems. Shows how you can work in the Scala programming language and use the existing Java language functionality.

Keywords: Scala programming language, Java programming language, import of libraries, using Java language classes.

Various programming languages are used to develop modern software. The development of technology is pushing the emergence of new programming languages. Some modern programming languages are based on two or more languages, adopting the features of these languages and eliminating their shortcomings. One such language is Scala programming language. Scala is a multi-paradigm programming language designed short and type-safe for the simple and fast creation of component software, combining the capabilities of functional and object-oriented programming [1]. First of all, the language inherited a significant number of concepts and syntax agreements Java and C #. The method of expressing properties is largely borrowed from the Sather language. The concept of a unified object model is taken from the Smalltalk language. From the BETA language came the idea that everything, including classes, should allow nesting. Abstract types in Scala are very similar to abstract signature types in SML and OCaml, generalized in the context of full-fledged components. This article discusses how the Scala programming language interacts with the Java programming language.

In Scala, interaction with Java is implemented using the import of Java language libraries. You must use the keyword "import" to import a library. When connecting a package, you must specify which language it belongs to: Scala or Java. All classes from the java.lang package are imported by default, while other packages need to be explicitly imported. You will learn more about importing using the example in which you want to obtain and format the current date according to agreements made in France. The Java class library contains utility classes, such as Date and DateFormat, that are required to solve this problem. In order not to implement equivalent classes in the Scala programming language, the import of ready-made classes from Java libraries will be used:

import java.util.{Date, Locale}

import java.text.DateFormat

import java.text.DateFormat._

object FrenchDate {

def main(args: Array[String]) {

val now = new Date

val df = getDateInstance(LONG, Locale.FRANCE)

println(df format now)

}

} [2]

Scala provides the ability to import individual classes from a single package. This option is demonstrated in the first line of the example code, where two Data and Locale classes are imported from the java.util package. Another possibility of Scala is to import all package or class names. Thus, the import expression on the third line imports all members of the DateFormat class. This makes the static getDateInstance method and the static LONG field directly visible. Inside the main function, an instance of the Date Java class is created that contains the current date. Next, you define the date format using the static method "getDateInstance" that was previously imported. The last line prints the current date formatted according to the localized DateFormat instance. It should be noted that it is also possible to inherit from Java classes and implement the Java interface directly in Scala.

As you can see in Figure 1, Java libraries make up only a small fraction of the capacity of Scala libraries.

Figure 1 - Class hierarchy [3]

This article discusses the interaction of the Scala programming language with the Java programming language through the import of Java libraries. Due to this interaction of the two languages, there is no need to implement equivalent classes in the Scala class library.

The list of the used sources:

Scala (язык программирования) [Электрон. ресурс]. Режим доступа: https://ru.wikipedia.org/wiki/Scala_(язык_программирования) (дата обращения: 05.04.2018)

Руководство по Scala для Java программистов[Электрон.ресурс]. Режим доступа: https://sitedev.ru/f/2012/04/rukovodstvo-po-scala-dlia-java-programmistov.pdf (дата обращения: 01.04.2018)

Хорстман К. Scala для нетерпеливых. - М.: ДМК Пресс, 2013. - 403 с.: ил.

Просмотров работы: 46