Learn Scala’s file I/O operations, handling JSON, XML, and serialization libraries. These 30 MCQs will help you master reading, writing files, and working with popular libraries like Circe and Play JSON.
Source?
Source.read()Source.fromFile()Source.readAll()Source.open()PrintWriter in Scala?
new FileWriter()new PrintWriter()Source.write()File.create()Source.fromFile() in Scala?
File objectBufferedSource in Scala allow?
FileWriter.append()PrintWriter.append()Source.append()File.create()Source.fromFile() in Scala?
close()closeFile()Source.close()File.close()Source.fromFile("file.txt").mkStringFile.read("file.txt")Source.read("file.txt")Source.load("file.txt")try-with-resourcesfinally blockusing method from scala.utilclose() on the file objectCircePlay JSONJacksonCirce is used to encode a Scala object into JSON?
encode()toJson()asJson()convertToJson()Circe?
decode()parseJson()jsonParse()fromJson()XMLscala.xmlJDOMPlay XMLJsObject from a Scala case class in Play JSON?
Json.toJson()Json.parse()toJson()Json.write()Circe?
decode[YourClass](jsonString)jsonString.toCaseClass()fromJson(jsonString)asCaseClass(jsonString)Play JSON to represent a JSON object?
JsObjectJsonObjectJsonMapJSonObjectscala.xml.XML.loadFile() do in Scala?
XML.loadString()XML.parse()XML.stringToXML()parseXML()toJson() method do in Play JSON?
CircePlay JSONJacksonUpickleCirce’s JSON support in Scala?
import io.circe._import play.api.libs.json._import com.fasterxml.jackson._import org.json4s._Circe use for serializing and deserializing JSON?
Encoder and DecoderMarshaller and UnmarshallerWriter and ReaderJsonFormatPlay JSON?
Json.stringify(Json.toJson(object))object.toJson()Json.encode(object)object.toJsonString()Circe?
decodeEither()parseJson()safeDecode()tryDecode()Json.format() in Play JSON?
Circe provide for better handling of default values?
JsonDefaultsderiveEncoder and deriveDecoderJson.optional()defaultValue()Circe?
Printer.pretty()Json.prettyPrint()jsonString.prettyPrint()json.pretty()Play JSON handle case class fields that are optional?
Option in the case classNullableMap using Play JSON?
Json.formatMap()Json.toMap() and Json.fromMap()Map.format()Map.toJson()| Qno | Answer (Option with the text) |
|---|---|
| 1 | B) Source.fromFile() |
| 2 | B) To write data to a file |
| 3 | B) By using new PrintWriter() |
| 4 | A) It reads a file line by line |
| 5 | B) Fast reading from large files |
| 6 | B) PrintWriter.append() |
| 7 | D) UTF-8 |
| 8 | A) close() |
| 9 | A) Source.fromFile("file.txt").mkString |
| 10 | C) By using using method from scala.util |
| 11 | D) All of the above |
| 12 | C) asJson() |
| 13 | A) decode[YourClass](jsonString) |
| 14 | B) scala.xml |
| 15 | A) Json.toJson() |
| 16 | A) decode[YourClass](jsonString) |
| 17 | A) JsObject |
| 18 | A) It parses an XML file into a Scala XML object |
| 19 | A) XML.loadString() |
| 20 | A) Converts an object into a JSON string |
| 21 | A) Circe |
| 22 | A) import io.circe._ |
| 23 | A) Encoder and Decoder |
| 24 | A) Json.stringify(Json.toJson(object)) |
| 25 | A) By using decodeEither() |
| 26 | A) It automatically provides reads and writes for case classes |
| 27 | B) deriveEncoder and deriveDecoder |
| 28 | A) Printer.pretty() |
| 29 | A) By using Option in the case class |
| 30 | B) Json.toMap() and Json.fromMap() |