Skip to content

misostack/ref_kotlin

Repository files navigation

Kotlin Reference

  1. Hello World
  2. Working with JSON Files

1. Hello World

To get started with Kotlin, you can write a simple "Hello, World!" program.

2. Working with JSON Files

  • Data Structure with Kotlin Data Classes: Data Types, Classes, Properties
  • Error Handling: Try-Catch, Null Safety
  • File I/O: Reading and Writing Files
  • Reading JSON Files
  • Writing JSON Files
  • Example: Reading and Writing JSON Files
  • Balance Management: Balance, Income, Expense, DateTime

Data Structure Example:

{
  "balance": 0,
  "transactions": [
    {"id": 1, "type": "income", "amount": 1000, "date": "2023-10-01T10:00:00", "description": "Salary"},
    {"id": 2, "type": "expense", "amount": 200, "date": "2023-10-02T12:00:00", "description": "Groceries"}
  ],
  "reports": {
    "yearly": [
      {
        "year": "2022",
        "totalIncome": 1200,
        "totalExpense": 500,
        "netBalance": 700
      }
    ],
    "monthly": [
      {
        "month": "2023-10",
        "totalIncome": 1000,
        "totalExpense": 200,
        "netBalance": 800
      }
    ]
  }
}
Method Input Type Typical Use Case Key Feature
writeText String Simple text files One-liner, overwrites
writeBytes ByteArray Binary data (images, PDFs) Handles raw bytes
printWriter Writer API Formatted output (println/printf) Easy formatting
bufferedWriter Writer API Large text files Efficient buffered writes

About

Kotlin References

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages