{"id":2943,"date":"2019-11-21T17:35:05","date_gmt":"2019-11-21T22:35:05","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=2943"},"modified":"2019-11-21T17:35:07","modified_gmt":"2019-11-21T22:35:07","slug":"kotlin-how-to-create-a-simple-hello-world-app","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2019\/11\/21\/kotlin-how-to-create-a-simple-hello-world-app\/","title":{"rendered":"Kotlin: How to create a simple Hello World app"},"content":{"rendered":"\n<p>When starting on the journey of learning the Kotlin language, it is a good idea to get an initial impression of the language by creating and running the simplest possible program in Kotlin. That is what I will describe how to do in this article. <\/p>\n\n\n\n<p>The first step assumes that you have already downloaded and installed the IntelliJ IDEA editor, which was created by Jet Brains specifically for Java and Kotlin. This can be downloaded from here:<br><a href=\"https:\/\/www.jetbrains.com\/idea\/\">https:\/\/www.jetbrains.com\/idea\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-1.png\" alt=\"\" class=\"wp-image-2946\" width=\"381\" height=\"385\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-1-296x300.png 296w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-1-768x779.png 768w\" sizes=\"auto, (max-width: 381px) 100vw, 381px\" \/><\/figure>\n\n\n\n<p>The first step after launching the program is to click &#8220;Create New Project&#8221;. Then you should see this dialog, where you should choose Kotlin from the list in the left column:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-2-1024x914.png\" alt=\"\" class=\"wp-image-2948\" width=\"495\" height=\"440\"\/><\/figure>\n\n\n\n<p>After clicking &#8220;Next&#8221;, there will be a &#8220;New Project&#8221; dialog that opens. In the &#8220;Project name:&#8221; field at the top, give your project a name. I chose &#8220;HelloKotlinWorld&#8221;. As you type this in, you will see the name populate in several other places below.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-3-1024x914.png\" alt=\"\" class=\"wp-image-2949\" width=\"502\" height=\"447\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-3-1024x914.png 1024w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-3-300x268.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-3-768x686.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-3.png 1194w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/figure>\n\n\n\n<p>The new project will appear under &#8220;Project&#8221; in the left pane. Right click on the &#8220;src&#8221; folder to create a new app. Choose the &#8220;Kotlin File\/Class&#8221; option near the top.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-4-896x1024.png\" alt=\"\" class=\"wp-image-2950\" width=\"542\" height=\"619\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-4-896x1024.png 896w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-4-263x300.png 263w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-4-768x877.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-4-676x772.png 676w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-4.png 1448w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/figure>\n\n\n\n<p>Then a small dialog will open up where you can give your app a name. I chose the name &#8220;simple_app&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-5-1024x634.png\" alt=\"\" class=\"wp-image-2951\" width=\"488\" height=\"302\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-5-1024x634.png 1024w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-5-300x186.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-5-768x476.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-5-676x419.png 676w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-5.png 1502w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/figure>\n\n\n\n<p>After clicking Enter (return) on your keyboard, you should now see the new app listed in the Editor as a <code>.kt<\/code> file. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"335\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-6-1024x335.png\" alt=\"\" class=\"wp-image-2952\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-6-1024x335.png 1024w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-6-300x98.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-6-768x251.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-6-676x221.png 676w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-6.png 1584w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now for the code! In the editor pane on the right, type &#8220;main&#8221; and click <code>TAB<\/code>. This is a shortcut that will create the main function in IntelliJ IDEA. For example:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-7.png\" alt=\"\" class=\"wp-image-2953\" width=\"231\" height=\"151\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-7.png 340w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-7-300x196.png 300w\" sizes=\"auto, (max-width: 231px) 100vw, 231px\" \/><\/figure>\n\n\n\n<p>Now to get the main function to do something, type the following <code>println()<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">fun main() {\n    println(\"Hello Kotlin World!\")\n}<\/pre>\n\n\n\n<p>Next, to run the simple app, click the green arrow in the gutter next to the code pane, and choose the Run option at the top:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-8.png\" alt=\"\" class=\"wp-image-2955\" width=\"394\" height=\"181\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-8.png 754w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-8-300x138.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-8-676x312.png 676w\" sizes=\"auto, (max-width: 394px) 100vw, 394px\" \/><\/figure>\n\n\n\n<p>Kotlin is a compiled language, so you will immediately notice that running the app initiates a compile:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-9.png\" alt=\"\" class=\"wp-image-2956\" width=\"476\" height=\"40\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-9.png 894w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-9-300x26.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-9-768x65.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-9-676x57.png 676w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/figure>\n\n\n\n<p>When the program is done compiling after a couple seconds, a console window will appear at the bottom of the Editor window, displaying the output of the <code>println()<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"187\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-10-1024x187.png\" alt=\"\" class=\"wp-image-2957\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-10-1024x187.png 1024w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-10-300x55.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-10-768x140.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/11\/image-10-676x123.png 676w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Success!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When starting on the journey of learning the Kotlin language, it is a good idea to get an initial impression of the language by creating and running the simplest possible program in Kotlin. That is what I will describe how to do in this article. The first step assumes that you have already downloaded and &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2019\/11\/21\/kotlin-how-to-create-a-simple-hello-world-app\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Kotlin: How to create a simple Hello World app<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[214],"tags":[215],"class_list":["post-2943","post","type-post","status-publish","format-standard","hentry","category-kotlin","tag-kotlin"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=2943"}],"version-history":[{"count":8,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2943\/revisions"}],"predecessor-version":[{"id":2962,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2943\/revisions\/2962"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=2943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=2943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=2943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}