← 输入框|github.com|刷新
Skip to content

About

Transition dotnet to java develop guide

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Transition .NET Framework to Java developer guide

Write once, run anywhere (c)

How to use

Preparation

Download and install required tools and software

  1. Java 11.0.2 (build 11.0.2+9)

    1. Set up JAVA_HOME and add Java bin to path for Windows for Mac
    2. Verify. Result of echo %JAVA_HOME%(Windows, for Mac use echo $JAVA_HOME) java --version should be something like this
      C:\Users\user>echo %JAVA_HOME%
      C:\workspace\soft\jdk-11.0.13+8
      
      C:\Users\ychum>java --version
      openjdk 11.0.13 2021-10-19
      OpenJDK Runtime Environment Temurin-11.0.13+8 (build 11.0.13+8)
      OpenJDK 64-Bit Server VM Temurin-11.0.13+8 (build 11.0.13+8, mixed mode)
      
  2. Download and install Maven

    1. Verify. Result of mvn --version should be something like this
      C:\Users\user>mvn --version
      Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
      Maven home: c:\workspace\soft\apache-maven-3.6.3\bin\..
      Java version: 11.0.13, vendor: Eclipse Adoptium, runtime: C:\workspace\soft\jdk-11.0.13+8
      Default locale: en_US, platform encoding: Cp1252
      OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
      
  3. Java IDE IntelliJ IDEA Community edition. Set up Intellij Idea to use your Java

Ecosystem overview

Java platform

https://www.oracle.com/java/technologies/platform-glance.html

Comparison with .NET Framework

https://www.overops.com/blog/clr-vs-jvm-how-the-battle-between-net-and-java-extends-to-the-vm-level

More info about JVM

Release cycle

Most commonly available JDKs

Difference between OpenJDK and Adoptium/AdoptOpenJDK

Build tools

Building results

The diagram below depicts building and running Java archive (jar)

Build tools overview

Maven

Getting Started in 5 Minutes

Getting Started in 30 Minutes

Lifecycles

Courses

Basics

Language basics

Oracle code conventions

Google Java Style Guide

Object

Object methods

Core

Recommended books

Courses

Tutorial Java language updates

Objects equality

Equals and hashcode

Exceptions

Tutorial

Collections

Collections Tutorial

Generics

Tutorial

Stream API vs LINQ

Comparison

Stream API #1 #2

Optional

Date time

Annotations

Tutorial

First console application

Intellij IDEA | Creating a Maven project

Maven project structure, detailed see

dotnet2java\java\console-app\src\main\java\com\mycompany\app\HelloWorldApp.java

public class HelloWorldApp {

  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}

How to run

  1. IntelliJ IDEA
  2. Console
    1. Make sure that you are in console-app folder

      $ pwd
      /code/dotnet2java/java/console-app
      
    2. Run maven to build jar

      mvn clean package
      
    3. Run Java program

      java -cp  ./target/console-app-1.0-SNAPSHOT.jar com.mycompany.app.HelloWorldApp
      

A Closer Look at the "Hello World!" Application

Unit testing

Usually, JUnit is usually used in conjunction with Mockito. Alternative testing framework is TestNG. Powermock as mocking extension for Mockito or EasyMock to test private or static methods.

Example

Let's imagine we have basic calculator with simple method that adds two integers.

dotnet2java\java\console-app\src\main\java\com\mycompany\app\BasicCalculator.java

public class BasicCalculator {

  public int addTwoIntegers(int firstInteger, int secondInteger) {
    return Math.addExact(firstInteger, secondInteger);
  }
}

In order to test at least 1 positive and 1 negative scenarios, we can create something like this: dotnet2java\java\console-app\src\test\java\com\mycompany\app\BasicCalculatorTest.java

package com.mycompany.app;

import org.junit.Assert;
import org.junit.Test;

public class BasicCalculatorTest {

  private final BasicCalculator calculator = new BasicCalculator();

  @Test
  public void shouldAddTwoIntegersTest() {
    //given
    int firstInteger = 1;
    int secondInteger = 3;

    //when
    int actual = calculator.addTwoIntegers(firstInteger, secondInteger);

    //then
    int expected = 4;
    Assert.assertEquals(expected, actual);
  }

  @Test(expected = ArithmeticException.class)
  public void shouldThrowArithmeticExceptionInCaseOverflow() {
    //given
    int firstInteger = Integer.MAX_VALUE;
    int secondInteger = Integer.MAX_VALUE / 2;

    //when
    calculator.addTwoIntegers(firstInteger, secondInteger);
  }

}

To run tests, make sure that you in the same folder as pom.xml and run mvn clean test. After maven execution, you will see:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.mycompany.app.BasicCalculatorTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.041 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Logging

Built in

SLF4J as logging facade

Log4j2

Logback

Web

Spring

Spring overview

Courses

Main concepts

Spring vs ASP .NET Framework

Comparison

Spring boot and starters

Overview

Article

First web application

TODO

12 factor

Origin

Cloud Native Apps

Template language

Mustache

Thymeleaf

Observability

Zipkin

Jaeger

Application metrics

ORM

JDBC

What is JDBC?

Tutorial

JPA

What is JPA?

Hibernate

Recommended blog

Entity states

Article

N+1 problem

Article

Utils

Objects mapping

JSON for Java

Jackson tutorial

Java bean mappings

Lombok

Project lombok is an annotation-based Java library that allows you to reduce boilerplate code using code generation. Alternative solution can be records introduced in Java 14.

Advanced

Concurrency

Recommended books

Tutorial

JLS Chapter 17

Troubleshooting

Guide

VM Options

Architecture

Recommended books

About

Transition dotnet to java develop guide

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages