<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: CodeGym</title>
    <description>The latest articles on Forem by CodeGym (@codegym_cc).</description>
    <link>https://forem.com/codegym_cc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F137939%2Fa63ab805-9b78-4088-9387-895ae3325e75.jpg</url>
      <title>Forem: CodeGym</title>
      <link>https://forem.com/codegym_cc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codegym_cc"/>
    <language>en</language>
    <item>
      <title>Learn How To Code Your First Game In Java With CodeGym</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Fri, 23 Aug 2019 15:34:49 +0000</pubDate>
      <link>https://forem.com/codegym_cc/learn-how-to-code-your-first-game-in-java-with-codegym-2220</link>
      <guid>https://forem.com/codegym_cc/learn-how-to-code-your-first-game-in-java-with-codegym-2220</guid>
      <description>&lt;h2&gt;
  
  
  We’ve got a problem, Cap!
&lt;/h2&gt;

&lt;p&gt;Most attempts to learn programming (or something else) on your own simply fail. Every self-taught risk to catch a loss of motivation for various reasons. For example, some coding topics may seem too complicated and incomprehensible. Or, on the contrary, you move so easily that there are doubts that you move in the right direction. It is tough, to estimate your own successes. How to do it? Where to go? And also, rookie programmers very often lose their motivation due to the fact that they do not see the final or even intermediate result of their work.&lt;/p&gt;

&lt;h2&gt;
  
  
  It’s too dark in here… I can’t see the results of my job!
&lt;/h2&gt;

&lt;p&gt;This problem is typical not only among students but among professional programmers as well. Software developers who work on large complicated projects in big teams and make a small piece of code of a huge program. The effect of this piece is not always visible, much more often it just lost there, drowning among the same pieces made by their colleagues.&lt;/p&gt;

&lt;p&gt;Programming students have slightly different problems. Most often they study some topics, solve some tasks to consolidate knowledge divorced from reality, but globally do not see what they have learned and what they actually can or cannot do. In fact, the result is the same as that of professionals: they do not see the result of their efforts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Yep, quite a problem… What should you do?
&lt;/h2&gt;

&lt;p&gt;Dropping your programming learning out isn’t a good idea. The better way is to dilute it with something else. Something interesting for you, where the result will be visible.&lt;/p&gt;

&lt;p&gt;Programmers who work in big outsourcing and product companies very often “entertain” themselves by creating their own projects. We recommend the same method for advanced students. Most often, novice developers write small games based on classic ones, and sometimes they realize their own ideas.&lt;/p&gt;

&lt;p&gt;But what should coding rookies do, those who are not ready for a relatively interesting project on their own? Now on the Internet, you can find enough step-by-step instructions.  Following them, a student creates their own project with the help of more experienced developers. A great example is free to use &lt;a href="https://codegym.cc/projects/games" rel="noopener noreferrer"&gt;CodeGym Game Section&lt;/a&gt;. There you can create your own versions of classical games under the clear guidance of professionals. Now you can try to write your own interpretation of 6 games: Minesweeper, 2048, Snake, Space Invaders, Moon Lander, and Racer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fql9hp1ovdttw2wwq8457.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fql9hp1ovdttw2wwq8457.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To code such game, you need to have only basic knowledge of Java, which can be obtained quite quickly: initial knowledge about classes and objects, basic primitive data types, String, loops and branches, arrays and initial knowledge about the ArrayList structure. The CodeGym authors recommend completing the first 5 to 10 levels of the &lt;a href="https://codegym.cc/quests" rel="noopener noreferrer"&gt;course&lt;/a&gt; to get such knowledge. If you don’t feel confident enough, here is a useful &lt;a href="https://codegym.cc/groups/posts/140-games-section-on-codegym-useful-theory" rel="noopener noreferrer"&gt;theory&lt;/a&gt; that helps you to solve the tasks.&lt;/p&gt;

&lt;p&gt;However, CodeGym &lt;a href="https://codegym.cc/groups/posts/137-new-section-on-codegym--games" rel="noopener noreferrer"&gt;Games section&lt;/a&gt; is apart of the main course and available to everyone, not only for CodeGym students.&lt;/p&gt;

&lt;p&gt;Each game is divided by two dozen subtasks as well as step-by-step instructions. First, you get your subtask and tips, then write your code. When you finish, CodeGym auto validation system is checking your code. If everything is ok, you go to the next step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmu0la0bpahbuf5xzv6gs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmu0la0bpahbuf5xzv6gs.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you complete the last step, you get a ready-to-use game. You are free to publish it on the site, and sharing with your friends or modify the code to improve it or propose something original into old ideas. All the games use simple CodeGym game engine, you can read about it in &lt;a href="https://codegym.cc/groups/posts/138-games-section-on-codegym-game-engine" rel="noopener noreferrer"&gt;this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;CodeGym Games section is a great way to write your first complete game project, modify it and understand how to develop indie projects by yourself. After such exercises, you are ready to continue your learning and to think of your own original projects in the near future.&lt;/p&gt;

&lt;p&gt;More about CodeGym Games: &lt;a href="https://codegym.cc/groups/posts/137-new-section-on-codegym%E2%80%93games" rel="noopener noreferrer"&gt;https://codegym.cc/groups/posts/137-new-section-on-codegym–games&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to code: &lt;a href="https://codegym.cc/projects/games" rel="noopener noreferrer"&gt;https://codegym.cc/projects/games&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First published on &lt;a href="https://www.technotification.com/2019/08/learn-how-to-code-your-first-game-in-java.html" rel="noopener noreferrer"&gt;Technotification&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>Top 10 + 1 common mistakes every Java learner makes</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Thu, 30 May 2019 13:31:40 +0000</pubDate>
      <link>https://forem.com/codegym_cc/top-10-1-common-mistakes-every-java-learner-makes-4b6i</link>
      <guid>https://forem.com/codegym_cc/top-10-1-common-mistakes-every-java-learner-makes-4b6i</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F1%2AJwxyCPl0o8-skeAj01XzMA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1200%2F1%2AJwxyCPl0o8-skeAj01XzMA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is said, “Your friend will swallow your mistakes, your enemy will present them on a plate”. I am definitely not your enemy, but I want to present you some mistakes, specific to each Java beginner student and I will do it right here on this blogging “plate”. Sure there are only some of them, I collected from CodeGym.cc courses analytical System. If you don’t know yet, &lt;a href="https://codegym.cc/" rel="noopener noreferrer"&gt;CodeGym&lt;/a&gt; is a practical Java course from scratch to upper intermediate. &lt;/p&gt;

&lt;p&gt;So, here they are.&lt;/p&gt;

&lt;h2&gt;
  
  
  0. Assignment or comparison (= or ==)?
&lt;/h2&gt;

