GithubHelp home page GithubHelp logo

bobocode-projects / java-fundamentals-exercises Goto Github PK

View Code? Open in Web Editor NEW
369.0 18.0 385.0 770 KB

Training Exercises that cover language basics, Algorithms, Data Structures, OOP, and Functional Programming

License: Apache License 2.0

Java 100.00%
java learning fundamentals java-8 computer-science

java-fundamentals-exercises's Introduction

Welcome to the Java Fundamentals Exercises

Build strong fundamental skills that you will need for real-world Enterprise Java development

Why

Most people don’t know how to learn Enterprise Java efficiently. So we create an Open-source Java Education that helps them to master strong skills, learn world best practices and build a successful career. 🚀

At Bobocode we have extensive experience in both building Enterprise Java applications and organizing efficient learning. Therefore, this course covers what you need in the most efficient way. We believe that the key to efficient learning is practice. 💪 And as a software engineer, you should spend as much time as you can in the IDE writing code. At the end of the day, this is the only place where you build software... 💻

About this repo

Java Standard Edition is huge. Computer Science is huge. Object-Oriented programming, as well as Functional programming, are also pretty big topics. So how can you learn everything you need and don't get stuck for years learning fundamentals only? 🤔 You're in the right place to find the answer. 😀

This repo gives you two uniques features that will help you to master fundamentals ASAP:

  1. It consists of selected topics that are must-have for real-world enterprise Java development ⭐️
  2. It is fully based on special training exercises that put your practice on rails and boost up your learning efficiency 🚀

Go ahead and check out Introduction module 👍

java-fundamentals-exercises's People

Contributors

andrii-k6a avatar boserhii avatar dimayakovenko avatar kastyan-kg avatar maxstasiuk92 avatar meitoseshifu avatar mepv avatar mk-javadeveloper avatar mrfim avatar mykhailobeheka avatar repnazar avatar shryhus avatar skolach avatar stanislav-zabramnyi avatar tboychuk avatar v-kuzma avatar vitshch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-fundamentals-exercises's Issues

3-6-3-crazy-regex. findOnlyDuplicates() method

It seems that the task description or test may be incorrect or unclear.

The regular expression "\b(\w+)\s\1\b" matches two consecutive instances of the same word separated by a single whitespace character (\s), but it does not actually find all duplicates in the string.

2-2-5-array-list, removeElementByIndex fails with working code

The following code is not accepted by 24-th test in ArrayListTest. But this code works just fine.

@Override
    @SuppressWarnings("unchecked")
    public T remove(int index) {
        Objects.checkIndex(index, size);

        T removedElement = (T) elements[index];
        Object[] copy = new Object[elements.length];

        System.arraycopy(elements, 0, copy, 0, index);
        System.arraycopy(elements, index + 1, copy, index, size - index - 1);

        elements = copy;
        size--;
        return removedElement;
    }

It works perfectly, if you just move internalArray initialization down like this:

@Test
    @Order(24)
    void removeElementByIndex() {
        fillTestArray(15, 69, 58, 78, 100);


        int removedElement = arrayList.remove(2);

        Object[] internalArray = getTestArray();

        assertThat(internalArray[2]).isEqualTo(78);
        assertThat(internalArray[1]).isEqualTo(69);
        assertThat(getTestSize()).isEqualTo(4);
        assertThat(removedElement).isEqualTo(58);
    }

2-2-4-linked-list, add tests accept the broken code

The broken code:

private void addAsHead(Node<T> newNode) {
        newNode.next = head;
        head = newNode;
}

Please consider the following example:

LinkedList<Integer> list = new LinkedList<>();
        list.add(0, 100);
        list.add(144);

This code will result in a NullPointerException if we define the add method as follows:

@Override
    public void add(T element) {
        requireNonNull(element);
        Node<T> newNode = new Node<>(element);

        if(head == null){
            head = tail = newNode;
        } else {
            tail.next = newNode;
            tail = tail.next;
        }
        size++;
    }

It's necessary to reassign tail, as shown in the "completed" branch.

3-6-3-crazy-regex. There is a mistake in the branch 'completed'.

I refer to the findLastWord() and findFirstWord() methods.

If you add the string " ........." to the end of the note.txt file like this, the regex from the branch "completed" won't pass the tests, which is "\w+$".

As far as I am concerned, we should use something like "\w+(?=\W*$)" instead.

Please, let me know If I am mistaken here.

Configure a synchronization between Jira and GitHub

In order to let other folks contribute, we need to set up a corresponding process on GitHub. Other OSS projects usually expose a simple board with tickets (like this) + a document (a guide) that describes how to contribute.

We use Jira for all our projects, and we’ll continue doing that. But it will be useful to expose a board on GitHub.

Ask

Configure sync between our Jira and our GitHub. One possible solution is https://unito.io/, but maybe we’re not limited to that. Having that configuration we should be able to create tickets in Jira and have them automatically created in GitHub.

I am not sure how we should be doing this. E.g. we can have a separate project and separate board in each GitHub repo. Or we can have a common board. It is important to map it properly, so issues are created in the right repo. (If we work on fundamentals, and create a ticket in Jira, the issue should be created in fundamentals repo). I don’t know how to map it. Probably using epics…

We should configure the mapping for

  • ticket creation (name and description)
  • status change (so it will be moved from column to column)
  • comments

ArrayList add test does not work properly with this example

Hello. The test does not fail with this corrupted code:

 @Override
    public void add(T element) {
        Objects.requireNonNull(element);

        if (elements.length != size) {
            elements[size] = element;
        } else {
            Object[] copy = new Object[size * 2];
            System.arraycopy(elements, 0, copy, 0, size);
            elements = copy;
        }
        size++;
    }
We should check at least 5 elements (if InitialCapaciti is 5):
  void add() {
       arrayList.add(10);
       arrayList.add(15);
       arrayList.add(20);
       arrayList.add(21);
       arrayList.add(24);
       arrayList.add(845);

       Object[] internalArray = getTestArray();

       assertThat(internalArray[0]).isEqualTo(10);
       assertThat(internalArray[1]).isEqualTo(15);
       assertThat(internalArray[2]).isEqualTo(20);
       assertThat(internalArray[3]).isEqualTo(21);
       assertThat(internalArray[4]).isEqualTo(24);
       assertThat(internalArray[5]).isEqualTo(845);
   }

2-2-4-linked-list, remove tests accept the broken code

The next broken code is accepted:

@Override
    public T remove(int index) {
        checkIndex(index, size);

        if (index == 0) {
            return removeHead();
        } else if (index == size - 1) {
            return removeTail();
        } else {
            return removeInBetween(index);
        }
    }

    private T removeInBetween(int index) {
        Node<T> previous = getNodeByIndex(index - 1);
        T removed = previous.next.element;
        previous.next = previous.next.next;

        size--;

        return removed;
    }

    private T removeTail() {
        T removed = tail.element;

        Node<T> preTail = getNodeByIndex(size - 2);
        preTail.next = null;
        tail = preTail;

        size--;
        return removed;
    }

    private T removeHead() {
        T removed = head.element;
        head = head.next;
        size--;
        return removed;
    }

Please consider the following example:

LinkedList<Integer> list = LinkedList.of(10);

        System.out.println(list.remove(0));

        System.out.println(list.size());
        System.out.println(list.getLast());

In this example, we can still get the "last" element even if size == 0.

It's necessary to reassign tail, as shown below:

private T removeHead() {
        T removed = head.element;
        head = head.next;
        size--;

        if(head == null){
            tail = null;
        }

        return removed;
    }

Create a red-black-tree exercise

I believe it's pretty self-explanatory. The first step would be to do the research in order to understand the tree details and implement the tree. Once we have a raw implementation, we can continue the discussion. ❗️

Location & name

2-2-7-red-black-tree

Tests

The only way to provide step-by-step test instructions is to use Reflection AP so I believe we will need to follow the same approach as we did with BST.

2-2-7 resizeTable() method's test accepts this corrupted code

The accepted corrupted code:

@SuppressWarnings("unchecked")
    public void resizeTable(int newCapacity) {
        Node<K, V>[] newTable = new Node[newCapacity];
        for (int i = 0; i < table.length; i++){
            int newIndex = calculateIndex(table[i], newCapacity);
            newTable[newIndex] = table[i];
        }
        table = newTable;
    }

Please, consider my test variation:

