CodeGym
AI Academy
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • Encapsulation and property visibility: public / private / internal

    Kotlin SELF
    Level 32, Lesson 0
    We explore encapsulation in Kotlin through visibility control: why public by default is an “open door”, how private protects state and invariants, and where internal is appropriate (access within a module). Using Expense and ExpenseBook as examples, we show why you shouldn’t expose MutableList to the outside, how to return a safe List snapshot, and how to validate data correctness with require ( ).
    Available
  • Getters and setters in Kotlin: private set, computed properties, and field

    Kotlin SELF
    Level 32, Lesson 1
    We break down why a property in Kotlin is a mini-API: reading goes through get(), writing through set(value). You’ll learn how to “open” reading and “close” writing with private set, how to make computed properties (showcase/proxy properties) without storage, and how to correctly work with a backing field via field. Separately: validation/normalization in a setter ( require(...), trim()) and common mistakes (recursion in a setter, “expensive” computed properties, scattered validation).
    Available
  • lateinit — deferred initialization and safe class API design

    Kotlin SELF
    Level 32, Lesson 2
    We break down when it makes sense to use lateinit in Kotlin: how to declare non-null properties without initialization, what limitations exist ( val and primitives), what happens on early access, and how to design “two-stage readiness” via init(...) + check(...)/ require(...). We reinforce it with a practical example of a console session BudgetBuddySession.
    Available
  • by lazy — lazy evaluation and result caching

    Kotlin SELF
    Level 32, Lesson 3
    We break down the delegated property val x by lazy { ... }: when exactly the block runs, what is cached and how, how lazy differs from a computed property via get ( ) and from lateinit, and what pitfalls arise due to stale cache, side effects, and thread-safety nuances.
    Available
  • Property delegates: Delegates.observable as a reaction to assignment

    Kotlin SELF
    Level 32, Lesson 4
    We break down how to use a delegated property in Kotlin via by and the ready-made delegate Delegates.observable: when the handler is invoked (after assignment), what parameters it receives ( old/ new and property metadata), how not to violate encapsulation with private set, and where this approach is especially convenient—logging, a “dirty” flag, and a change counter. At the end: common mistakes—recursion inside the handler, trying to validate “after the write”, and noisy logging.
    Available
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym