Home » Archives for Mary Zheng

Author Archives: Mary Zheng

Mary Zheng
Mary has graduated from Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She works as a senior Software Engineer in the telecommunications sector where she acts as a leader and works with others to design, implement, and monitor the software solution.

Java Unit Testing with JUnit Example

This is an article for Java Unit Testing with JUnit Example. 1. Introduction Java unit testing is a software testing where methods and classes are tested. JUnit is a unit testing framework for the Java programming language which provides a way to test the application as many as you want. Unit testing usually includes the following steps: define a testcreate ...

Read More »

Java Unit Testing Tutorial

This is a tutorial for Java unit testing. In this tutorial, I will create a spring boot application which includes test cases written with Junit, Mockito, and Spring test. The overall unit tests cover 90 percent of the application. Table Of Contents 1. Introduction 2. Unit Testing Frameworks 3. Technologies Used 4. Maven Project 4.1 Dependencies 4.2 Application Properties 4.3 ...

Read More »

Hashset Java Example

1. Introduction The HashSet class is a part of the Java Collection API since JDK 1.2. It extends from the AbstractSet class and implements the Set Java interface. It uses HashMap internally. Figure 1 HashSet You can also check the Java Set Example in the following video: Java Set Example – Video The HashSet class contains unique elements. It permits ...

Read More »

Java Stream Map Example

1. Introduction Java has provided Stream API to iterate and process elements in a collection with a declarative style since version 8. A stream is a sequence of objects that can be constructed via the default java.util.Collection.stream() method, static java.util.Arrays.stream() method, static java.nio.file.Files.lines() method, etc. Streams don’t change the element data. Stream API provides intermediate and terminal operations to process ...

Read More »

Linear Search Java Example

1. Introduction Linear search is a computer algorithm which finds an element from an array sequentially. The time complexity is O(n) in the worst case – meaning the element is the last element of the array or not in the array. The time complexity is O(1) in the best case – meaning the element is the first element of the ...

Read More »

Multiple Inheritance Java Example

1. Introduction Multiple inheritance means that a class inherits fields and methods from more than one parent. Java class does not support multiple inheritance as it cannot have more than one parent. Java supports multiple inheritance via interface because an interface can have more than one parent. The “diamond problem” is an ambiguity that arises when two classes B and ...

Read More »

What is a Field in Java ?

1. Introduction Java is an object-oriented programming language which uses “object” concept to group data and methods in a class. A variable defined in a class is called a field. A field is declared by specifying its type and name. In this example, I will demonstrate: Declare a field for the primitive data type, object, and collectionAdd static, final, transient, ...

Read More »

Pi in Java Example

In this post, we feature a comprehensive article about Pi in Java. 1. Introduction PI is a mathematics number defined as the circumference of any circle divided by its diameter. Java has provided the java.lang.Math class since version 1. It includes a static constant PI with value of 3.141592653589793. /*the double value that is closer than any other to pi, ...

Read More »

isDigit Java Example

1. Introduction Java provides a java.lang.Character class to wrap a value of the primitive type char in an object. It has provided several methods for determining a character’s category, such as lowercase letter, digit, etc since version 5. Here are the isDigit method’s signatures: //Determines if the specified character is a digit. static boolean isDigit​(char ch) //Determines if the specified character (Unicode ...

Read More »

Breadth First Search Java Example

1. Introduction Breadth First Search (BFS) is a traversing or searching algorithm for a tree or graph data structure. BFS starts at the tree root, and explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level. A tree is a nonlinear data structure which includes a root and ...

Read More »