As mentioned before, generally, the UI is declared in XML files and then modified during runtime through the Java code. It is possible to create the UI completely in Java code, though for a complex layout, it would generally not be considered best practice.
In this recipe, we are going to add a view to the existing layout defined in activity_main.xml.