@Test
        @Order(1)
        @DisplayName("resizeTable creates a new array and put there all elements")
        void resizeTable() {
            for(int i = 10; i < 40; i++){
                addToTable(String.valueOf(i), i % 7);
            }

            hashTable.resizeTable(64);

            assertThat(getInternalTable(hashTable)).hasSize(64);

            for(int i = 10; i < 40; i++){
                assertTrue(checkKeyValueExists(String.valueOf(i), i % 7));
            }
        }

Add crazy-regex exercise

@Meitoseshifu let's track the work using this issue. Please create an initial PR targeting to main, so I can add some comments and we will continue from there.

java-fundamentals-course/0-0-intro/.../Introduction.java

/**
...
Every exercise is covered with tests. So when you're implementing some class like {@link Introduction}, you should
also be able to find a corresponding class like {@link IntroductionTest}.
...
*/

В JavaDoc'у отримую таку помилку:
Cannot resolve symbol 'IntroducionTest'
Як її позбутися?

Migrate to Java 17

Since Java 17 is already GA and it's an LTS version, we can start this migration.

Please make sure that you properly tested both main and completed before creating the PR.

Please create a PR to completed as well. (Technically there is no need for the second PR because we always merge main into completed but having the second PR we'll let us see that the build on completed branch pass.

New Exercise "Java Articles Searcher"

The implementation should analyze some web page for available Java materials and have some API for getting specific information about the page.

Interface:

  • int getAmountOfRepetives(String string)
  • int getAmountOfImages()
  • int GetAmountOfLinks()
  • void createFileFromPage()

Using:

  • URL API
  • Url Connection API

1-3-1-crazy-generics, hasDuplicates' test accepts the broken code

The broken code:

public static <T extends BaseEntity> boolean hasDuplicates(List<T> entities, T targetEntity) {
            return entities.stream()
                    .map(BaseEntity::getUuid)
                    .distinct()
                    .count() != entities.size();
        }

This code doesn't check if the target entity is in the list, so we need to add something like this to the tests to ensure that the target entity is in the list:

...
arguments(List.of(uniqueEntity, uniqueEntity, uniqueEntity), duplicateEntity1, false)
...

2-2-7 containsValue method accepts wrong solution

The containsValues()'s tests accept this wrong solution.

This solution doesn't work if in the bucket's element are more than one Node.

@Override public boolean containsValue(V value) { return Arrays.stream(table) .filter(Objects::nonNull) .map(node -> node.value) .anyMatch(v -> v.equals(value)); }

Create new hello-threads exercise

The main goal of this exercise is to introduce threads and let people get their hands dirty with concurrent code. It should be an entry-level exercise that does not require previous experience with concurrency.

Location

  • create a new high-level module 7-0-java-concurrency
  • add 7-0-0-hello-theads exercise

Task

I guess it should be something like one class with a list of very simple methods. Each of those methods should require a person to implement a simple Thread-related logic. Here's a complete example

  • accept some logic as Runnable and return a new Thread based on it
  • accept a thread and start it
  • accept a thread and return its name
  • accept a thread and return its state
  • accept some logic, create a thread, start it and return it
  • accept working thread and wait for it to complete (join)
  • accept a thread and return its state
  • accept a list of tasks (Runnable) and return a list of threads that are in progress
  • accept a thread and make it sleep

Appreciation Post

It's one of the best hands-on resources to get your hands dirty with Java.
I really like the exercise quality and difficulty level, they do tend to teach something new about java.

I also went through your org website. Kinda felt disappointed to see all the teaching material is in Russian only. Would appreciate if you guys can create any course for English viewers.

2-2-4-linked-list, contains()'s tests accept this wrong solution

The corrupted code:

@Override
    public boolean contains(T element) {
        requireNonNull(element);
        Node<T> current = head;

        if(!isEmpty()){
            while (current.next != null){
                if (current.element.equals(element)){
                    return true;
                }
                current = current.next;
            }
        }

        return false;
    }

It would be great to check in tests for the presence of the last element in the list.

Fix typos found in README.md and CONTRIBUTING.MD

Issue description

There are a couple of typos in README.md and CONTRIBUTING.MD files.

README.md 5-0-functional-programming

ablte

- At the end of this module you will be ablte to
+ At the end of this module you will be able to

to uderstnad way

- process data collections in a concise and easy to uderstnad way using Stream API
+ process data collections in a concise and easy way to understand using Stream API

CONTRIBUTING.MD

brnach

- 7. Merge your exercise branch into the solution brnach
+ 7. Merge your exercise branch into the solution branch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.