&lt;p&gt;This is one of the first mistakes of students who learn Java from scratch. It is easy to confuse that &lt;strong&gt;=&lt;/strong&gt; is an assignment operator whereas &lt;strong&gt;==&lt;/strong&gt; is a relational operator. That’s natural mistake because in math “=” is closer to Java’s “&lt;strong&gt;==&lt;/strong&gt;”, than to Java’s “=”. Usually compiler catch such mistakes, however they could be hidden from it. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boolean myBoolean; 
If (myBoolean = true) {
doSomething; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See? This block will be true anyway because you assign it to be true…&lt;/p&gt;

&lt;h2&gt;
  
  
  1.  Comparing Strings with == operator.
&lt;/h2&gt;

&lt;p&gt;A while after you did your first Java tasks (usually there are some console output and arithmetical problems) you learn String class. However beginners often forget that particular string isn’t a representative of a primitive type like char or int, it’s an object. You can’t compare objects using &lt;code&gt;==&lt;/code&gt; operator. Remember using the &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.Object-" rel="noopener noreferrer"&gt;string.equals(Object object)&lt;/a&gt; function to compare strings (or other objects), not the &lt;code&gt;==&lt;/code&gt; operator. Equals checks the contents of the string, while the &lt;code&gt;==&lt;/code&gt; operator checks whether the references to the objects are equal.&lt;/p&gt;

&lt;p&gt;To be honest with you, string constants are usually “interned”. That means two constants with the same value can actually be compared with &lt;code&gt;==&lt;/code&gt;, but don’t really rely on that.Use .equals.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Different names of Class and the file where its code is.
&lt;/h2&gt;

&lt;p&gt;This mistake was very popular (maybe even leader of all) some years ago. Now even beginners use modern IDE’s and it is on the verge of extinction. Anyway, it is useful to bear in mind that in Java file name and class name should be the same. If you name your file, for example, Test.java and write there some class CodeGymTest code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//File name: Test.java 

public class CodeGymTest { 
   public static void main(String[] args) { 
        System.out.println("Hello world"); 
   } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll get the next output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Test.java:9: error: class CodeGymTest is public, should be
                    declared in a file named CodeGymTest.java
public class CodeGymTest 
^
1 error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By the way, if you remove &lt;strong&gt;public&lt;/strong&gt; modifier from the class name, your program will run. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Accessing non-static members from the main method or other static methods
&lt;/h2&gt;

&lt;p&gt;Pretty often beginners don’t know how to work with static context. Static variable is the one shared among all instances of a class. Therefore, there’s only one copy of it which is shared by all objects. So we can’t work with non-static variable in a “static way”. This mistake usually happens in the &lt;code&gt;main()&lt;/code&gt; method (which is static!), when novice programmer attempts to access an instance variable or method. If you try such code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MyExample {
    public String myString;  

public static void main(String[] args) {
        myExample.String = “non static String”;    
}
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’ve got compile error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;non-static variable number cannot be referenced from a static context.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What should we do to avoid this? First of all we can make our variable static, but it is not always meets the program purpose. One of the solutions is to create an object of our class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MyExample {
    public String myString;  

public static void main(String[] args) {
MyExample myExample = new MyExample(); 

        myString = “non static String”;    
}
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember, you can work with static variables or methods from static or non-static context. You can work with non-static elements using object reference.   &lt;/p&gt;

&lt;h2&gt;
  
  
  4. Array index is out of Array bounds
&lt;/h2&gt;

&lt;p&gt;It is an extremely popular mistake among beginner programming students. The reason of such popularity is, that the very first more or less complicated tasks are about arrays and cycles. Very easy example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] name = { "Snoopy", "Woodstock", "Charlie Brown" };
for (int i = 0; i &amp;lt;= name.length; i++) {
    System.out.println(name[i]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cycle starts from zero element “Snoopy”, then goes to the first “Woodstock” and to the second one “Charlie Brown”… and tries to print the third element, but we don’t have it (our “third” is a “second” such as “first” is number zero). Here the mistake is pretty obvious, but it is not always like this. &lt;/p&gt;

&lt;p&gt;Cycles and arrays are pretty tough for rookies. However, practice makes diamonds. &lt;strong&gt;There are hundreds Arrays &amp;amp; Cycles tasks on CodeGym. Try to solve them (it is free for now on!) to get confident skills.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Puting “;” wrong in cycles or conditionals
&lt;/h2&gt;

&lt;p&gt;In the block below you don’t print any of array’s members. First, the cycle is ending with “;” so nothing happens. Even more: the program won’t work because your int i works only inside the cycle and it ends with “;”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args)  {

            int [] myArray = {2,5,7};
            for (int i=0; i&amp;lt;3; i++);
            {
                System.out.println(myArray[i]);
            }
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args)  {

            int [] myArray = {2,5,7};
            int i = 0;

            for (i=0; i&amp;lt;3; i++);
            {
                System.out.println(myArray[i]);
            }
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ve got &lt;code&gt;java.lang.ArrayIndexOutOfBoundsException&lt;/code&gt;, because System.out.println tries to print element #3 and only this one, but we don’t have such an array member. The last one is the second and it is 7. &lt;/p&gt;

&lt;p&gt;The same story with ; and conditions. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args)  {

            int [] myArray = {2,5,7};
           if (myArray[0] &amp;gt; myArray[1]);
            System.out.println("it is");
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The condition is not satisfied here, but “it is” would be printed because of “;” after if construction. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you start your CodeGym learning, you’ll get your first coding tasks with cycles on the level 4 &lt;a href="https://codegym.cc/quests/QUEST_JAVA_SYNTAX" rel="noopener noreferrer"&gt;Java Syntax&lt;/a&gt; quest. I guess you’ll forget about this kind of mistakes solving enough problems.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Missing the ‘break’ Keyword in a Switch-Case construction
&lt;/h2&gt;

&lt;p&gt;The embarrassing thing about missing a “break” keyword is that there aren’t compiler error. However your code works the wrong way.&lt;/p&gt;

&lt;p&gt;Look at the code example below, where we forgot to put a break in “case 0”. The program will work but it prints both “0” and “1” because switch construction ends its work with break.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void switchCasePrimer() {
        int counting = 0;

        switch (counting) {
            case 0:
                System.out.println("0");
            case 1:
                System.out.println("1");
                break;
            case 2:
                System.out.println("2");
                break;
            default:
                System.out.println("Default");
        }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This rule has an exception. &lt;strong&gt;Switch&lt;/strong&gt; block can finish its work with &lt;strong&gt;return&lt;/strong&gt; operator&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class test {
    public static void main(String[] args) {
        System.out.println(showSwitch(1));
    }

    public static int showSwitch(int condition) {
        switch (condition) {
            case 1:
                System.out.println(1);
                return 1;
            case 2:
                System.out.println(2);
                return 4;
            case 3:
                System.out.println(3);
                return 8;
            default:
                System.out.println("default");
                return 256;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case switch finishes its job right after case 1.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Mess with pass by value and pass by reference
&lt;/h2&gt;

&lt;p&gt;If you pass a primitive data type, such as a char, int or double, to a method, you are passing by value. That means a copy of the data type would be duplicated and passed to your method. If that data is modified inside the method, there are no influence on the “original” data outside the method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {

    public static void swap(int i, int j)
    {
        int temp = i;
        i = j;
        j = temp;
        System.out.println("from swap method i = " + i + ", j = " + j);
    }


    public static void main(String[] args) {


        int i1 = 1;
        int j1 = 2;
        swap(i1,j1);
        System.out.println("from main method i = " + i1 + ", j = " + j1);

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you pass a Java object, for example, array or string to a method, that means you are passing a reference (address of your data), not a duplicate. So if you change the data in method, it will be changed outside it as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {

    static int[] outer = new int[3];

    public static void swap(int[] array) {
        System.out.println("(swap) Before swap :" + Arrays.toString(array));
        int first = array[0];
        int last = array[array.length - 1];
        array[0] = last;
        array[array.length - 1] = first;
        System.out.println("(swap) After swap :" + Arrays.toString(array));
    }


    public static void main(String[] args) {
        outer[0] = 0;
        outer[1] = 1;
        outer[2] = 2;

        swap(outer);

        System.out.println("(main) After swap :" + Arrays.toString(outer));
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Attempt to work with uninitialized field or variable
&lt;/h2&gt;

&lt;p&gt;Work with an object type without initialization is pretty dangerous.&lt;/p&gt;

&lt;p&gt;Class variables are initialized by the default value (0 for int, 0.0 for double, false for boolean, null for non-primitive types (objects).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Test2 {
    static String test;

    public static void main(String[] args) {

     System.out.println(test);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The output is:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you work with a local method variables you need to initialize them manually, otherwise you’ll get a compilation error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Test2 {

    public static void main(String[] args) {
        String test2;
     System.out.println(test2);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The output is:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error:(6, 28) java: variable test2 might not have been initialized
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. Forgetting about integer division
&lt;/h2&gt;

&lt;p&gt;If you divide one int to another int, you’ll get int again. So ½ = 0, not 0.5 in this case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

        int i = 1;
        int j = 2; 
  int k = i/j; //here we’ve got 0 
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may learn about division and real types from &lt;a href="https://codegym.cc/quests/QUEST_JAVA_SYNTAX" rel="noopener noreferrer"&gt;Java Syntax quest&lt;/a&gt; of CodeGym and solve a lot of coding tasks related to the topic.   &lt;/p&gt;

&lt;h2&gt;
  
  
  10. Mess with order of calling constructors in Child objects
&lt;/h2&gt;

&lt;p&gt;When you try to create an instance of a Child class, Child is called first, and Parent after it. Order of constructors execution in Parent-Child relationship builds from basic (Parent) class to inherited (Child).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Test3 {
    static class Parent {
        Parent() {
            System.out.println("a Parent is created");
        }
    }
    static class Child extends Parent {
        Child(){
            System.out.println("a Child is created");
        }
    }

    public static void main(String[] args) {
        Child child = new Child();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a Parent is created
a Child is created
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If you join CodeGym, you’ll meet OOP and inheritance in &lt;a href="https://codegym.cc/quests/QUEST_JAVA_CORE" rel="noopener noreferrer"&gt;Java Core Quest&lt;/a&gt;. There are really many tasks of this topic. So sooner or later you’ll get a subtle understanding of OOP principles.&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusions
&lt;/h1&gt;

&lt;p&gt;I presume, there is no article that can accumulate all the potential mistakes of newbie Java students. Nevertheless, such lists are very useful to avoid the popular mistakes… and have time to find less trivial issues! Praemonitus, praemunitus (* forewarned is forearmed).&lt;/p&gt;

&lt;p&gt;However the most important step is not avoiding mistakes but practice coding itself. &lt;strong&gt;That’s why we created &lt;a href="https://codegym.cc/" rel="noopener noreferrer"&gt;CodeGym&lt;/a&gt;, Java Core course with more than 1000 practicing tasks, fun lectures and instant feedback on your improvements. When you make a mistake, popular or rare, CodeGym System warning you about it and gives you recommendations to avoid it. Try the course by yourself, it is free for now on.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Don’t stop practice and you become a better software developer for sure. Good luck with your learning!  &lt;/p&gt;

&lt;p&gt;P.S.: Have you ever made mistakes from this article? What mistakes have you faced with during your learning? Tell us in comments!&lt;/p&gt;




&lt;p&gt;The post by Alex Yelenevych, Computer software industry enthusiast and CMO at CodeGym.cc. First was published on &lt;a href="https://medium.com/codegym/top-10-1-common-mistakes-every-java-learner-makes-47e5dc082c6b" rel="noopener noreferrer"&gt;CodeGym Medium blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>CodeGym.cc: Play a Game to Learn Java Programming</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Thu, 25 Apr 2019 15:23:51 +0000</pubDate>
      <link>https://forem.com/codegym_cc/codegym-cc-play-a-game-to-learn-java-programming-ibe</link>
      <guid>https://forem.com/codegym_cc/codegym-cc-play-a-game-to-learn-java-programming-ibe</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-1-compressed-770x515.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-1-compressed-770x515.jpg" alt="pic0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A gamified education is ready to kick the boring studying out of our lives. Today let’s take a look on CodeGym.cc, a gamified course, where one can learn how to code in Java from scratch.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But first of all, why choose Java among dozens of languages to start a career? The statistics tell no lies. Java has been on top positions of the programming languages popularity rankings for the past 20 years. Today there are more than 10 millions of Java developers worldwide, and there’s enough of space for the newcomers.&lt;/p&gt;

&lt;p&gt;Java is everywhere: Big Data developments, Internet of things, enterprise solutions, and even space exploration. It is a flexible, secure, cross-platform and multi-purpose programming language for writing programs for any devices.&lt;/p&gt;

&lt;p&gt;What’s more important, you can learn programming anywhere thanks to a wide range of online courses. Let’s see, what’s the &lt;a href="https://codegym.cc/" rel="noopener noreferrer"&gt;best way to learn Java&lt;/a&gt; coding and is it possible not to lose your motivation when you learn alone.&lt;/p&gt;

&lt;p&gt;CodeGym.cc is a relatively new online platform for mastering Java programming. Here are five key features of the course, which may help in learning how to code in Java and become confident at it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A gamified Java tutorial for the beginners
&lt;/h2&gt;

&lt;p&gt;CodeGym.cc is geared towards learners with zero experience in programming. Though students with a developer’s background will surely embrace many features of this platform.&lt;/p&gt;

&lt;p&gt;The course is designed with numerous gaming technologies to bring a better learning experience, and help users in clearing the major obstacle — a lack of motivation in self-education. In this case, a futuristic plot, the vivid characters and a way of explaining complicated concepts through real-life examples are pushing students to move forward.&lt;/p&gt;

&lt;p&gt;CodeGym’s storyline expands in the future. It is the year 3018 when the spaceship crashes on a “wild” planet with robots. The crew needs to teach them programming to clear the rocks and free the ship. A user’s character is a young robot called Amigo, who will learn Java fundamentals by passing &lt;strong&gt;four educational quests&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Each quest guides a user through a certain general subject like Java Core, Java Syntax, Java Collections, and Java Multithreading. Each quest consists of 10 levels with 12-13 lectures and few dozens of different tasks.&lt;/p&gt;

&lt;p&gt;To become a programmer you need to code — that’s the motto of the course. And this is exactly what you need to do approximately 80% of the time you spend on this online platform. If you want to progress and open new lessons, you need a “dark matter”, which you receive for completing tasks.&lt;/p&gt;

&lt;p&gt;Each new subject in Java is explained by one of the crew’s members, while captain John Squirrels is responsible for bringing a dash of motivation at the beginning of each level. All lectures are written in the conversational format with jokes and easy to understand examples. Imagine you’re reading a funny story and learning Java at the same time. Sounds cool, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Up to 500+ hours of practice and coding from the first lesson
&lt;/h2&gt;

&lt;p&gt;Again, coding skill is sharpened only through practice. It’s almost impossible to memorize a new piece of theory without trying to implement what you’ve just learned immediately.&lt;/p&gt;

&lt;p&gt;CodeGym offers powerful capabilities to practice Java programming. Overall, there are 1200+ tasks of three different types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;writing your own code&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;fixing the source code&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;retyping code parts&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The course accustoms students to use professional Java developers’ tools like IntelliJ IDEA. Though it’s still handy to solve tasks online directly on CodeGym.cc website. Each task is presented in a frame (web IDE) with different tabs. The first one contains the task requirements:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-2-1024x566.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-2-1024x566.png" alt="pic1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you read them carefully, click on the “Solution” tab to write your code or fix the source code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-3-1024x564.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-3-1024x564.png" alt="pic2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click on the “Verify” button to check your solution:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-4-1024x265.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-4-1024x265.png" alt="pic3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will get the result in a matter of seconds, right after the validator matches the solution with the task requirements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-5-1024x566.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-5-1024x566.png" alt="pic4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each successful solution brings you a few points of the “dark matter”. Of course, more complicated tasks bring you more reward.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Useful tips on improving your code
&lt;/h2&gt;

&lt;p&gt;You rarely think about the style of the code while you learn, and it’s okay. First of all, you need to get the grip of Java fundamentals. But the style of the code is something that differs a “pro” from a starter. Click the “Code analysis” button after you complete the solution to get some recommendations from the virtual mentor at CodeGym and improve your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Java fundamentals with the real-life examples
&lt;/h2&gt;

&lt;p&gt;Let’s be honest, it’s possible to learn Java programming endlessly. A great software developer will study something new for life to broaden his stack of technologies and follow the trends.&lt;/p&gt;

&lt;p&gt;But you need far less theoretical learning to simply start coding and get the Junior position. At CodeGym’s course, you’ll get a minimum theory within a short timeframe to form a strong basis for further profession growth.&lt;/p&gt;

&lt;p&gt;Each lecture in the course is short and easy to read. It takes 5 to 10 minutes to read the new subject and move straight to the tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. A growing and helpful community
&lt;/h2&gt;

&lt;p&gt;Need a hint on solving a tricky task? Of course, you’ll need it someday. There’s a “Help” section at CodeGym, where you can discuss any task and get explanations from other students and skilled software developers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-6-1024x424.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.technotification.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fpic-6-1024x424.png" alt="pic5"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, you can discuss almost any subject from the programming field in the “Groups” sections of CodeGym. It’s early to say about CodeGym as a great source of Java programming content, but there is plenty of additional material, which enhances the course itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CodeGym is a course for learning Java programming through practice in a fancy way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hands-on practice, plenty of cool tasks with instant verification and tips on code improvement;&lt;/li&gt;
&lt;li&gt;entertaining gamified learning instead of boring lectures and video tutorials;&lt;/li&gt;
&lt;li&gt;a strong motivation to continue studying until you master coding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;requires the extra reading to get a thorough understanding of Java language;&lt;/li&gt;
&lt;li&gt;as for now, isn’t fully adjusted for studying on mobile devices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Was published on &lt;a href="https://www.technotification.com/2019/04/play-game-to-learn-java-codegym.html" rel="noopener noreferrer"&gt;Tech Notification blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>The Best Way To Learn Java Programming</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Tue, 09 Apr 2019 10:09:51 +0000</pubDate>
      <link>https://forem.com/codegym_cc/the-best-way-to-learn-java-programming-2p2c</link>
      <guid>https://forem.com/codegym_cc/the-best-way-to-learn-java-programming-2p2c</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffojblu2ghv2k3pmdx7bt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffojblu2ghv2k3pmdx7bt.png" alt="How to learn Java successfully" width="800" height="417"&gt;&lt;/a&gt;&lt;br&gt;
There are plenty of compelling reasons to learn Java coding, even if you're a beginner. Java is a popular programming language, known for its reliability, versatility, and backwards compatibility (meaning it works with older legacy systems). It can also run on almost every computer without changing behavior.&lt;/p&gt;

&lt;p&gt;But is Java hard to learn? The simple answer is that yes, it can be tricky. As you learn Java programming, you'll encounter some simple concepts like variables and functions, but there are also more abstract, complex ones like objects, bringing inheritance, and polymorphism that can be difficult to understand. Java also changes on a regular basis, with new features being added from time to time.&lt;/p&gt;

&lt;p&gt;But even though there's a learning curve, it's smoother when you know some basic tips for how to learn Java coding. Once you get the hang of some basics and become fluent at a beginning level, it's much easier (and more enjoyable) to learn the complex topics.&lt;/p&gt;

&lt;p&gt;In this special sponsored post in partnership with &lt;a href="https://codegym.cc/" rel="noopener noreferrer"&gt;CodeGym&lt;/a&gt;, you'll discover the most effective and best ways to learn Java successfully, plus one of the best resources to learn Java for free. If you're unsure how to learn Java as a beginner, or have struggled to learn Java from scratch in the past, this article is for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Should I Learn Java?
&lt;/h2&gt;

&lt;p&gt;Before we get into the best ways to learn Java programming, there's a more pressing question: why learn Java in the first place?&lt;/p&gt;

&lt;p&gt;Java is a great choice for career-oriented beginners because it's a skill that's in high demand (&lt;a href="https://www.zdnet.com/article/three-billion-devices-run-java-yeah-but-do-they-like-it/" rel="noopener noreferrer"&gt;three billion devices run Java!&lt;/a&gt;), which means more job/internship opportunities. Evidence suggests that 90% of Fortune 500 companies use Java for building applications and back-end systems. And it's a financially lucrative career option, with the average Java developer earning &lt;a href="https://www.indeed.com/salaries/Java-Developer-Salaries" rel="noopener noreferrer"&gt;$102,514 per year&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can use Java to build a variety of platforms and applications for different devices, including laptops, computers, gaming consoles, car navigation systems, Blu-ray players, medical monitoring devices, lottery terminals, parking meters, etc. This versatility makes the language exciting and unique, since the options for specialization are endless.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---xv93VhU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/Java-1024x684.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---xv93VhU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/Java-1024x684.jpeg" alt="Java" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's worth noting that Android apps are also built using Java, opening up opportunities not just in web and software development, but also mobile development.&lt;/p&gt;

&lt;p&gt;Finally, Java has a strong community that can provide support as you're learning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2nd largest StackOverflow community&lt;/li&gt;
&lt;li&gt;4th largest meetup community (there are over 1,400 Java Meetup groups, totaling over 580,000 members worldwide)&lt;/li&gt;
&lt;li&gt;2nd most-tagged language on GitHub (over 1.5 million Java projects live on GitHub)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ultimately, Java might not be the easiest language to learn, but there are many reasons why it's worth buckling down to the task.&lt;/p&gt;

&lt;h2&gt;
  
  
  5 Best Ways To Learn Java Successfully
&lt;/h2&gt;

&lt;p&gt;Now that we've convinced you to start learning Java (or pick it back up), you're probably wondering what's the best way to learn Java successfully.&lt;br&gt;
We've got you covered! Let's take a look at five tips for how to learn to code in Java and keep going even when things get tough. Along the way you'll learn about &lt;a href="https://codegym.cc/" rel="noopener noreferrer"&gt;CodeGym&lt;/a&gt;, one of the best resources out there to start learning Java for free in a successful, sustainable way.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Balance Between Theory And Practice
&lt;/h3&gt;

&lt;p&gt;Some theory is good to build yourself a knowledge foundation, but avoid too much theory at the expense of little practice. Reading a lot of Java books won't help if you don't actually write any programs. Don't try to understand everything at once: read a bit at a time and then code, code, and code! You'll learn as you go, and things will click as you actually use the concepts in a hands-on exercise.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JVLI-9SI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/CodeGym_Screen.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JVLI-9SI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/CodeGym_Screen.jpg" alt="CodeGym screen1" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's why CodeGym is 80% focused on practice and 20% on theory. The course can provide complex help with the theoretical part of your education (Java syntax, OOP, structures, multithreading, etc.), without getting you too bogged down in theory with nothing to show for it.&lt;/p&gt;

&lt;p&gt;After you solve all 1200+ of the tasks on CodeGym, you'll walk away with about 500 hours of actual programming experience under your belt.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Schedule Your Learning Experience And Set Milestones And Achievable Goals To Stay Focused
&lt;/h3&gt;

&lt;p&gt;Jumping from skill to skill is not usually an effective way to learn. It's best to dive deep into one language at a time so you don't get distracted or confuse one language with another. It's like trying to learn Spanish and Italian at the same time - you'll probably end up speaking some kind of hybrid.&lt;/p&gt;

&lt;p&gt;Once you've chosen to learn a language like Java, keep your momentum by working through your chosen curriculum seven days a week. Even if it's only for half an hour at a time, committing to coding every day will help solidify the habit and make it feel like a normal part of your routine.&lt;/p&gt;

&lt;p&gt;To stay focused when motivation is low, remind yourself why you want to learn Java. Do you want to become a full-time developer? Build your own app? Determine your goals and use them to keep you on track.&lt;/p&gt;

&lt;p&gt;Using time management strategies will also make it much less stressful to carve out time to learn in your busy life.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F868paSL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/codegym-course-timeline-1024x562.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F868paSL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/codegym-course-timeline-1024x562.png" alt="CodeGym screen2" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CodeGym's course is helpful in this way because it sets milestones for you. The course is divided into a clear roadmap and timeline of what to work on, and sets achievable bite-size goals for you along the way.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Use Gamification To Stay Motivated
&lt;/h3&gt;

&lt;p&gt;Not everyone can successfully learn from books and lectures alone. Gamification works by making the learning experience much more engaging, fun, and interactive. You'll look forward to sitting down and completing tasks instead of feeling intimidated and overwhelmed. It's also a lot harder to get distracted when you're immersed in a game!&lt;/p&gt;

&lt;p&gt;This is one of the main reasons that CodeGym is ideal for those seeking how to learn Java with no programming experience - their gamification is on point:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CodeGym plays out like a video game; when you solve a problem correctly, you get "dark matter" (the points you need to open the next lecture or the next level)&lt;/li&gt;
&lt;li&gt;You play as an anthropomorphic robot named Amigo, and you go through the course level by level, collecting and spending dark matter&lt;/li&gt;
&lt;li&gt;The course/game is story-based and involves space travel, extraterrestrial life, and robots&lt;/li&gt;
&lt;li&gt;It's divided into 40 levels (4 quests with 10 levels), with each level including about 15–30 coding tasks, 10–20 Java lectures, and motivation articles to keep you going - even when things get tricky&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ja6KCdxZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/codegym-gamification-1024x542.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ja6KCdxZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/codegym-gamification-1024x542.png" alt="CodeGym screen3" width="800" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By making it into a game, you'll basically trick yourself into learning to code!&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Communicate With Other Java Students And Developers + Ask Questions
&lt;/h3&gt;

&lt;p&gt;You'll learn more effectively if you work closely with like-minded people. Plus, forming connections will improve your confidence and accelerate your learning.&lt;/p&gt;

&lt;p&gt;When times get tough, asking the right questions helps you solve tricky tasks and complete complicated projects when you might give up otherwise. Be sure to ask specific questions instead of "something went wrong, can you help?" Don't be embarrassed that you don't know the answer.&lt;/p&gt;

&lt;p&gt;Building a sense of community for yourself is also important for staying motivated. Learning to code is hard, but knowing that you're not doing this alone helps!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0SvtVx64--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/codegym-help-forum-1024x572.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0SvtVx64--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://mk0learntocodew6bl5f.kinstacdn.com/wp-content/uploads/2019/03/codegym-help-forum-1024x572.png" alt="CoswGym screen4" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you've built a foundation of knowledge, you can give back to the community by sharing tips of your own. You don't even have to wait until you're an expert, because teaching and mentoring someone else can actually help you retain information better and learn faster.&lt;/p&gt;

&lt;p&gt;If you choose to learn with CodeGym, they have a community of students in their help section. Here, students ask for hints, help to break through roadblocks, and advice for finding out what they did wrong in their code.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Start Building An Online Portfolio
&lt;/h3&gt;

&lt;p&gt;As you learn, it's extremely valuable to build real projects and give others a chance to see your work. When you're ready to apply for Java developer jobs or take on freelance projects, you'll already have a portfolio ready to show potential employers or clients.&lt;/p&gt;

&lt;p&gt;One popular option for developers is to create a GitHub account and post your projects there. Or, you could build your own portfolio website. Having a portfolio of your own also lets you look back with pride on the work you've accomplished.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Now you're armed with the strategies and techniques to help you learn Java the right way. Overall, the keys to learning Java are practice and consistency - and it doesn't hurt to keep it fun!&lt;/p&gt;

&lt;p&gt;I really recommend starting your journey by &lt;a href="https://codegym.cc/login" rel="noopener noreferrer"&gt;signing up for CodeGym&lt;/a&gt; - completing the first quest is totally free, so you can try it out before moving on to the next quests. What better way to get your start in Java?&lt;/p&gt;

&lt;p&gt;Previously was published on &lt;a href="https://learntocodewith.me/posts/learn-java/" rel="noopener noreferrer"&gt;LearnToCodeWith.me blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>OOP Concepts in Java</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Tue, 09 Apr 2019 09:13:08 +0000</pubDate>
      <link>https://forem.com/codegym_cc/oop-concepts-in-java-44c9</link>
      <guid>https://forem.com/codegym_cc/oop-concepts-in-java-44c9</guid>
      <description>&lt;p&gt;One of the strongest points of Java is OOP or Object Oriented Programming. That’s the reason why this language has became so popular and suits really well for projects of any scale.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2Fe5867c90-24ee-4094-a9d6-e7c982300b79%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2Fe5867c90-24ee-4094-a9d6-e7c982300b79%3Fsize%3D0" alt="OOP concepts in Java"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;What is Object Oriented Programming? It is not a magic but it looks like magic if you really get in to it. OOP is about how to build your software. A concept or rather a bunch of concepts that allows you to construct some specific interactions and relations between Java objects for effective development and usage of software.  &lt;/p&gt;

&lt;p&gt;Сlassical version includes 3 + 1 main OOPs concepts. Let’s start with the classics.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The Object&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Objects in Java as well as real-world objects have two characteristics, state and behavior.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example object Human has state (name, gender, sleeping…) and behavior (studying Java, walking, talking...). Any Java object stores its state in fields and exposes its behavior through methods&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Encapsulation
&lt;/h2&gt;

&lt;p&gt;Data encapsulation is hiding internal data from the outside world, and accessing it only through publicly exposed methods.What does that mean? What data, hiding from whom? Hiding means restriction direct access to data members (fields) of a class.&lt;/p&gt;

&lt;h3&gt;
  
  
  How it works in Java:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Fields are set to private&lt;/li&gt;
&lt;li&gt;Each field of class gets two special methods: a getter and a setter. Getter methods return the field. Setter methods let you change the value of the field in non-direct but legal way.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example of encapsulation, Java code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Student {
private int age;
private String name;

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

public class Test{
public static void main(String[] args) {
Student firstStudent = new Student();
firstStudent.setName("John");
//now you can’t do this:  firstStudent.name = “John”, the name field is private!
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why you should do it?
&lt;/h3&gt;

&lt;p&gt;The main reason is simplification of your code changes. Imagine, you have an application for Hockey School and there is a class &lt;code&gt;HockeyStudent&lt;/code&gt; with two fields: name and age of a student when he joined school. Something like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class HockeyStudent {
public String name;
public  int ageOfEnrollment;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Public &lt;code&gt;ageOfEnrollment&lt;/code&gt;, no getters or setters… This class is used by many other classes and everything was ok before one guy said, that the int age is not enough. Some hockey players in group are almost one year older than others so it would be more convenient to apart them on two groups depending upon the month they were born. So new field &lt;code&gt;ageOfEnrollment&lt;/code&gt; should be array int[][] the first number is for full years and the second is for months. Now you should refactor all code that uses class &lt;code&gt;Student&lt;/code&gt;! However if your &lt;code&gt;ageOfEnrollment&lt;/code&gt; is private and you have getters and setters everything gets easier. If the requirement for setting the age of a student changes, just update the logic in the setter method &lt;code&gt;setAgeOfEnrollment()&lt;/code&gt; and your classes may continue using &lt;code&gt;Student&lt;/code&gt; without problems! &lt;/p&gt;

&lt;p&gt;This example is somewhat artificial, but I hope it explains why using encapsulation is a great idea. &lt;/p&gt;

&lt;h2&gt;
  
  
  Inheritance
&lt;/h2&gt;

&lt;p&gt;This principle is more understandable even without practicing. Don’t repeat yourself (DRY) could be the motto of inheritance concept. &lt;/p&gt;

&lt;p&gt;Inheritance lets to create a child class that inherits the fields and methods of the parent class without redefinition them. Sure you can override the fields and methods of the parent class in child class, but it’s not a necessity. Also you can add new states and behaviors in child class. Parent classes sometimes are called superclasses or base classes, and child classes are known as subclasses. Java &lt;code&gt;extends&lt;/code&gt; keyword uses to implement the principle of inheritance in code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works in Java:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a Parent class.&lt;/li&gt;
&lt;li&gt;Create a Child class using &lt;code&gt;extends&lt;/code&gt; keyword.&lt;/li&gt;
&lt;li&gt;In Child’s class constructor use &lt;code&gt;super(parentField1, parentField2,...)&lt;/code&gt; method to inherit the parent’s fields.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Constructor is a special method to initialize the newly created object. Constructor has the same name as its class name. There are two types of constructors: default (no-arg constructor) and parameterized constructor. Class must have at least one constructor (it is always is by default) and it can have a lot of them.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Every time you create a new object you call its constructor. In the example above the line&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Student firstStudent = new Student();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;You call the default constructor&lt;/em&gt; &lt;code&gt;Student()&lt;/code&gt; &lt;em&gt;of class&lt;/em&gt; &lt;code&gt;Student&lt;/code&gt; &lt;em&gt;using word&lt;/em&gt; &lt;code&gt;new&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some rules:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;One class could have only one parent.&lt;/li&gt;
&lt;li&gt;One parent class may have many child classes.&lt;/li&gt;
&lt;li&gt;Child class can have its own child classes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example Inheritance, Java code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s create a &lt;code&gt;Phone&lt;/code&gt; class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Phone {
    int price;
    double weight;

//constructor
public Phone(int price, double weight) {
        this.price = price;
        this.weight = weight;
    }

    void orderPhone(){
        System.out.println("ordering phone...");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, there are different type of phones, so let’s create two child classes, one for Android phones and the second for iPhones, and add some fields and methods their parent didn’t have. The fields that their parent has, let’s call in constructors using &lt;code&gt;super()&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java inheritance example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Android extends Phone {

//some new fields
String androidVersion;
int screenSize;

    String secretDeviceCode;

//constructor
    public Android(int price, double weight, String androidVersion, int screenSize, String secretDeviceCode) {
        super (price, weight); //Android inherits Phone’s fields

        //this - reference to the current class object
        //super - reference to the parent class object

        this.androidVersion = androidVersion;
        this.screenSize = screenSize;
        this.secretDeviceCode = secretDeviceCode;
    }

    //new method specific for Android only, but not for Phone class
    void installNewAndroidVersion() {
        System.out.println("installNewAndroidVersion invoked...");

    }

}

public class IPhone extends Phone {
    int price;
    double weight;

    boolean fingerPrint;

    public IPhone(int price, double weight, boolean fingerPrint) {
        super (price, weight, countryProduced);
        System.out.println("IPhone constructor was invoked...");
        this.fingerPrint = fingerPrint;
    }

    void deleteIPhoneFromDb() {
        System.out.println("deleteIPhoneFromDb invoked...");
    }

@Override //This is about polymorphism, see below
void orderPhone(){
        System.out.println("ordering my new iPhone and deleting the old one...");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, once more: in Java inheritance allows you to extend a class with child classes that inherit the fields and methods of the parent class. It’s an excellent way to achieve code reusability. &lt;/p&gt;

&lt;h2&gt;
  
  
  Polymorphism
&lt;/h2&gt;

&lt;p&gt;Polymorphism is the ability of an object to take on different forms or rather to act in different ways. Usually polymorphism in Java happens if a parent class reference is used to refer to a child class object.&lt;/p&gt;

&lt;h3&gt;
  
  
  What does it mean and how it works in Java:
&lt;/h3&gt;

&lt;p&gt;What is polymorphism in Java? In general that means you can use the same method name for different purposes. There are two two types of polymorphism in Java: method overriding (dynamic polymorphism) and method overloading (static polymorphism).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method overriding&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can override parent’s method in child class forcing it to work in different way. Let’s create a parent class Musician with  a play() method. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java Polymorphism example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Musician {
    String name;
    int age;

    //default constructor
    public Musician() {
    }

    //parameterized constructor
    public Musician(String name, int age) {
        this.name = name;
        this.age = age;
    }

    void play() {
        System.out.println("I am playing my instrument...");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Musicians use different instruments. Let’s create two child classes &lt;code&gt;Pianist&lt;/code&gt; and &lt;code&gt;Violinist&lt;/code&gt;. They both will be playing using their own versions of &lt;code&gt;play()&lt;/code&gt; method thanks to polymorphism. For overriding you can use &lt;code&gt;@Override&lt;/code&gt; notation but it is not necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Pianist extends Musician {

    String favoritePianoType;

    public Pianist(String name, int age, String favoritePianoType) {
        super(name, age);
        this.favoritePianoType = favoritePianoType;
    }


    @Override
void play(){
        System.out.println("I am playing piano...");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The violin player could be soloist or orchestra participant. Let’s take it into consideration while overriding our &lt;code&gt;play()&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Violinist extends Musician {
    boolean isSoloist;

public Violinist(String name, int age, boolean isSoloist) {
            super(name, age);
            this.isSoloist = isSoloist;
        }


    @Override
void play(){
if (isSoloist)
        System.out.println("I am playing violin solo...");
else
System.out.println("I am playing violin in Orchestra...");

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s create a &lt;code&gt;Demo&lt;/code&gt; class where we create three objects, one of every class and check out the result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Demo {
    public static void main(String[] args) {
  Musician musician = new Musician();
        Violinist violinist = new Violinist("John", 32,true);
  Pianist pianist = new Pianist("Glen", 30, "Wooden");

        System.out.println("Musician said:");
        musician.play();
        System.out.println("Violinist said:");
        violinist.play();
  System.out.println("Pianist said:");
  pianist.play();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;That’s what we’ve got here:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Musician said:&lt;br&gt;
I am playing my instrument...&lt;br&gt;
Violinist said:&lt;br&gt;
I am playing violin solo…&lt;br&gt;
Pianist said:&lt;br&gt;
I am playing piano...&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every violinist and pianist is a musician, but not vice versa. That means you may use the musician’s play method if you don’t need to create a new one. Or you can call the parent’s method from child’s one using &lt;code&gt;super&lt;/code&gt; keyword. Let’s do it in Pianist’s code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Pianist extends Musician {

    String favoritePianoType;

    @Override
    void play(){
        super.play();
        System.out.println("I am playing piano...");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now let’s call our Demo class. Here the result:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Musician said:&lt;br&gt;
I am playing my instrument...&lt;br&gt;
Violinist said:&lt;br&gt;
I am playing violin solo...&lt;br&gt;
Pianist said:&lt;br&gt;
I am playing my instrument...&lt;br&gt;
I am playing piano...&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method overloading&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Method overloading means using various methods with the same name in the same class. They should be different by number, order, or types of their parameters. Say, pianist can play classics piano and electric piano. To play the last one this musician needs electricity. Let’s create two different &lt;code&gt;play()&lt;/code&gt; methods. The first one without parameters, for wooden instrument, and the second with electricity checker for electric piano.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Pianist extends Musician {

    String name;
    int age;
    String favoritePianoType;

    @Override
    void play(){
        super.play();
        System.out.println("I am playing piano...");
    }
    void play(boolean isElectricity){
        if (isElectricity) {
            System.out.println("Electricity on");
            System.out.println("I am playing piano...");
        }
        else System.out.println("I can't play this without electricity");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By the way, you can use the first &lt;code&gt;play()&lt;/code&gt; method in the second &lt;code&gt;play(boolean)&lt;/code&gt; method this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void play(boolean isElectricity){
        if (isElectricity) {
            System.out.println("Electricity on");
            play();
        }
        else System.out.println("I can't play this without electricity");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s add some lines in our &lt;code&gt;Demo&lt;/code&gt; class to check out our overloading:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Demo {
    public static void main(String[] args) {

        Musician musician = new Musician();
        Violinist violinist = new Violinist("John", 23,true);
        Pianist pianist = new Pianist("Glen", 30, "Wooden");

        System.out.println("Musician said:");
        musician.play();
        System.out.println("Violinist said:");
        violinist.play();
        System.out.println("Pianist said:");
        pianist.play();
        System.out.println("Now pianist tries electronic Piano:");
        pianist.play(true);
        System.out.println("now electricity's gone and electronic Piano player said:");
        pianist.play(false);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Here is the result:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Musician said:&lt;br&gt;
I am playing my instrument...&lt;br&gt;
Violinist said:&lt;br&gt;
I am playing violin solo...&lt;br&gt;
Pianist said:&lt;br&gt;
I am playing my instrument...&lt;br&gt;
I am playing piano...&lt;br&gt;
Now pianist tries electronic Piano:&lt;br&gt;
Electricity on&lt;br&gt;
I am playing my instrument...&lt;br&gt;
I am playing piano...&lt;br&gt;
now electricity's gone and electronic Piano player said:&lt;br&gt;
I can't play this without electricity&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java knows what method should be used according to its parameters and object’s type. That’s polymorphism.  &lt;/p&gt;
&lt;h2&gt;
  
  
  Abstraction
&lt;/h2&gt;

&lt;p&gt;When we describe an object we are trying to build a model of it. For example, we write a racer video game &lt;strong&gt;MyRacer&lt;/strong&gt; with different cars. A player can choose one of them, then update or buy newer.  So… What is a car? A car is pretty complicated thing, but if we are trying to create an arcade racing game (not simulator) we shouldn’t describe all thousands of cogs it contains.&lt;/p&gt;

&lt;p&gt;We need its model, maximal speed, maneuverability, price, color… And maybe that’s enough. That’s a model of a car for this game. &lt;/p&gt;

&lt;p&gt;Later in MyRacer 2 we decided to add tires that affect resilience on a road. Here the model is different because we need more details.      &lt;/p&gt;

&lt;p&gt;Let’s define Data Abstraction as the process of identifying only the important (or required) characteristics of an object and ignoring the irrelevant details. &lt;/p&gt;

&lt;p&gt;There are different levels of abstraction. For example if you are a passenger of a bus, you should know how your bus looks and where it goes but you shouldn’t know how to drive it. If you are a bus driver you don’t need to know how to create a new bus, you should know how to drive it. But if you are a bus constructor you should go onto the lower level of abstraction…The details about the bus  architecture are very important to you. Hope you understand what I mean.     &lt;/p&gt;
&lt;h3&gt;
  
  
  How it works in Java:
&lt;/h3&gt;

&lt;p&gt;Let’s build four level of abstraction in Java or rather in OOP from the lowes (the most particular) to the highest (more abstract).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Lower level of abstraction is a particular &lt;strong&gt;Object&lt;/strong&gt;. It is an entity with a set of characteristics inherent in a specific instance of a class. It has specific field values&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Template for creating objects is a &lt;strong&gt;Class&lt;/strong&gt;. It’s a description of the set of objects of similar properties and internal structure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Abstract class&lt;/strong&gt; is an abstract description of the characteristics of a set of classes (acts as a template for inheritance by other classes). It has a high level of abstraction, therefore, it is impossible to create objects directly from the abstract class, only through the creation of objects from the child classes. Abstract class, may include methods with an implementation but not necessarily.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interface&lt;/strong&gt; is a Java programming language construct within which only abstract public methods and static property constants (final static) can be described. That is, as well as on the basis of abstract classes, it is impossible to generate objects on the basis of interfaces.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Btw, in Java 8 or later you can use in interfaces not only abstract methods and constants, but also default and static methods.&lt;/p&gt;

&lt;p&gt;In Java interface defines a behavior and abstract class creates hierarchy. One interface may implement different classes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java interface example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Human {
    public void struggle();
    public void protect();
}

interface Vulcanian {
int earSharpnessAngle;
    public void emotionOff(boolean isOn);
    public void telepathy();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can implement more than one interface&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Class Spock implements Human, Vulcanian {
public void struggle() {
System.out.println (“I am struggling...”);
}
    public void protect() {
System.out.println(“You are under my protection!”);
}
public void emotionOff(boolean isOn){
If (isOn) {
System.out.println(“I am turning off my emotions”);
isOn= !isOn;
}
}
    public void telepathy() {
System.out.println(“Connecting to your brain... ”);
}

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;That’s all about the main object oriented programming concepts in Java for beginner students.&lt;/strong&gt; Besides the 4 main principles of OOP, there are also association, aggregation and composition in Java. You may call them “additional OOP principles” and they deserve their own article.&lt;/p&gt;

&lt;p&gt;Previously was published on &lt;a href="https://codegym.cc/groups/posts/76-oop-concepts-in-java" rel="noopener noreferrer"&gt;CodeGym blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>Why You Should Learn Java in 2019</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Tue, 09 Apr 2019 08:58:19 +0000</pubDate>
      <link>https://forem.com/codegym_cc/why-you-should-learn-java-in-2019-2nd8</link>
      <guid>https://forem.com/codegym_cc/why-you-should-learn-java-in-2019-2nd8</guid>
      <description>&lt;p&gt;Learning how to code might be slightly scary for the newcomers, and that’s hardly a surprise. It’s not easy to stay cool and smash along millions of programmers globally with zero experience and an intangible idea of your goals and career. Would your education be intense? Yes. Is it too late to try? Of course, not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2F870aaae1-0de5-4426-b013-12dff63445d7%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2F870aaae1-0de5-4426-b013-12dff63445d7%3Fsize%3D0" alt="Why You Should Learn Java in 2019"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You probably look for a rapid progress, if you’re serious about programming, and the language is your basis to start with. Even if you search for the answer to the question, which is the best programming language to learn, you won’t find a unanimous opinion. First of all, every developer will try to “push” you his own choice. Secondly, there’s no such thing as the best language, because they serve different purposes.&lt;/p&gt;

&lt;p&gt;There are at least half a dozen programming languages, which keep the highest positions of different rankings. According to &lt;a href="https://www.tiobe.com/tiobe-index/" rel="noopener noreferrer"&gt;TIOBE Programming Community ranking&lt;/a&gt;, Java firmly keeps the first place with the largest number of searches through the most popular search engines. It is tracked by C, Python and C++ languages. As for GitHub’s Octoverse ranking, the top three most popular languages of all time are Javascript, Java, and Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Java is so popular
&lt;/h2&gt;

&lt;p&gt;Now you’re probably thinking something like: “why exactly do I need Java of all options”? As told before, there will never be a programming language with unchallenged authority. But still, you can make a choice quite easy, if you analyze the long-term benefits of mastering a certain language. Let’s talk about why Java is so popular and why little is going to change in the closest time. &lt;/p&gt;

&lt;p&gt;You may heard something like “Java is too old, it will become out of use in a few years”. Actually, it’s of the same age as other widely used programming languages. The story of its creation begins in the 90s at a Californian company Sun Microsystems. You may know (or remember), that back in the 90s a TV was truly influential in communications and entertainment. For this reason, it inspired many useful progressive inventions. And, by implication, it kickstarted the creation of Java language. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2F5c3dc5b8-fe0c-46e2-a057-67f148851ebf%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2F5c3dc5b8-fe0c-46e2-a057-67f148851ebf%3Fsize%3D0" alt="pic1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It was initially developed for interactive television to let application developers write code once and run it on any platform without the need to decompile it, thanks to JVM (Java virtual machine). For the obvious reason, such flexibility and multiplatform usability can be applied anywhere. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is Java used for
&lt;/h2&gt;

&lt;p&gt;So, nowadays, what is Java used for? Particularly, for a majority of modern demands. Java is object-oriented, class-based, all-purpose language that allows developers to create programs, which are compatible with any devices. It has many benefits for a beginner in programming and for a further career development. Let’s see what’s waiting for a future Java developer step by step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step #1 Learning to code from point zero
&lt;/h3&gt;

&lt;p&gt;One of the main reasons why you should learn Java is because it's quite easy to learn. You don’t even need to be a pro in math to start coding: you simply need to understand the logic. Secondly, it is a high-level language. This means that many processes in Java programming run automatically and you don’t have to delve too deep to create a program that actually works. Referring to a simple example, Java is like a car with automatic transmission: it’s easy to grasp a skill with a little help from your “machine”. &lt;/p&gt;

&lt;p&gt;Even if you have any difficulties in learning Java, you can easily get help from a global community. There are more than 9 millions Java developers in the world, and their online community is vast and dynamic. You can easily find an answer to almost any question, that appears while you study and get useful sources to deepen your knowledge. &lt;/p&gt;

&lt;p&gt;Some programmers say, that Java isn’t the first choice in learning how to code from scratch. Probably, it can be harder for a freshman to learn Java, than other languages. But a hard drill makes an easy battle. Once you learn Java, it will become a handy tool for a great number of tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step #2 Starting as a junior developer
&lt;/h3&gt;

&lt;p&gt;Once you’ve gained core knowledge, you start a career as a programmer on Java: this is what you aspire, don’t you? As a beginner, you’ll feel more confident knowing that Java has a huge number of libraries and frameworks for numerous tasks. As a learner, you write your own routines to get plenty of practice and make sense of programming process. But later, as a developer, you can adjust ready-made solutions to your project. They will help you save time in numerous large-scale projects. Plus everything you need is there for you in a great Java documentation at &lt;a href="https://docs.oracle.com/en/java/" rel="noopener noreferrer"&gt;Oracle&lt;/a&gt; and &lt;a href="https://stackoverflow.com/questions/tagged/java" rel="noopener noreferrer"&gt;Stack Overflow&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2Fef76895f-b8da-484b-bebe-fe28046d0643%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2Fef76895f-b8da-484b-bebe-fe28046d0643%3Fsize%3D0" alt="pic2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step #3 Boosting your career
&lt;/h3&gt;

&lt;p&gt;When you get familiar with the Java Virtual Machine, you can easily use other languages with such a runtime environment. For example, Groovy, Scala, Kotlin and Clojure. So if you want to, you can join as many interesting projects as you wish and enhance the knowledge of the technology stack.&lt;/p&gt;

&lt;p&gt;Anyway, Java itself will always inspire your progress. The latest versions were released within six months of each other, and the newest is coming up in spring, 2019. They are enhanced with new features, which answer the needs of modern enterprises, startups, medium and small-sized businesses. That puts Java developers in a high demand. Hence, they work on promising projects and earn high salaries. According to &lt;a href="https://www.indeed.com/salaries/Java-Developer-Salaries" rel="noopener noreferrer"&gt;Indeed.com&lt;/a&gt;, an average Java developer salary in the U.S. is more than $100 000 per year. &lt;/p&gt;

&lt;p&gt;Why learn Java in 2019? Because you will use all the benefits of a flexible, security-oriented, dynamic language. As told before, Java is among all-time leaders in the programming world. &lt;/p&gt;

&lt;p&gt;Java is used for writing mobile applications, both Android and iOS. You can also choose it to create web pages by compiling to JavaScript (Google Web Toolkit). Considering that nowadays almost all B2C companies need to reach their clients through the mobile channel, there are thousands of projects waiting for you. &lt;/p&gt;

&lt;p&gt;Java is everywhere and in the closest time is expected to become even more important in Big Data and the Internet of things developments. Building platforms and applications for any devices, such as laptops, computers, gaming consoles, navigation systems, monitoring facilities, terminals, etc., makes Java the best programming language to learn in 2019 &lt;/p&gt;

&lt;p&gt;All in all, the short answer fotohe question what is Java used for is “to create a mainstream software any business needs”.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to learn Java
&lt;/h2&gt;

&lt;p&gt;If you want to learn to code on Java, be sure you are ready to devote at least 3 to 6 month to a self-education and study daily. You probably already know, that programming is about practice, so you should have three times or even four times more coding than researching. In such a way you will get skilled at coding and won’t fall into an endless “rabbit-hole” of programming theory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2Fb632a951-59f4-41a0-af37-4739bb56727a%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodegym.cc%2Fapi%2F1.0%2Frest%2Fimages%2F10000017%2Fb632a951-59f4-41a0-af37-4739bb56727a%3Fsize%3D0" alt="pic3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to know how to learn Java fast, these tips are for you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set your goals in a career by answering a question “Why exactly do I need Java”.&lt;/li&gt;
&lt;li&gt;With this context, create your personal educational plan with a schedule.&lt;/li&gt;
&lt;li&gt;Choose tools to help your needs: books, courses, coding platforms, etc.&lt;/li&gt;
&lt;li&gt;Find additional sources of information: media, forums, Java communities — everything to keep you up to date.&lt;/li&gt;
&lt;li&gt;Practice a lot: you need hundreds of hours of coding before it becomes your habit.&lt;/li&gt;
&lt;li&gt;Don’t get stuck on something you don’t quite understand — go on with your study and practice.&lt;/li&gt;
&lt;li&gt;Never stop learning: this is what successful programmer do.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And if you were searching for the (almost) perfect environment for learning Java, this is what probably brought you to CodeGym :) There’s no better time for starting than right now.&lt;/p&gt;

&lt;p&gt;Previously was published on &lt;a href="https://codegym.cc/groups/posts/why-should-you-learn-java" rel="noopener noreferrer"&gt;CodeGym blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>Java LinkedList Tutorial with Examples</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Mon, 04 Mar 2019 14:34:00 +0000</pubDate>
      <link>https://forem.com/codegym_cc/java-linkedlist-tutorial-with-examples-3nmi</link>
      <guid>https://forem.com/codegym_cc/java-linkedlist-tutorial-with-examples-3nmi</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5xpblflwls8foqztavf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5xpblflwls8foqztavf.png" alt="LinkedList" width="560" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the latest CodeGym lessons have been devoted to &lt;code&gt;ArrayList&lt;/code&gt;. This data structure is very convenient and useful. It can handle plenty of tasks. But Java has lots of other data structures.&lt;/p&gt;

&lt;p&gt;Why? Above all, because the range of tasks is enormous, and &lt;strong&gt;the most efficient data structures are different for different tasks&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Today we'll meet a new structure: &lt;code&gt;LinkedList&lt;/code&gt;, a doubly-linked list.&lt;/p&gt;

&lt;p&gt;Let's see how it's organized, why it's called doubly-linked, how it differs from &lt;code&gt;ArrayList&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The elements in a &lt;code&gt;LinkedList&lt;/code&gt; are actually links in a single chain. In addition to data, &lt;strong&gt;each element stores references to the previous and next elements&lt;/strong&gt;. These references let you move from one element to another. &lt;/p&gt;

&lt;p&gt;This is how you create one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {

   public static void main(java.lang.String[] args) {

       String str1 = new String("Hello World!");
       String str2 = new String("My name is Earl");
       String str3 = new String("I love Java");
       String str4 = new String("I live in Canada");

       LinkedList&amp;lt;String&amp;gt; earlBio = new LinkedList&amp;lt;&amp;gt;();
       earlBio.add(str1);
       earlBio.add(str2);
       earlBio.add(str3);
       earlBio.add(str4);

       System.out.println(earlBio);

   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Hello World! My name is Earl, I love Java, I live in Canada]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what our list looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_G2afkcd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000017/ddb43f41-c7d3-4504-85c3-04f45043744b%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_G2afkcd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000017/ddb43f41-c7d3-4504-85c3-04f45043744b%3Fsize%3D0" alt="LinkedList 1" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's see how to add a new element. This is done using the &lt;strong&gt;&lt;code&gt;add()&lt;/code&gt;&lt;/strong&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;earlBio.add(str2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the point in the code, our list consists of one element: the String &lt;code&gt;str1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's see what happens next in the picture:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--exkSf4QJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000017/9859bb21-3f24-4e34-b033-1931836a7a8f%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--exkSf4QJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000017/9859bb21-3f24-4e34-b033-1931836a7a8f%3Fsize%3D0" alt="LinkedList 2" width="800" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a result, &lt;code&gt;str2&lt;/code&gt; and &lt;code&gt;str1&lt;/code&gt; become linked via the &lt;strong&gt;&lt;code&gt;next&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;previous&lt;/code&gt;&lt;/strong&gt; links stored in this nodes of the list:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nStg0k-y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000061/72466dc5-c916-41d2-9a1a-be26e1b86a29%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nStg0k-y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000061/72466dc5-c916-41d2-9a1a-be26e1b86a29%3Fsize%3D0" alt="LinkedList 3" width="800" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you should understand the main idea of a doubly-linked list. &lt;strong&gt;This chain of links is precisely what makes &lt;code&gt;LinkedList&lt;/code&gt; elements a single list.&lt;/strong&gt; Unlike &lt;code&gt;ArrayList&lt;/code&gt;, &lt;code&gt;LinkedList&lt;/code&gt; doesn't have an array or anything array-like inside. &lt;/p&gt;

&lt;p&gt;Any (well, most) work with &lt;a href="https://codegym.cc/quests/lectures/questsyntax.level07.lecture05" rel="noopener noreferrer"&gt;ArrayList&lt;/a&gt; boils down to working with the internal array. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Any work with &lt;code&gt;LinkedList&lt;/code&gt; boils down to changing links.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This can be seen very clearly by adding an element to the middle of the list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {

   public static void main(java.lang.String[] args) {

       String str1 = new String("Hello World!");
       String str2 = new String("My name is Earl");
       String str3 = new String("I love Java");
       String str4 = new String("I live in Canada");

       LinkedList&amp;lt;String&amp;gt; earlBio = new LinkedList&amp;lt;&amp;gt;();
       earlBio.add(str1);
       earlBio.add(str3);
       earlBio.add(1, str2);

       System.out.println(earlBio);

   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the overloaded &lt;strong&gt;&lt;code&gt;add()&lt;/code&gt;&lt;/strong&gt; method lets you specify a specific index for a new item. In this case, we want to add String &lt;code&gt;str2&lt;/code&gt; between &lt;code&gt;str1&lt;/code&gt; and &lt;code&gt;str3&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is what will happen internally:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7EkkQafR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000017/50c60ece-dd95-49c9-a00b-5092460d057d%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7EkkQafR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000017/50c60ece-dd95-49c9-a00b-5092460d057d%3Fsize%3D0" alt="LinkedList 4" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After changing the internal links, &lt;code&gt;str2&lt;/code&gt; has been successfully added to the list:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DiKy57Ug--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000061/4bdfd57b-29a2-43d7-8592-495953c798a8%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DiKy57Ug--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000061/4bdfd57b-29a2-43d7-8592-495953c798a8%3Fsize%3D0" alt="LinkedList 5" width="800" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now all 3 elements are connected. You can move via the &lt;code&gt;next&lt;/code&gt; link from the first element on the chain to the last and back again.&lt;/p&gt;

&lt;p&gt;So, we're fairly comfortable with insertion, but what about removing elements?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The principle is exactly the same.&lt;/strong&gt; We just update the links in the two elements "to the left and the right" of the element being removed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {

   public static void main(java.lang.String[] args) {

       String str1 = new String("Hello World!");
       String str2 = new String("My name is Earl");
       String str3 = new String("I love Java");
       String str4 = new String("I live in Canada");

       LinkedList&amp;lt;String&amp;gt; earlBio = new LinkedList&amp;lt;&amp;gt;();
       earlBio.add(str1);
       earlBio.add(str3);
       earlBio.add(1, str2);

       earlBio.remove(1);
       System.out.println(earlBio);
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what happens if we delete the item with index 1 (it's in the middle of the list):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nbxHeKDP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000061/6351bbad-4ace-46ef-84e3-fe1b92fd0b56%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nbxHeKDP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000061/6351bbad-4ace-46ef-84e3-fe1b92fd0b56%3Fsize%3D0" alt="LinkedList 6" width="800" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After updating the links, we get the desired result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7l9NrZNB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000061/315aa18f-7717-4155-9495-612b55f8b374%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7l9NrZNB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://codegym.cc/api/1.0/rest/images/10000061/315aa18f-7717-4155-9495-612b55f8b374%3Fsize%3D0" alt="LinkedList 7" width="800" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unlike the removal operation in &lt;code&gt;ArrayList&lt;/code&gt;, here there is no need to shift array elements or do anything of the kind. We just update the links for &lt;code&gt;str1&lt;/code&gt; and &lt;code&gt;str3&lt;/code&gt;. They now point to each other, and &lt;code&gt;str2&lt;/code&gt; has "&lt;em&gt;dropped out&lt;/em&gt;" of the chain of links and is no longer part of the list. &lt;/p&gt;

&lt;h2&gt;
  
  
  Overview of methods
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;LinkedList&lt;/code&gt; has a lot of methods in common with &lt;code&gt;ArrayList&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, both classes have methods such as &lt;strong&gt;&lt;code&gt;add()&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;remove()&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;indexOf()&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;clear()&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;contains()&lt;/code&gt;&lt;/strong&gt; (indicates whether an item is in the list), &lt;strong&gt;&lt;code&gt;set()&lt;/code&gt;&lt;/strong&gt; (replaces an existing element), and &lt;strong&gt;&lt;code&gt;size()&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Although many of them work differently internally (as we found with &lt;code&gt;add()&lt;/code&gt; and &lt;code&gt;remove()&lt;/code&gt;), the end result is the same.&lt;/p&gt;

&lt;p&gt;However, &lt;code&gt;LinkedList&lt;/code&gt; does have separate methods for working with the beginning and end of the list, which &lt;code&gt;ArrayList&lt;/code&gt; does not have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;addFirst()&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;addLast()&lt;/code&gt;&lt;/strong&gt;: These methods for adding an element to the beginning/end of the list
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Car {

   String model;

   public Car(String model) {
       this.model = model;
   }

   public static void main(String[] args) {
       LinkedList&amp;lt;Car&amp;gt; cars = new LinkedList&amp;lt;&amp;gt;();
       Car ferrari = new Car("Ferrari 360 Spider");
       Car bugatti = new Car("Bugatti Veyron");
       Car lambo = new Car("Lamborghini Diablo");
       Car ford = new Car("Ford Modneo");
       Car fiat = new Car("Fiat Ducato");

       cars.add(ferrari);
       cars.add(bugatti);
       cars.add(lambo);
       System.out.println(cars);

       cars.addFirst(ford);
       cars.addLast(fiat);
       System.out.println(cars);
   }

   @Override
   public String toString() {
       return "Car{" +
               "model='" + model + '\'' +
               '}';
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car{model='Ferrari 360 Spider'}, Car{model='Bugatti Veyron'}, Car{model='Lamborghini Diablo'}]
[Car{model='Ford Modneo'}, Car{model='Ferrari 360 Spider'}, Car{model='Bugatti Veyron'}, Car{model='Lamborghini Diablo'}, Car{model='Fiat Ducato'}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We end up with "Ford" at the top of the list, and "Fiat" at the end.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;peekFirst()&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;peekLast()&lt;/code&gt;&lt;/strong&gt;: The methods return the first/last element in the list. They return &lt;code&gt;null&lt;/code&gt; if the list is empty.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {
   LinkedList&amp;lt;Car&amp;gt; cars = new LinkedList&amp;lt;&amp;gt;();
   Car ferrari = new Car("Ferrari 360 Spider");
   Car bugatti = new Car("Bugatti Veyron");
   Car lambo = new Car("Lamborghini Diablo");

   cars.add(ferrari);
   cars.add(bugatti);
   cars.add(lambo);
   System.out.println(cars.peekFirst());
   System.out.println(cars.peekLast());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car{model='Ferrari 360 Spider'}
Car{model='Lamborghini Diablo'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pollFirst()&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;pollLast()&lt;/code&gt;&lt;/strong&gt;: These methods return the first/last element in the list and remove it from the list. They return null if the list is empty
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {
   LinkedList&amp;lt;Car&amp;gt; cars = new LinkedList&amp;lt;&amp;gt;();
   Car ferrari = new Car("Ferrari 360 Spider");
   Car bugatti = new Car("Bugatti Veyron");
   Car lambo = new Car("Lamborghini Diablo");

   cars.add(ferrari);
   cars.add(bugatti);
   cars.add(lambo);
   System.out.println(cars.pollFirst());
   System.out.println(cars.pollLast());

   System.out.println ("What's on the list?");
   System.out.println(cars);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car{model='Ferrari 360 Spider'}
Car{model='Lamborghini Diablo'}
What's left on the list?
[Car{model='Bugatti Veyron'}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;toArray()&lt;/code&gt;&lt;/strong&gt;: This method returns an array containing the list items
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {
   LinkedList&amp;lt;Car&amp;gt; cars = new LinkedList&amp;lt;&amp;gt;();
   Car ferrari = new Car("Ferrari 360 Spider");
   Car bugatti = new Car("Bugatti Veyron");
   Car lambo = new Car("Lamborghini Diablo");

   cars.add(ferrari);
   cars.add(bugatti);
   cars.add(lambo);
   Car[] carsArray = cars.toArray(new Car[3]);
   System.out.println(Arrays.toString(carsArray));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Car{model='Ferrari 360 Spider'}, Car{model='Bugatti Veyron'}, Car{model='Lamborghini Diablo'}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we know how &lt;code&gt;LinkedList&lt;/code&gt; works and how its organization differs from &lt;code&gt;ArrayList&lt;/code&gt;. What are the benefits of using &lt;code&gt;LinkedList&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Above all, &lt;strong&gt;we benefit when working in the middle of the list&lt;/strong&gt;. Insertion and removal operations in the middle of a &lt;code&gt;LinkedList&lt;/code&gt; are much simpler than in an &lt;code&gt;ArrayList&lt;/code&gt;. We simply update the links of neighboring elements, and the unwanted element "drops out" of the chain of links.&lt;/p&gt;

&lt;p&gt;But in an &lt;code&gt;ArrayList&lt;/code&gt;, we must &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;check whether there is enough space (when inserting)&lt;/li&gt;
&lt;li&gt;if not, then we create a new array and copy the data there (when inserting)&lt;/li&gt;
&lt;li&gt;we remove/insert the element, and move all the other elements to the right/left (depending on the type of operation). And the complexity of this process depends heavily on the size of the list. It's one thing to copy/move 10 elements, and quite another to do the same with a million elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, if your program insertion/removal operations in the middle of the list are most common in your program, &lt;code&gt;LinkedList&lt;/code&gt; should be faster than &lt;code&gt;ArrayList&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  In theory
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {

   public static void main(String[] args) {
       List&amp;lt;Integer&amp;gt; list = new LinkedList&amp;lt;&amp;gt;();

       for (int i = 0; i &amp;lt; 5_000_000; i++) {
           list.add(new Integer(i));
       }

       long start = System.currentTimeMillis();

       for (int i = 0; i &amp;lt; 100; i++) {
           list.add(2_000_000, new Integer(Integer.MAX_VALUE));
       }
       System.out.println("Time taken by LinkedList (in milliseconds) = " + (System.currentTimeMillis()-start));
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time taken by LinkedList (in milliseconds) = 1873
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {

   public static void main(String[] args) {
       List&amp;lt;Integer&amp;gt; list = new ArrayList&amp;lt;&amp;gt;();

       for (int i = 0; i &amp;lt; 5_000_000; i++) {
           list.add(new Integer(i));
       }

       long start = System.currentTimeMillis();

       for (int i = 0; i &amp;lt; 100; i++) {
           list.add(2_000_000, new Integer(Integer.MAX_VALUE));
       }
       System.out.println("Time taken by ArrayList (in milliseconds) = " + (System.currentTimeMillis()-start));
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time taken by ArrayList (in milliseconds) = 181
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was unexpected!&lt;/p&gt;

&lt;p&gt;We performed an operation where &lt;code&gt;LinkedList&lt;/code&gt; should be much more efficient: inserting 100 items in the middle of a list. &lt;/p&gt;

&lt;p&gt;And our list is huge: 5,000,000 elements. &lt;code&gt;ArrayList&lt;/code&gt; had to shift a couple of million items with every insertion!&lt;/p&gt;

&lt;p&gt;How did it win?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, the time required for &lt;code&gt;ArrayList&lt;/code&gt; to access elements is fixed (constant).&lt;/strong&gt; When you write&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list.add(2_000_000, new Integer(Integer.MAX_VALUE));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then &lt;code&gt;ArrayList&lt;/code&gt; [2_000_000] is a specific memory address (after all, the list has an internal array).&lt;/p&gt;

&lt;p&gt;But, a &lt;code&gt;LinkedList&lt;/code&gt; does not have an array. It will search for element number 2_000_000 along the chain of links. For LinkedList, this is not a memory address, but a link that still needs to be reached:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;fistElement.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next.next………&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As a result, during each insertion (removal) in the middle of the list, &lt;code&gt;ArrayList&lt;/code&gt; already knows the exact memory address to access, but &lt;code&gt;LinkedList&lt;/code&gt; still needs to "get there".&lt;/p&gt;

&lt;p&gt;Second, there is the structure of the &lt;code&gt;ArrayList&lt;/code&gt; itself. A special internal function (&lt;code&gt;System.arrayCopy()&lt;/code&gt;) expands the internal array, and copies and shifts all the elements. It is very fast, because it is optimized for this specific work.&lt;/p&gt;

&lt;p&gt;But when you don't have to "get to" a particular index, &lt;code&gt;LinkedList&lt;/code&gt; is the winner. Suppose we insert at the very beginning of the list.&lt;/p&gt;

&lt;p&gt;Let's try inserting a million elements there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {

   public static void main(String[] args) {
       getTimeMsOfInsert(new ArrayList());
       getTimeMsOfInsert(new LinkedList());
   }

   public static long getTimeMsOfInsert(List list) {
       // Write your code here
       Date currentTime = new Date();
       insert1000000(list);
       Date newTime = new Date();
       long msDelay = newTime.getTime() - currentTime.getTime(); // Calculate the difference
       System.out.println("The result in milliseconds: " + msDelay);
       return msDelay;

   }

   public static void insert1000000(List list) {
       for (int i = 0; i &amp;lt; 1000000; i++) {
           list.add(0, new Object());
       }
   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The result in milliseconds: 43448
The result in milliseconds: 107
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we get an entirely different result!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ArrayList&lt;/code&gt; spent more than 43 seconds inserting a million items at the front of the list took, while &lt;code&gt;LinkedList&lt;/code&gt; managed to do it in 0.1 seconds!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;LinkedList&lt;/code&gt; benefited here, because it did not have to run through the chain of links to the middle of the list every time. It immediately finds the needed index at the beginning of the list, so the different algorithm is already an advantage. :)&lt;/p&gt;

&lt;p&gt;In fact, the "&lt;code&gt;ArrayList&lt;/code&gt; versus &lt;code&gt;LinkedList&lt;/code&gt;" discussion is very widespread, and we won't dive deep into it at the current level.&lt;br&gt;
The main thing that you need to remember is this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Not all of the theoretical advantages any particular collection always work in reality (we saw this with the example involving the middle of the list)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don't adopt an extreme position when it comes to choosing a collection ("&lt;code&gt;ArrayList&lt;/code&gt; is always faster. Use it and you can't go wrong. Nobody has been using &lt;code&gt;LinkedList&lt;/code&gt; for a long time").&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although even &lt;code&gt;LinkedList&lt;/code&gt;'s author, Joshua Bloch, says this is the case. :)&lt;/p&gt;

&lt;p&gt;Still, this perspective is far from 100% correct, and we've convinced ourselves of this. In our previous example, &lt;code&gt;LinkedList&lt;/code&gt; was 400 (!) times faster. Another thing is that there really are few situations where &lt;code&gt;LinkedList&lt;/code&gt; is the best choice. But they do exist, and at the right moment &lt;code&gt;LinkedList&lt;/code&gt; can reward you handsomely. Don't forget what we said at the beginning of the lesson: &lt;strong&gt;the most efficient data structures are different for different tasks&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It's impossible to be 100% sure which data structure will be best until you know all the conditions of your task.&lt;/p&gt;

&lt;p&gt;You'll know more about these collections later, which will make the choice easier. But the simplest and most effective option is always the same: try both on the actual data used in your program. Then you will be able to see for yourself how both types of lists perform and you definitely won't go wrong. :)&lt;/p&gt;

&lt;p&gt;Previously was published on &lt;a href="https://codegym.cc/groups/posts/23-linkedlist" rel="noopener noreferrer"&gt;CodeGym blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>18 Best Java Books For Beginners In 2019</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Mon, 04 Mar 2019 13:54:26 +0000</pubDate>
      <link>https://forem.com/codegym_cc/18-best-java-books-for-beginners-in-2019-fme</link>
      <guid>https://forem.com/codegym_cc/18-best-java-books-for-beginners-in-2019-fme</guid>
      <description>&lt;h1&gt;
  
  
  18 Best Java Books For Beginners In 2019
&lt;/h1&gt;

&lt;p&gt;Getting the hang of coding might be confusing for a complete beginner. There are dozens and dozens of Java books on Amazon — it’s so easy to get lost! How about a little piece of advice, based on experience of the other Java learners? If you still haven’t put together your reading list for 2019, we’re here to help with our choice of the best books for Java learners.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xXwe4tUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/c36444b2-3740-49ca-8aeb-30d5e0949066%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xXwe4tUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/c36444b2-3740-49ca-8aeb-30d5e0949066%3Fsize%3D0" alt="18 Best Java Books For Beginners In 2019"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The best Java books for beginners
&lt;/h2&gt;

&lt;p&gt;These are completely safe sources for ones that only start to learn coding in Java. We advise you to have a look at all of them, because they use different approaches in presenting core concepts. When you get stuck with a certain topic in one book, the chances are strong that you will get a clear explanation somewhere else.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Head First Java by Kathy Sierra &amp;amp; Bert Bates
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_LATsXYZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/e19e6e99-997b-4429-9d9f-06b092ecece2%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_LATsXYZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/e19e6e99-997b-4429-9d9f-06b092ecece2%3Fsize%3D1024" alt="Head First Java by Kathy Sierra &amp;amp; Bert Bates"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you can’t imagine a clear explanation without a proper visual, like scheme, diagram or a graphic drawing, you’ll enjoy this book for beginners. It’s arguably the best introduction to Java, which explains the core language and the concepts of OOP on the real-world examples. Even though it’s a book, it has a very “user-friendly interface”: you’ll get engaged from the first page till you finish it. &lt;/p&gt;

&lt;p&gt;You won’t immediately start to code after you read Head First Java, but you will understand without any difficulties the logic of this language and its main concepts. Each chapter ends with exercises and puzzles: they will help you memorize the material.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; engaging storytelling, great illustrations, and real-life explanations. Probably the best book to learn Java from scratch.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; sometimes the puzzles are a bit confusing.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Beginning Programming with Java For Dummies
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---3mBqpKA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/060e0523-a29d-4a49-9438-e0e57d3726e5%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---3mBqpKA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/060e0523-a29d-4a49-9438-e0e57d3726e5%3Fsize%3D1024" alt="Beginning Programming with Java For Dummies"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You have all the right to be skeptic about “the dummies series” since they are of no use for readers with even a minimal experience and understanding of any subject. But due to the plain language, they explain the main terms simply without any confusions. You will learn the major things you need to start with Java coding, like how to install Java, compile code and complete different practical exercises after you finish the reading. It is as easy as books for kids. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; very simple examples and lots of “how-tos” if you have no idea of programming concepts.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; nothing more than a plain introduction in Java.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Java: Programming Basics for Absolute Beginners by Nathan Clark
&lt;/h3&gt;

&lt;p&gt;Another book for readers with a zero experience in coding will guide you step-by-step through the basics. You will learn how to choose an IDE and write the first program. The book familiarizes you with Java Development Kit and Java Runtime Environment and gives the description for each part of the code in examples. It serves as a rather good preliminary environment before you delve into more serious subjects. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bCfeSGYt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/e2449137-cb96-4a24-af39-b0eb7fbcfabd%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bCfeSGYt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/e2449137-cb96-4a24-af39-b0eb7fbcfabd%3Fsize%3D1024" alt="Java: Programming Basics for Absolute Beginners by Nathan Clark"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; smooth intro to Java programming and its main features.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; there’s no profound explanation of the Object Oriented Programming concept, this is why some practical examples might be confusing.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Java: A Beginner’s Guide by Herbert Schildt
&lt;/h3&gt;

&lt;p&gt;Generally, Schildt’s guide is considered to be among the 3 or at least 5 best books for Java beginners. But this book requires a little bit more understanding of programming comparing to the previous sources. It will deepen your understanding of Java origins and its relations to other programming languages. &lt;/p&gt;

&lt;p&gt;It is profound research about the core concepts of Java which explains the code by line and guides you from the basic understanding of data types, classes and objects to more complex concepts like lambda expressions and functional interfaces. The great part of this book is a self-test section at the end of each chapter. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d5UTh5cV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/d393bb98-32d2-4dc2-aea0-256551e5af26%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d5UTh5cV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/d393bb98-32d2-4dc2-aea0-256551e5af26%3Fsize%3D1024" alt="Java: A Beginner’s Guide by Herbert Schildt"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; a plain tone of voice, self-testing, full coverage of Java core.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; you need at least a small prior understanding of programming. &lt;/p&gt;

&lt;h2&gt;
  
  
  5. Core Java Volume I — Fundamentals
&lt;/h2&gt;

&lt;p&gt;Don’t mind the impressive 1000 pages — you can easily read this book from cover to cover. It puts aside the playful tone and focuses on detailed explanations of Java core. Each chapter is devoted to a certain subject, starting from introduction to the language and Java programming environment and moving to data structures, objects and classes and so on. Unlike many books for beginners, Core Java gives an explicit coverage of collections and generics, which is useful for real programming. &lt;/p&gt;

&lt;p&gt;All in all, it is a great reference book. Read it once and return to it anytime you need to refresh your knowledge. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--63iht05O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/0196b027-6749-4cfd-9748-daf24340cfb0%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--63iht05O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/0196b027-6749-4cfd-9748-daf24340cfb0%3Fsize%3D1024" alt="Core Java Volume I — Fundamentals"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; a full reference to Java Core and attention to collections and generics, profound explanations.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; some topics, like generics, are covered less diligent than others.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Think Java: How to Think Like a Computer Scientist by Allen Downey and Chris Mayfield
&lt;/h3&gt;

&lt;p&gt;This book for complete beginners will teach you how to think in code. Like many others, it starts with an introduction to OOP. It is also a rather good reference book. Each chapter has the vocabulary and exercise sections to consolidate theory and master the skill of programming thinking. It is more suitable for beginners than readers with even a small experience in coding. For starters, it is simple and kind of fun to read. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NEoc9Bkx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/b79a6af3-b6a1-4490-9bec-9ba8ac5d191d%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NEoc9Bkx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/b79a6af3-b6a1-4490-9bec-9ba8ac5d191d%3Fsize%3D1024" alt="Think Java: How to Think Like a Computer Scientist by Allen Downey and Chris Mayfield"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; a source for adjusting your way of coding, practice, basic concepts explained clearly.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; cannot be considered as the complete reference for core Java; the same level of complexity in all exercises. &lt;/p&gt;

&lt;h2&gt;
  
  
  Java books for advanced learners
&lt;/h2&gt;

&lt;p&gt;You’re already familiar with the main concepts and have already made coding your daily habit? Cheers to that! Let’s move forward to Java books, which will deepen your knowledge and set a focus on the number of useful topics in real-world coding. &lt;/p&gt;

&lt;h3&gt;
  
  
  7. Effective Java is written by Joshua Bloch
&lt;/h3&gt;

&lt;p&gt;This is not a book for a complete beginner but is must-read research for every Java developer. You will quickly see that it’s written by an expert with a serious practical background, because it explains not only the general subjects but the subtleties, too. If you want to understand the inner processes and get a clue of how and why they are arranged this way, this book serves the purposes well. Each chapter consists the “items” with lots of practical advice and a good review of the latest Java features. It will teach you how to write the code and how to do it well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w3ewFxwm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/33f15d51-6a00-4405-bb4f-77b3c669c77f%3Fsize%3D0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w3ewFxwm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/33f15d51-6a00-4405-bb4f-77b3c669c77f%3Fsize%3D0" alt="Effective Java is written by Joshua Bloch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; easy to read, covers best practices in programming, useful advice for improving your coding.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; requires an understanding of core concepts and at least a small experience in coding.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Java: The Complete Reference by Herbert Schildt
&lt;/h3&gt;

&lt;p&gt;Probably you won’t start learning Java from scratch with this book, but sooner or later you will refer to it, as it’s a well-structured fully-featured source on Java programming with examples from the real world programming. It covers the Java 8 APIs, and clearly explains the basic concepts and beyond that. The “additional” material is devoted to JavaBeans, servlets, applets, and swing. So it’s totally right decision to have this book on your bookshelf or on your book reader. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Fa2Z8JHB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/2b85d3d6-3d02-4d02-b1cb-2ac26e4605f5%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Fa2Z8JHB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/2b85d3d6-3d02-4d02-b1cb-2ac26e4605f5%3Fsize%3D1024" alt="Java: The Complete Reference by Herbert Schildt"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; the real world examples, clear and detailed explanations, a good reference for the latest Java APIs.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; requires a basic knowledge of Java programming.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Java 8 in Action
&lt;/h3&gt;

&lt;p&gt;If you need a Java 8 book with full coverage of its features, this one is for you. &lt;/p&gt;

&lt;p&gt;It will be easier for you to understand the material with some background in Java. But what’s great about this book is the many-sidedness of practice. The examples include both “proper” and “wrong” code samples. Just be sure not to mix them up :) All in all, this is a book with an obvious focus on practice, so you can use it as an additional source for the enhanced studying. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K-uWzSfl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/067a798e-8e41-4222-8309-45af8a6179e4%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K-uWzSfl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/067a798e-8e41-4222-8309-45af8a6179e4%3Fsize%3D1024" alt="Java 8 in Action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; focused on practice, shows the difference between the right and the wrong code.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; requires supplementary sources for a deeper understanding of Java basics. &lt;/p&gt;

&lt;h3&gt;
  
  
  10. Thinking in Java by Bruce Eckel
&lt;/h3&gt;

&lt;p&gt;This book offers you a rather refreshing approach to explaining Java fundamentals. It has a focus on Java language design and behavior, and includes many detailed explanations. You will get the understanding of how each topic fits in with OOP. The basic subjects are fully covered on the first 200 pages of the book. The larger part can help you to cover the new ground. It is one of those books, which you will return to even after years of studying and coding. &lt;/p&gt;

&lt;p&gt;Although some of the examples are a bit outdated, this book is still a profound source for learners, because it actually teaches you to think like a Java programmer and encourages you to code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G5SFHikC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/abe05848-1c52-4933-80df-66ed4cbc3746%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G5SFHikC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/abe05848-1c52-4933-80df-66ed4cbc3746%3Fsize%3D1024" alt="Thinking in Java by Bruce Eckel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; a thorough source, plenty of code samples and exercises, excellent explanation of OOP concepts in Java.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; might be too complicated for a beginner. &lt;/p&gt;

&lt;h3&gt;
  
  
  11. Grokking Algorithms: An illustrated guide for programmers and other curious people by Aditya Y. Bhargava
&lt;/h3&gt;

&lt;p&gt;If you need the best book about algorithms, this one may be the right choice. It is comprehensible for readers with an entry level of knowledge and presents popular algorithms such as sorting and searching in a graphical manner. Not many people would say that this specific subject is very exciting. This is why a visual approach to presenting data will help the newcomers to quickly engage themselves in learning. &lt;/p&gt;

&lt;p&gt;The book is divided into short chapters with a variety of examples, so you perceive the new information in the right proportions. And a plain and vivid narration will guide you through the concepts in such a way that you’ll be prepared to advanced content. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZNd-qg6k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/b1492b0e-4d37-45f1-9df5-1d6c8c8da5d4%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZNd-qg6k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/b1492b0e-4d37-45f1-9df5-1d6c8c8da5d4%3Fsize%3D1024" alt="Grokking Algorithms: An illustrated guide for programmers and other curious people by Aditya Y. Bhargava"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; visuals, engaging narration, full coverage of fundamentals.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; great for beginners, but cannot be considered as a full reference. &lt;/p&gt;

&lt;h3&gt;
  
  
  12. Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein
&lt;/h3&gt;

&lt;p&gt;If you can’t get enough of algorithms, try this one. The unusual feature of the “Introduction…” is that it includes examples in a “pseudocode”. Despite it’s been presented as an introduction, it has a large scope of covered topics, and the whole concept of data structures and algorithms is explained pretty well. It is written in plain English and covers everything you need to know. The only thing is that it’s focused on describing algorithms rather than designing them. Still, it is a good reference book. If you feel you need to learn more about algorithms, then keep this book in mind.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--13sD5vTR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/9076775f-a957-4ea9-94f7-b35335a67e6e%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--13sD5vTR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/9076775f-a957-4ea9-94f7-b35335a67e6e%3Fsize%3D1024" alt="Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; a detailed catalogue of algorithms to which for a variety of situations.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; a lack of practice, requires a background reading. &lt;/p&gt;

&lt;h3&gt;
  
  
  13. Think Data Structures: Algorithms and Information Retrieval in Java by Allen B. Downey
&lt;/h3&gt;

&lt;p&gt;This is a helpful guide for utilizing data structures in Java programming. It will be an easy read for experienced developers, as it goes beyond the fundamentals straight to the deep understanding of interfaces, arrays, hash maps, jsoup using, etc.&lt;/p&gt;

&lt;p&gt;Each chapter includes an introduction to the topic, example, additional explanations plus the exercise to consolidate theory. You will enjoy the clear language and plain examples and how this book helps you to implement your knowledge immediately. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kvIu4ARw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/18f058ab-537c-4c36-876f-a69b53d9911c%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kvIu4ARw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/18f058ab-537c-4c36-876f-a69b53d9911c%3Fsize%3D1024" alt="Think Data Structures: Algorithms and Information Retrieval in Java by Allen B. Downey"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; a condensed material with useful examples.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; might be tough for the novices.&lt;/p&gt;

&lt;h3&gt;
  
  
  14. Learning Java by Building Android Games: Learn Java and Android from scratch by building six exciting games by John Horton
&lt;/h3&gt;

&lt;p&gt;Android is among the most popular mobile operating systems, and Java is one of the major languages for building apps on it. If being a mobile developer is your goal, why not take one of the best books for learning Java programming in this field? For the record, this book doesn’t require a Java proficiency. The level of difficulty grows gradually from the key subjects (variables, loops, methods, object-oriented programming). After each stage, you’re given a task to develop your own game for Android platform, six of them in total.&lt;/p&gt;

&lt;p&gt;Not a fan of game development? Still worth trying to see Java programming in action. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9TQURcma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/8f1aab00-6858-4739-a848-f53d147fccf2%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9TQURcma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/8f1aab00-6858-4739-a848-f53d147fccf2%3Fsize%3D1024" alt="Learning Java by Building Android Games: Learn Java and Android from scratch by building six exciting games by John Horton"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; a practical guide to game development.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; serves a specific goal.&lt;/p&gt;

&lt;h2&gt;
  
  
  General-purpose books on programming
&lt;/h2&gt;

&lt;p&gt;These books should be on your list somewhere between the sources for the newcomers in Java and readers with a slight experience. They will broaden your scope about coding in general and teach you the major concepts of programming, creating clean code and getting started your career. Here’s our choice of the best programming books for beginners, regardless of the language they learn. &lt;/p&gt;

&lt;h3&gt;
  
  
  15. Head First Learn to Code by Eric Freeman
&lt;/h3&gt;

&lt;p&gt;Head First series is presented by the best book to learn Java and also books on learning other programming languages. This one is devoted to programming in general. You will easily recognize the unique style of narration once you open it. Read this if you need a hand of the key concepts of coding in a fun and easy to understand way. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ncFL7hH---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/f32c567a-0372-4cd9-b02c-035c0caca208%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ncFL7hH---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/f32c567a-0372-4cd9-b02c-035c0caca208%3Fsize%3D1024" alt="Head First Learn to Code by Eric Freeman"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; gives a general understanding of programming. &lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; uses examples on Python (as it is considered to be easier for newbies). &lt;/p&gt;

&lt;h3&gt;
  
  
  16. Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin
&lt;/h3&gt;

&lt;p&gt;When you’re new to programming, you don’t pay much attention to your code style, as you’re focused on avoiding the obvious mistakes. But improving your style is very important in your further work. This book will show you the difference between good code and bad code and teach you major rules of writing clean and readable code, using the best practices. The book is highly recommended for beginner developers. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WLXKozrd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/9f917e88-ffd8-47de-893d-463c9b8c2e5f%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WLXKozrd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/9f917e88-ffd8-47de-893d-463c9b8c2e5f%3Fsize%3D1024" alt="Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; good examples and advice on crafting a readable code.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; come rules are taken to an extreme.&lt;/p&gt;

&lt;h3&gt;
  
  
  17. Code: The Hidden Language of Computer Hardware and Software by Charles Petzold
&lt;/h3&gt;

&lt;p&gt;Well, this is not a beginners’ book on Java, but it is a must-read for every developer. It will help you to clearly understand how computers work, from hardware to software. The author covers a wide range of subjects like electricity, circuits, relays, binary, logic, gates, microprocessors, code, and others to gradually create an understanding of how computer technology works. After reading this book, you would see behind the pixels on your desktop and know what’s happening every time you use your devices. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aBWiayBD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/a3b82176-f48c-4397-994a-aed31cc5f466%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aBWiayBD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/a3b82176-f48c-4397-994a-aed31cc5f466%3Fsize%3D1024" alt="Code: The Hidden Language of Computer Hardware and Software by Charles Petzold"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; a great summary of computer technologies, lots of examples.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; some part of the book might be complicated. &lt;/p&gt;

&lt;h3&gt;
  
  
  18. Cracking the Coding Interview by Gayle Laakmann McDowell
&lt;/h3&gt;

&lt;p&gt;This is the best book for Java learners that have a goal to get a job as a software developer. It includes a wide list of practical questions and solutions you might be asked during a coding interview. Of course, the time zips along and many trends in “testing” developers change, but this book will help a newcomer to seize the idea of what to expect. However, we advise you to update your insights on forums and Java communities. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dSzomW3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/8125afd9-c921-4c7f-b8c0-8c223f1a92a4%3Fsize%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dSzomW3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codegym.cc/api/1.0/rest/images/10000017/8125afd9-c921-4c7f-b8c0-8c223f1a92a4%3Fsize%3D1024" alt="Cracking the Coding Interview by Gayle Laakmann McDowell"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; prepares for the real-world coding interviews.&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; won’t help you without additional sources. &lt;/p&gt;

&lt;p&gt;Well, we’ve finally reached the end of our list of best books to learn Java. Applauses for you being so patient and curious! &lt;/p&gt;

&lt;p&gt;Have you already read some of those? Do you have other books to recommend? Share your thoughts with us in the comments!&lt;/p&gt;

&lt;p&gt;Previously was published on &lt;a href="https://codegym.cc/groups/posts/72-18-best-java-books-for-beginners-in-2019"&gt;CodeGym blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>Creating a Telegram Bot in Java: from conception to deployment</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Tue, 26 Feb 2019 09:43:44 +0000</pubDate>
      <link>https://forem.com/codegym_cc/creating-a-telegram-bot-in-java-from-conception-to-deployment-3a8c</link>
      <guid>https://forem.com/codegym_cc/creating-a-telegram-bot-in-java-from-conception-to-deployment-3a8c</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F2yk3893hh64s05bcl0lq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F2yk3893hh64s05bcl0lq.png" title="Telegram bot with Java" alt="Telegram bot with Java"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what are bots? You can read more about this &lt;a href="https://core.telegram.org/bots" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To start, you need to review the official documentation for the library used to develop Telegram bots (hereafter the “API”). It can be found &lt;a href="https://core.telegram.org/bots/api" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Everything there is very accessible and clear. It seems we can just write code and rejoice! But it’s not so simple. After spending a lot of time searching, I’ve found tidbits of knowledge on bot development, for example, how to make a keyboard, handle a &lt;code&gt;CallbackQuery&lt;/code&gt;, and so forth. But, I didn't find a complete, exhaustive guide for Java bot development. That prompted me to write this article.&lt;/p&gt;

&lt;p&gt;There are a lot of websites where you can create your own easily deployable bot. But the fact is, most of the bots created provide reference information and the like. Our bot is a full-fledged web application. You can bind a database, execute various API requests, parse websites, perform complex calculations, and more. The possibilities are limited only by your imagination. I hope that the above has helped clarify what I'm going to write about.&lt;/p&gt;

&lt;p&gt;It's very easy to register a bot on Telegram. This process is described in detail in the documentation linked to above. For our application, you only need to know the bot's name and the token you receive when registering the bot.&lt;/p&gt;

&lt;p&gt;Basically, a bot is just a console-based web application. There is no front end, just pure command processing. If you want to master &lt;strong&gt;Hibernate&lt;/strong&gt; or learn how to parse &lt;strong&gt;JSON&lt;/strong&gt;, then this is the project for you. Let's start by adding a dependency to pom.xml (I'll assume you're using Maven). You can do that like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.telegram&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;telegrambots&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;3.5&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create a Bot class that inherits the &lt;code&gt;TelegramLongPollingBot&lt;/code&gt; class, and override its methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Bot extends TelegramLongPollingBot {

    /**
     * Method for receiving messages.
     * @param update Contains a message from the user.
     */
    @Override
    public void onUpdateReceived(Update update) {
    String message = update.getMessage().getText();
    sendMsg(update.getMessage().getChatId().toString(), message);
    }

    /**
     * Method for creating a message and sending it.
     * @param chatId chat id
     * @param s The String that you want to send as a message.
     */
    public synchronized void sendMsg(String chatId, String s) {
        SendMessage sendMessage = new SendMessage();
        sendMessage.enableMarkdown(true);
        sendMessage.setChatId(chatId);
        sendMessage.setText(s);
        try {
            sendMessage(sendMessage);
        } catch (TelegramApiException e) {
            log.log(Level.SEVERE, "Exception: ", e.toString());
        }
    }

    /**
     * This method returns the bot's name, which was specified during registration.
     * @return bot name
     */
    @Override
    public String getBotUsername() {
        return "BotName";
    }

    /**
     * This method returns the bot's token for communicating with the Telegram server
     * @return the bot's token
     */
    @Override
    public String getBotToken() {
        return "BotToken";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now the contents of the main method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {
        ApiContextInitializer.init();
        TelegramBotApi telegramBotApi = new TelegramBotApi();
        try {
            telegramBotApi.registerBot(Bot.getBot());
        } catch (TelegramApiRequestException e) {
            e.printStackTrace();
        }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After filling in the &lt;code&gt;getBotUsername()&lt;/code&gt; and &lt;code&gt;getBotToken()&lt;/code&gt; methods, start the bot. For now, it just redirects to us any messages we send to it, kind of like a "mirror". It works like this: when you start the application, it starts sending requests to the Telegram server, once every n seconds, at the following URL: &lt;em&gt;&lt;a href="https://api.telegram.org/BotToken/getMe" rel="noopener noreferrer"&gt;https://api.telegram.org/BotToken/getMe&lt;/a&gt;&lt;/em&gt;, where BotToken is your bot's token. In response, it receives JSON containing all the messages. Each of these messages is processed by the library and is passed to the &lt;code&gt;OnUpdateReceived(Update update)&lt;/code&gt; method as an &lt;code&gt;Update&lt;/code&gt; object. And that's what we work with. Herein lies the beauty of Telegram bots: they can run on any computer, testing it just requires starting the application, and you don't need to deploy it to the host after each change. This is very convenient.&lt;/p&gt;

&lt;p&gt;Of course, you can configure a bot to work using webhooks. You can find directions for that on the Internet. For simplicity, we'll use LongPolling.&lt;/p&gt;

&lt;p&gt;How messages are processed and what you send in response are only limited by the capabilities of the language and library. Everything else is up to you. You can make a bot that will search YouTube videos for you. You can make a bot that will send you what you send yourself everyday, like a time capsule from a year ago. Or you can learn to integrate with CRM systems and make bots for small businesses—you're only limited by your imagination.&lt;/p&gt;

&lt;p&gt;Moving on. Those who have used bots know that it's convenient to interact with them using commands that start with the "&lt;code&gt;/&lt;/code&gt;" character, for example, &lt;code&gt;/start&lt;/code&gt;. But there is a more convenient way: buttons. There are two kinds of buttons: those that appear under an input field (&lt;code&gt;ReplyKeyboardMarkup&lt;/code&gt;) and buttons that are directly below the message they're linked to (&lt;code&gt;InlineKeyboardMarkup&lt;/code&gt;). You can get a basic understanding of them from their descriptions in the documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  ReplyKeyboardMarkup
&lt;/h2&gt;

&lt;p&gt;In reality, this is an array of button arrays: &lt;code&gt;List&amp;lt;KeyboardRow &amp;lt;KeyboardButton&amp;gt;&amp;gt;&lt;/code&gt;. Here's sample code that creates a keyboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public synchronized void setButtons(SendMessage sendMessage) {

        // Create a keyboard
        ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
        sendMessage.setReplyMarkup(replyKeyboardMarkup);
        replyKeyboardMarkup.setSelective(true);
        replyKeyboardMarkup.setResizeKeyboard(true);
        replyKeyboardMarkup.setOneTimeKeyboard(false);

        // Create a list of keyboard rows
        List&amp;lt;KeyboardRow&amp;gt; keyboard = new ArrayList&amp;lt;&amp;gt;();
        // First keyboard row
        KeyboardRow keyboardFirstRow = new KeyboardRow();

        // Add buttons to the first keyboard row
        keyboardFirstRow.add(new KeyboardButton("Hi"));

        // Second keyboard row
        KeyboardRow keyboardSecondRow = new KeyboardRow();
        // Add the buttons to the second keyboard row
        keyboardSecondRow.add(new KeyboardButton("Help");

        // Add all of the keyboard rows to the list
        keyboard.add(keyboardFirstRow);
        keyboard.add(keyboardSecondRow);
        // and assign this list to our keyboard
        replyKeyboardMarkup.setKeyboard(keyboard);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We call this method in the &lt;code&gt;sendMsg()&lt;/code&gt; method, after passing it a message. This is how we set up a keyboard for that message. When we send this message to the user, he will see the text of our message and 2 buttons that say "&lt;em&gt;Hi&lt;/em&gt;" and "&lt;em&gt;Help&lt;/em&gt;", one under the other.&lt;/p&gt;

&lt;p&gt;When one of these buttons is clicked, the bot is sent a message containing the button text. So, if the client clicks "&lt;em&gt;Help&lt;/em&gt;", the bot will receive a message with "Help". To the bot, it will seem that the client itself wrote "&lt;em&gt;Help&lt;/em&gt;" and sent the text to the bot. And then you process the messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  InlineKeyboardMarkup
&lt;/h2&gt;

&lt;p&gt;This is also an array of arrays. It is similar to the previous Markup, but the logic works a little differently here. This type of keyboard is attached to a specific message and exists only for it. Here’s a method for setting up an inline keyboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private void setInline() {
        List&amp;lt;List&amp;lt;InlineKeyboardButton&amp;gt;&amp;gt; buttons = new ArrayList&amp;lt;&amp;gt;();
        List&amp;lt;InlineKeyboardButton&amp;gt; buttons1 = new ArrayList&amp;lt;&amp;gt;();
        buttons1.add(new InlineKeyboardButton().setText("Button").setCallbackData(17));
        buttons.add(buttons1);

        InlineKeyboardMarkup markupKeyboard = new InlineKeyboardMarkup();
        markupKeyboard.setKeyboard(buttons);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a &lt;code&gt;List&lt;/code&gt; within the &lt;code&gt;List&lt;/code&gt;, and add the inline button to the first row. This button can contain a URL, a link to a channel, or a &lt;code&gt;CallbackQuery&lt;/code&gt;, which I'll write about a little later. This is where we set our button's text, which is what the user will see, and then we set the data that will be sent to the bot. In our example, the user sees "Hi", and when the button is pressed the number 17 will be sent to the bot. This is our &lt;code&gt;CallbackQuery&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A few words regarding &lt;code&gt;CallbackQuery&lt;/code&gt;. To obtain this data from the &lt;code&gt;Update&lt;/code&gt; object, you need to execute &lt;code&gt;update.getCallbackQuery()&lt;/code&gt;. This method returns a &lt;code&gt;CallbackQuery&lt;/code&gt;, from which you can access the data passed to the bot. Don't try to get this data through the &lt;code&gt;update.getMessage().getText()&lt;/code&gt; method—you'll get a &lt;code&gt;NullPointerException&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Override
    public void onUpdateReceived(Update update) {
        if(update.hasMessage()) {
            ThreadClass thread = new ThreadClass(update.getMessage());
        } else  if(update.hasCallbackQuery()) {
            AnswerCallbackThread answerThread = new AnswerCallbackThread(update.getCallbackQuery());
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there’s a message, we send it to a new thread for processing; if there’s a &lt;code&gt;CallbackQuery&lt;/code&gt;, we send to the appropriate thread for processing. You can send a response to a &lt;code&gt;CallbackQuery&lt;/code&gt;. Every object in Telegram has its own id. To send a response to a specific &lt;code&gt;CallbackQuery&lt;/code&gt;, you just need to know its id, which we get from the corresponding object. To send a response, we call this method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public synchronized void answerCallbackQuery(String callbackId, String message) {
        AnswerCallbackQuery answer = new AnswerCallbackQuery();
        answer.setCallbackQueryId(callbackId);
        answer.setText(message);
        answer.setShowAlert(true);
        try {
            answerCallbackQuery(answer);
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;IMPORTANT&lt;/strong&gt;: The text in a response to a &lt;code&gt;CallbackQuery&lt;/code&gt; must be no longer than 200 characters!&lt;/p&gt;

&lt;p&gt;After sending such a response, the client will see a pop-up window containing the message. This window can disappear a few seconds after it appears, or it can persist until the user presses OK. To switch modes, we call the &lt;code&gt;answer.setShowAlert(true)&lt;/code&gt; method. If you pass &lt;code&gt;true&lt;/code&gt; to the method, the window persists until OK is pressed. If you pass false, then it disappears after 5 seconds.&lt;/p&gt;

&lt;p&gt;These are all of the Telegram Bot library's basic features. If you want, you can learn things like how to send multimedia, geolocation, etc.&lt;/p&gt;

&lt;p&gt;Let's move on to deploying our bot to a hosting platform.&lt;/p&gt;

&lt;p&gt;For my project, I chose Heroku. I think it's a rather convenient hosting platform with its own CLI. It's free, but on this plan your bot will hibernate after 30 minutes of receiving no requests. It will wake up when a request is received. This happens so quickly, you won't even notice (unless, of course, the database connection doesn't restart). The free plan is limited by a 5MB database, 100MB disk space, 2TB data per month, and 1 dyno. A dyno is your running application.&lt;/p&gt;

&lt;p&gt;I'll say right away that it was deployment that caused me difficulties, since I had never deployed my applications before.&lt;/p&gt;

&lt;p&gt;During deployment, Heroku requires a file named Procfile (without an extension). We create it in the project root. Inside, we write &lt;code&gt;worker: sh target/bin/workerBot&lt;/code&gt;, where &lt;strong&gt;workerBot&lt;/strong&gt; is the name specified in &lt;code&gt;pom.xml&lt;/code&gt;. A sh script, generated by the Maven Application Assembler Plugin (appassembler-maven-plugin), will launch. The script describes how to launch a compiled jar file. The name of the class to launch is specified between &lt;code&gt;&amp;lt;mainClass&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;/mainClass&amp;gt;&lt;/code&gt;, while the name of the script is given between &lt;code&gt;&amp;lt;name&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;/name&amp;gt;&lt;/code&gt; in &lt;code&gt;pom.xml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
&amp;lt;build&amp;gt;
    &amp;lt;plugins&amp;gt;
        ...
       &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;org.codehaus.mojo&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;appassembler-maven-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;1.1.1&amp;lt;/version&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;assembleDirectory&amp;gt;target&amp;lt;/assembleDirectory&amp;gt;
                &amp;lt;programs&amp;gt;
                    &amp;lt;program&amp;gt;
                        &amp;lt;mainClass&amp;gt;com.home.server.TelegramBot&amp;lt;/mainClass&amp;gt;
                        &amp;lt;name&amp;gt;workerBot&amp;lt;/name&amp;gt;
                    &amp;lt;/program&amp;gt;
                &amp;lt;/programs&amp;gt;
            &amp;lt;/configuration&amp;gt;
            &amp;lt;executions&amp;gt;
                &amp;lt;execution&amp;gt;
                    &amp;lt;phase&amp;gt;package&amp;lt;/phase&amp;gt;
                    &amp;lt;goals&amp;gt;
                        &amp;lt;goal&amp;gt;assemble&amp;lt;/goal&amp;gt;
                    &amp;lt;/goals&amp;gt;
                &amp;lt;/execution&amp;gt;
            &amp;lt;/executions&amp;gt;
        &amp;lt;/plugin&amp;gt;
    &amp;lt;/plugins&amp;gt;
&amp;lt;/build&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before starting this process, you should register on Heroku, and install both Git and the Heroku CLI. If your application needs a database, then don’t forget to add the required database when you create a new application. Further, you need to determine the host, username, password and port for your database, and then indicate them in your application. Next, before deploying, build your project using Maven.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mvn clean install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;First, we go to our project directory and initialize the repository with the command &lt;code&gt;git init&lt;/code&gt;. Then we add our project to this repository.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Then we commit the changes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "First commit in the project"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Next, you need to sign in to heroku. Write the following on the command line&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Enter the credentials you created during registration. After that, determine your repository’s URL on heroku. You do this in the settings. Then we write&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add heroku [url]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;A remote heroku repository is added for your repository. Next we write&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push heroku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Then we wait… if the application deploys successfully, execute the following command&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku ps:scale worker=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it, your application is up and running. If it isn’t, look at the logs carefully. Most likely, an error in your application has caused it to fail.&lt;/p&gt;

&lt;p&gt;Thank you for reading such a long article. I hope someone will find it useful and that it will save you a lot of time in the areas that gave me trouble during development.&lt;/p&gt;

&lt;p&gt;Previously was published on &lt;a href="https://codegym.cc/groups/posts/50-creating-a-telegram-bot-in-java--from-conception-to-deployment" rel="noopener noreferrer"&gt;CodeGym blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>Top 21 Interview Questions for Java Developers You Totally Should Know</title>
      <dc:creator>CodeGym</dc:creator>
      <pubDate>Tue, 19 Feb 2019 13:45:23 +0000</pubDate>
      <link>https://forem.com/codegym_cc/top-21-interview-questions-for-java-developers-you-totally-should-know-4n3l</link>
      <guid>https://forem.com/codegym_cc/top-21-interview-questions-for-java-developers-you-totally-should-know-4n3l</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J71YbrUo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/gjlerrkp99rfd3ksq9rw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J71YbrUo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/gjlerrkp99rfd3ksq9rw.jpeg" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are myriads of Java interview questions and we can’t collect all of them in one article. However here you can find some very common Java interview questions, according to HR-managers of IT companies.&lt;/p&gt;

&lt;h3&gt;1. “Disassemble” &lt;code&gt;&lt;strong&gt;public static void main(String args[])&lt;/strong&gt;&lt;/code&gt;.&lt;/h3&gt;

&lt;p&gt;One of the popular java interview questions for freshers, and easy one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;public&lt;/code&gt; is an access modifier. We use it to specify access to this method. Here modifier is “public”, so any Class has access to this method.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;static.&lt;/code&gt; This Java keyword means that we use this method without creating a new Object of a Class.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Void&lt;/code&gt; is the return type of the method. It means that the method doesn’t return any value.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;main&lt;/code&gt; is the name of the method. JVM “knows” it as an entry point to an application (it should have a particular signature). Main is a method where the main execution occurs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;String args[].&lt;/code&gt; This is the parameter passed to the main method. Here we have the arguments of String type that your Java application accepts when you run it. You can type them on the terminal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;2. What is the difference between &lt;code&gt;equals()&lt;/code&gt; and &lt;code&gt;==&lt;/code&gt; ?&lt;/h3&gt;

&lt;p&gt;First, “&lt;code&gt;==&lt;/code&gt;” is an operator whereas &lt;code&gt;equals()&lt;/code&gt; is a method. We use &lt;code&gt;==&lt;/code&gt; operator for reference comparison (or address comparison) and &lt;code&gt;equals()&lt;/code&gt; method for content comparison. It means that &lt;code&gt;==&lt;/code&gt; checks if both objects point to the same memory location while &lt;code&gt;equals()&lt;/code&gt; compares values in the objects.&lt;/p&gt;

&lt;h3&gt;3. Can we execute a program without &lt;code&gt;main()&lt;/code&gt; method?&lt;/h3&gt;

&lt;p&gt;Many java basic interview questions are really easy. Like this one. So short answer is: yes, we can. For example, we can do it using a static block.&lt;/p&gt;

&lt;p&gt;You can use a static block to initialize the static data member. It is executed before the &lt;code&gt;main&lt;/code&gt; method, at the time of class loading.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Example{
 Static{ 
System.out.println("static block is invoked"); 
} 
  public static void main(String args[]){ 
   System.out.println("Now main method"); 
  } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;b&gt;The output is:&lt;/b&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**static** block is invoked 
Now main method
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What about total main method absence? If you try to run an ordinary class without the main method at all, you got the next error: &lt;/p&gt;

&lt;p&gt;Main method not found in class Test, please define the main method as: &lt;code&gt;public static void main (String [] args)&lt;/code&gt; or a JavaFX application class must extend &lt;code&gt;javafx.application.Application&lt;/code&gt;. &lt;br&gt;
The error itself says that if this is a JavaFX application and the class is inherited from &lt;code&gt;javafx.application.Application&lt;/code&gt;, then it is possible.&lt;/p&gt;

&lt;h3&gt;4. What is &lt;code&gt;immutable&lt;/code&gt; object? Can you create &lt;code&gt;immutable&lt;/code&gt; object?&lt;/h3&gt;

&lt;p&gt;You can’t modify objects of an &lt;code&gt;immutable&lt;/code&gt; class after their creation. So once you create them, you can’t change them. If you try to modify &lt;code&gt;Immutable&lt;/code&gt; object you get a new object (clone) and change this clone while creation.&lt;/p&gt;

&lt;p&gt;A good example is &lt;code&gt;String&lt;/code&gt;, it is &lt;code&gt;immutable&lt;/code&gt; in Java. That means you cannot change the object itself, but you can change the reference to the object.&lt;/p&gt;

&lt;h3&gt;5. How many objects are created in the following code?&lt;/h3&gt;

&lt;p&gt;One of the Java technical interview questions that substitutes #4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String s1="Hello"; 
String s2="Hello"; 
String s3="Hello";

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The answer is “only one” because Java has a String Pool. When we create a String object using the &lt;code&gt;new()&lt;/code&gt; operator, it creates a new object in heap memory. If we use String literal syntax, like in our example, it may return an existing object from the String pool, if it already exists.&lt;/p&gt;

&lt;h3&gt;6. How many objects are created in the following code?&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String s = new String("Hello");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are 2 objects. One is in string constant pool and the other in heap.&lt;/p&gt;

&lt;h3&gt;7. What is the difference between &lt;code&gt;String&lt;/code&gt;, &lt;code&gt;StringBuilder&lt;/code&gt; and &lt;code&gt;StringBuffer&lt;/code&gt; classes in Java?&lt;/h3&gt;

&lt;p&gt;There is one of the leaders in top java interview questions.&lt;/p&gt;

&lt;p&gt;First of all &lt;code&gt;String&lt;/code&gt; is an Immutable class. That means you can’t modify its content once created. While &lt;code&gt;StringBuffer&lt;/code&gt; and &lt;code&gt;StringBuilder&lt;/code&gt; are mutable classes, so you can change them later. If we change the content of &lt;code&gt;String&lt;/code&gt; object, it creates a new string, therefore, it doesn’t modify the original one. That’s why the performance with &lt;code&gt;StringBuffer&lt;/code&gt; is better than with &lt;code&gt;String&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The main difference between &lt;code&gt;StringBuffer&lt;/code&gt; and &lt;code&gt;StringBuilder&lt;/code&gt; that &lt;code&gt;StringBuffer&lt;/code&gt;’s methods are synchronized while &lt;code&gt;StringBuilder&lt;/code&gt;’s are not.&lt;/p&gt;

&lt;h3&gt;8. Is there any difference in &lt;code&gt;String&lt;/code&gt; that was created using literal and with &lt;code&gt;new()&lt;/code&gt; operator?&lt;/h3&gt;

&lt;p&gt;It is. If we create a string with &lt;code&gt;new()&lt;/code&gt; operator it appears in heap and not added to string pool. If you create &lt;code&gt;String&lt;/code&gt; using literal it is created in &lt;code&gt;String&lt;/code&gt; pool which exists in Perm area of heap.&lt;/p&gt;

&lt;h3&gt;9. Can you override &lt;code&gt;private&lt;/code&gt; or &lt;code&gt;static&lt;/code&gt; method in Java?&lt;/h3&gt;

&lt;p&gt;One of java tricky interview questions for rookies. You really can’t override &lt;code&gt;private&lt;/code&gt; or &lt;code&gt;static&lt;/code&gt; method in Java.&lt;/p&gt;

&lt;p&gt;You can’t override the &lt;code&gt;private&lt;/code&gt; methods because the scope of the private access specifier is only within the class. When you are going to override something, we should have a parent and child class. If the method of superclass is &lt;code&gt;private&lt;/code&gt;, child class can’t use it, and the methods in child class will be treated as new methods (not overridden).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Static&lt;/code&gt; methods also cannot be overridden, because &lt;code&gt;static&lt;/code&gt; methods are the part of the Class itself, and not a part of any object of the class. Sure you can declare the same &lt;code&gt;static&lt;/code&gt; method with the same signature in child classes, but again, they will be treated as new methods.&lt;/p&gt;

&lt;h3&gt;10. Difference between &lt;code&gt;Abstract Class&lt;/code&gt; and &lt;code&gt;Interface&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;One of the popular java developer interview questions that bears on OOP principles. First of all, in Java &lt;code&gt;interface&lt;/code&gt; defines behavior and &lt;code&gt;abstract class&lt;/code&gt; creates a hierarchy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g6vqFG4H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/vdix55tmwjjg62juyvui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g6vqFG4H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/vdix55tmwjjg62juyvui.png" width="800" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;11. Can we declare &lt;code&gt;static&lt;/code&gt; variables and methods in an &lt;code&gt;abstract&lt;/code&gt; class?&lt;/h3&gt;

&lt;p&gt;Yes, it is possible to declare &lt;code&gt;static&lt;/code&gt; variables and methods in &lt;code&gt;abstract&lt;/code&gt; method. There is no requirement to make an object to access the static context. So we are allowed to access the static context declared inside the &lt;code&gt;abstract&lt;/code&gt; class by using the name of the &lt;code&gt;abstract&lt;/code&gt; class.&lt;/p&gt;

&lt;h3&gt;12. What types of memory areas are allocated by JVM?&lt;/h3&gt;

&lt;p&gt;&lt;b&gt;Class Area&lt;/b&gt; stores perclass structures, for example, runtime constant pool, fields, method datas, and all the code for methods.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Heap&lt;/b&gt; is a runtime data area where memory is allocated to the objects.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Stack&lt;/b&gt; stores frames. It contains local variables and partial results, and takes part in method invocation and return. Every thread has a private JVM stack, created at the same time as the thread. A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Program Counter Register&lt;/b&gt; contains an address of the Java virtual machine instruction currently being executed.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Native Method Stack&lt;/b&gt; contains all the native methods that are used in the application.&lt;/p&gt;

&lt;h3&gt;13. Why is multiple inheritance isn’t allowed in java?&lt;/h3&gt;

&lt;p&gt;It would be really complicated. Imagine three classes &lt;code&gt;A&lt;/code&gt;, &lt;code&gt;B&lt;/code&gt;, and &lt;code&gt;C&lt;/code&gt; and &lt;code&gt;C&lt;/code&gt; inherits &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt;. Now, &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt; classes have the same method and you call it from a child class object... Which one? &lt;code&gt;A&lt;/code&gt;’s or &lt;code&gt;B&lt;/code&gt;’s? Here we have ambiguity. If you try to inherit two classes Java renders compile time error.&lt;/p&gt;

&lt;h3&gt;14. Can we overload the &lt;code&gt;main()&lt;/code&gt; method?&lt;/h3&gt;

&lt;p&gt;Sure, we are allowed to have many main methods in a Java program by using method overloading. Try it out!&lt;/p&gt;

&lt;h3&gt;15. Can we declare a constructor as &lt;code&gt;final&lt;/code&gt;?&lt;/h3&gt;

&lt;p&gt;Nope. A constructor can’t be declared as a &lt;code&gt;final&lt;/code&gt; because it can’t be inherited. So it is senseless to declare constructors as &lt;code&gt;final&lt;/code&gt;. However, if you try to do it, Java compiler throws you an error.&lt;/p&gt;

&lt;h3&gt;16. Can we declare an interface as &lt;code&gt;final&lt;/code&gt;?&lt;/h3&gt;

&lt;p&gt;No, we can’t do this. An interface can’t be &lt;code&gt;final&lt;/code&gt; because the interface should be implemented by some class according to its definition. Therefore, there is no sense to make an interface &lt;code&gt;final&lt;/code&gt;. However, if you try to do so, the compiler will show an error.&lt;/p&gt;

&lt;h3&gt;17. What is the difference between &lt;code&gt;static binding&lt;/code&gt; and &lt;code&gt;dynamic binding&lt;/code&gt;?&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;binding&lt;/code&gt; which can be resolved at compile time by a compiler is called &lt;code&gt;static&lt;/code&gt; or early binding. &lt;code&gt;Binding&lt;/code&gt; of all the &lt;code&gt;static&lt;/code&gt;, &lt;code&gt;private&lt;/code&gt; and &lt;code&gt;final&lt;/code&gt; methods is done at compile-time.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;Dynamic binding&lt;/code&gt; compiler can’t choose a method to be called. Overriding is a perfect example of &lt;code&gt;dynamic binding&lt;/code&gt;. In overriding both parent and child classes have the same method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Static Binding 
class Cat{ 
 private void talk() 
{System.out.println("cat is mewing..."); 
} 
&amp;lt;/code&amp;gt;
&amp;lt;code&amp;gt; public static void main(String args[]){ 
  Cat cat=new Cat(); 
  cat.talk(); 
 } 
} &amp;lt;/code&amp;gt;
&amp;lt;code&amp;gt;Dynamic Binding 
class Animal{ 
 void talk(){ 
System.out.println("animal is talking..."); 
} 
} &amp;lt;/code&amp;gt;
&amp;lt;code&amp;gt;class Cat extends Animal{ 
 void talk(){ 
System.out.println("cat is talking...");
} &amp;lt;/code&amp;gt;
&amp;lt;code&amp;gt; public static void main(String args[]){ 
  Animal animal=new Cat(); 
  animal.talk(); 
 } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;18. How to create a read-only class in Java?&lt;/h3&gt;

&lt;p&gt;You can do it by making all of the class’ fields private. The read-only class has only getter methods which return the private property of the class to the &lt;code&gt;main&lt;/code&gt; method. You are not able to modify this property, the reason is the lack of setters method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class HockeyPlayer{ 
private String team ="Maple leaf"; 
public String getTeam(){ 
return team; 
} 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;19. How to create a write-only class in Java?&lt;/h3&gt;

&lt;p&gt;Again, you should make all of the class’ fields &lt;code&gt;private&lt;/code&gt;. Now, your write-only class should have only setter methods and no getters. Therefore, we can’t read the properties of the class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class HockeyPlayer{ 
private String team; 
public void setTeam(String college){ 
this.team = team; 
} 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;20. Each &lt;code&gt;try&lt;/code&gt; block must be followed by a &lt;code&gt;catch&lt;/code&gt; block, mustn’t it?&lt;/h3&gt;

&lt;p&gt;Nope. It is not a necessity. Each-try block can be without a catch block. It could be followed by either a &lt;code&gt;catchblock&lt;/code&gt; or a finally block or even without them at all.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main{ 
     public static void main(String []args){ 
        try{ 
            int variable = 1; 
            System.out.println(variable/0); 
        } 
        finally 
        { 
            System.out.println("the other part of the program..."); 
        } 
     } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Main {
        public static void main(String[] args) throws IOException {
            try(InputStreamReader inputStreamReader = new InputStreamReader(System.in);
                BufferedReader reader = new BufferedReader(inputStreamReader)){
                System.out.println("test");
            }
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;P.S.: Before Java 8 methods in interfaces could have been abstract only. In Java 8 or newer, it became possible to define default methods and implement them directly in the interface.&lt;/p&gt;

&lt;h3&gt;21. What is the difference between &lt;code&gt;throw&lt;/code&gt; and &lt;code&gt;throws&lt;/code&gt; keywords?&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Throws&lt;/code&gt; is used to declare an exception, so it works similar to the &lt;code&gt;try-catch&lt;/code&gt; block. &lt;code&gt;Throw&lt;/code&gt; keyword is used to throw an exception explicitly from a method or any other block of code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Throw&lt;/code&gt; is followed by an instance of &lt;code&gt;Exception&lt;/code&gt; class and throws is followed by exception class names.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Throw&lt;/code&gt; is used in the method body to throw an exception. &lt;code&gt;Throws&lt;/code&gt; is used in a method signature to declare the exceptions that may occur in the statements present in the method.&lt;/p&gt;

&lt;p&gt;It is allowed to throw one exception at a time but you can handle multiple exceptions by declaring them using &lt;code&gt;throw&lt;/code&gt;keyword. You can declare multiple exceptions, e.g., &lt;code&gt;public void method()throws IOException&lt;/code&gt;, &lt;code&gt;SQLException&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here we had only a few java interview questions and answers. This article is the first of interview series. The next one (coming soon) is about data structure questions.&lt;/p&gt;

&lt;p&gt;First was published on &lt;a href="https://codegym.cc/groups/posts/78-top-21-java-interview-questions" rel="noopener noreferrer"&gt;CodeGym blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>coding</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
