<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/can-you-build-an-object-without-calling-its-constructor-cracking-the-java-coding-interview-py6mxlbon" -->

---
title: Can you build an object without calling its constructor?...
description: Constructors are normally the only way to create an object in Java, since even factory methods internally call a constructor. Deserialization is the one...
canonical: https://daily.dev/posts/can-you-build-an-object-without-calling-its-constructor-cracking-the-java-coding-interview-py6mxlbon
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Can you build an object without calling its constructor? Cracking the Java Coding Interview | daily.dev
og:description: Constructors are normally the only way to create an object in Java, since even factory methods internally call a constructor. Deserialization is the one...
og:url: https://daily.dev/posts/can-you-build-an-object-without-calling-its-constructor-cracking-the-java-coding-interview-py6mxlbon
og:image: https://api.daily.dev/og/posts/py6mxlBON.png
og:image:alt: Can you build an object without calling its constructor? Cracking the Java Coding Interview
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Can you build an object without calling its constructor? Cracking the Java Coding Interview

**[Java \(Official Oracle\)](https://daily.dev/sources/java-oracle)** · 1 min read · 0 upvotes · 0 comments

## Summary

Constructors are normally the only way to create an object in Java, since even factory methods internally call a constructor. Deserialization is the one exception: it bypasses the constructor entirely, which can let validation rules be skipped and corrupted objects enter an application. Records break this exception, though, because deserialization always invokes their canonical constructor and its validation, making records safer against this particular bypass.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=ZYEsagr1CjI>

## Questions this post answers

### Does Java deserialization call the constructor of the object being deserialized?

No, standard Java deserialization bypasses the constructor entirely. This is a known security issue because any validation logic placed inside the constructor gets skipped, which can allow corrupted or invalid objects to be reconstructed and enter the running application.

_Developers weighing validation safety in their data models can find deeper Java design discussions like this on daily.dev._

### Do Java records get their validation skipped during deserialization like regular classes do?

No, records are an exception to the exception: their canonical constructor is always invoked during deserialization, including any validation rules defined in it. There is no way to construct a record without going through its canonical constructor, making records a safer choice than regular classes for validated data.

_Anyone deciding between classes and records for safer data modeling can explore more Java patterns via daily.dev._

## Similar posts on daily.dev

- [You Must Avoid Final Field Mutation](https://daily.dev/posts/you-must-avoid-final-field-mutation-owvllfprz) · nipafx \(Nicolai Parlog\) · 0 upvotes · 0 comments
- [Basic and advanced Java serialization](https://daily.dev/posts/basic-and-advanced-java-serialization-rxbf5qb8h) · InfoWorld · 1 upvotes · 0 comments
- [Decapsulation: Breaking Java Strong Encapsulation](https://daily.dev/posts/decapsulation-breaking-java-strong-encapsulation-xzmoii8fd) · Awesome Java Newsletter · 3 upvotes · 0 comments

---

Tags: [#security](https://daily.dev/tags/security), [#java](https://daily.dev/tags/java)

[View this post on daily.dev](https://daily.dev/posts/can-you-build-an-object-without-calling-its-constructor-cracking-the-java-coding-interview-py6mxlbon)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Can you build an object without calling its constructor? Cracking the Java Coding Interview","url":"https://daily.dev/posts/can-you-build-an-object-without-calling-its-constructor-cracking-the-java-coding-interview-py6mxlbon","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/can-you-build-an-object-without-calling-its-constructor-cracking-the-java-coding-interview-py6mxlbon"},"datePublished":"2026-09-11T10:01:07.213Z","dateModified":"2026-10-15T02:22:54.062Z","description":"Constructors are normally the only way to create an object in Java, since even factory methods internally call a constructor. Deserialization is the one...","image":"https://i.ytimg.com/vi/ZYEsagr1CjI/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/ZYEsagr1CjI/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Java (Official Oracle)","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Java (Official Oracle)","logo":"https://media.daily.dev/image/upload/s--SM9hIYUY--/f_auto,q_auto/v1773648791/logos/java-oracle?_a=BAMAMiiu0","url":"https://daily.dev/sources/java-oracle"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/can-you-build-an-object-without-calling-its-constructor-cracking-the-java-coding-interview-py6mxlbon","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"security,java","timeRequired":"PT1M","video":{"@type":"VideoObject","name":"Can you build an object without calling its constructor? Cracking the Java Coding Interview","description":"Constructors are normally the only way to create an object in Java, since even factory methods internally call a constructor. Deserialization is the one...","thumbnailUrl":"https://i.ytimg.com/vi/ZYEsagr1CjI/sddefault.jpg","uploadDate":"2026-09-11T10:01:07.213Z","duration":"PT1M","url":"https://api.daily.dev/r/py6mxlBON","embedUrl":"https://www.youtube.com/embed/ZYEsagr1CjI"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Java (Official Oracle)","item":"https://daily.dev/sources/java-oracle"},{"@type":"ListItem","position":3,"name":"Can you build an object without calling its constructor? Cracking the Java Coding Interview"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/can-you-build-an-object-without-calling-its-constructor-cracking-the-java-coding-interview-py6mxlbon#faq","mainEntity":[{"@type":"Question","name":"Does Java deserialization call the constructor of the object being deserialized?","acceptedAnswer":{"@type":"Answer","text":"No, standard Java deserialization bypasses the constructor entirely. This is a known security issue because any validation logic placed inside the constructor gets skipped, which can allow corrupted or invalid objects to be reconstructed and enter the running application. Developers weighing validation safety in their data models can find deeper Java design discussions like this on daily.dev."}},{"@type":"Question","name":"Do Java records get their validation skipped during deserialization like regular classes do?","acceptedAnswer":{"@type":"Answer","text":"No, records are an exception to the exception: their canonical constructor is always invoked during deserialization, including any validation rules defined in it. There is no way to construct a record without going through its canonical constructor, making records a safer choice than regular classes for validated data. Anyone deciding between classes and records for safer data modeling can explore more Java patterns via daily.dev."}}]}
```

