# New Default Code

DevFeed: [New Default Code](<https://devfeed.tech/articles/new-default-code-19400.md>)

Original publisher: [Read original article](<https://www.codenameone.com/blog/new-default-code/>)

Author: Shai Almog

Published: 2018-03-06T00:00:00Z

Content type: article

Language: en

Sources: [CodeName One](<https://devfeed.tech/sources/codename-one.md>)

Topics: [Boilerplate](<https://devfeed.tech/topics/boilerplate.md>), [Code](<https://devfeed.tech/topics/code.md>), [App](<https://devfeed.tech/topics/app.md>), [networking](<https://devfeed.tech/topics/networking.md>)

Tags: [app](<https://devfeed.tech/tags/app.md>), [code](<https://devfeed.tech/tags/code.md>), [developers](<https://devfeed.tech/tags/developers.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [errors](<https://devfeed.tech/tags/errors.md>), [event](<https://devfeed.tech/tags/event.md>), [feature](<https://devfeed.tech/tags/feature.md>), [github](<https://devfeed.tech/tags/github.md>), [init](<https://devfeed.tech/tags/init.md>), [network](<https://devfeed.tech/tags/network.md>), [networking](<https://devfeed.tech/tags/networking.md>), [performance](<https://devfeed.tech/tags/performance.md>), [toolbar](<https://devfeed.tech/tags/toolbar.md>)

## AI overview

Codename One changed the default boilerplate generated for new hello world apps. The update keeps the code in the init method and adds configurable defaults for two network threads, the global Toolbar, and generic network error handling.

## Source excerpt

This is new behavior that went in without fanfare. If you created a new hello world app you might have noticed this. We changed the default boilerplate for Codename One and made it more representative of what you'd want to see in a hello world app. The entire change to the default generated app is within the init method: public void init(Object context) { // use two network threads instead of one updateNetworkThreadCount(2); __**(1)** theme = UIManager.initFirstTheme("/theme"); // Enable Toolbar on all Forms by default Toolbar.setGlobalToolbar(true); // Pro only feature Log.bindCrashProtection(true); addNetworkErrorListener(err -> { __**(2)** // prevent the event from propagating err.consume(); if(err.getError() != null) { Log.e(err.getError()); } Log.sendLogAsync(); Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null); }); } __1 By default networking in Codename One runs on one network thread for consistency. Two threads make more sense from a performance standpoint. We wanted to make this easily configurable and it should be easy in the init() method __2 Handling network errors in a generic way is probably one of the hardest things to grasp. So many developers are still stuck with the default error handling code... With that in mind we added a bit of boilerplate to handle network errors in a way that makes sense and should be easily customizable I had some thoughts about removing this boilerplate and packaging it in a class. But then I thought again.