Home » Author Archives: 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 12 New Features Tutorial

In this tutorial, I will demonstrate how to install JDK12 and dive into several API changes with Java examples. Table Of Contents 1. Introduction 2. Technologies Used 3. Set Up 3.1 Install Oracle Open JDK 12 3.2 Install Eclipse 4.11 3.3 Maven Project 4. Changes in String 5. Changes in NumberFormat 6. Changes in Collectors 7. Support Unicode 11 8. ...

Read More »

Java round double value to 2 decimal places Example

1. Introduction A double variable is used to hold a floating point value, such as 12.578. A decimal place is the position of a digit to the right of a decimal point. The 12.578 with 2 decimal places is represented as 12.57. Java has provided PrintStream, String.format, Formatter, NumberFormat, DecimalFormat, and BigDecimal to format and round a number based on ...

Read More »

Java Convert Byte[] array to String Example

1. Introduction A byte array is an array of bytes. A byte is binary data with 8 bits which represents an integer with values from -128 to 127. A char is a primitive data type which represents a character. The bytes translate to characters based on the character encoding scheme (such as Unicode, UTF-8, UTF-16, and UTF-32). The String class ...

Read More »

Java Generate Random Integers Example

1. Introduction Java JDK has provided the following utility classes to generate random integers over time: The java.util.Random class from version 1.0, java.util.concurrent.ThreadLocalRandom class from version 1.7, and java.util.SplittableRandom class from version 1.8. These classes provide the nextInt method to generate a random integer and ints method to generate a stream of random integers. Here are the syntax details: /** ...

Read More »

Java Copy Array Example

1. Introduction Java array is an object which represents a data structure that contains elements of a similar data type. Array in java is index-based, the first element of the array is stored at the 0 index. Java has provided several ways to copy an array over time: System.arraycopy – provided since version 1.0. It copies an array from a ...

Read More »

Java Pass by Value vs Pass by Reference Example

1. Introduction There are two ways to pass arguments (parameters) into methods (functions) in most programming languages: Pass by Reference – A reference to the actual parameter is passed to the method. If the method modifies the parameter variable, the changes are visible to the caller.Pass by Value – The method parameter values are copied to another variable and then ...

Read More »

Java 11 New Features Tutorial

In this tutorial, I will talk about the JDK 11 product changes. Then I will dive into several API changes with Java examples. Finally I will show the new Single-File Launcher, which executes a Java source file without going through the compile processing. Table Of Contents 1. Introduction 2. Install JDK11 3. Technologies Used 4. Change at java.lang.String 5. Change ...

Read More »

Java String charAt() Method with Example

1. Introduction The java.lang.CharSequence interface provides read-only access to many different kinds of char sequence. It has provided a charAt method since version 1.4 to return the character value at the specified index. java.lang.String class implements java.lang.CharSequence. The string indexes start from zero to the string’s length() minus one. Here is the method syntax: char charAt(int index) Parameters: index – ...

Read More »

Java String contains() method with Example

1. Introduction The java.lang.String class represents character strings. It has provided a contains method since version 5 to return true if and only if this string contains the specified sequence of char values. Here is the method syntax: boolean contains(CharSequence s) A CharSequence interface represents a readable sequence of char values. It has five implementation classes: java.nio.CharBuffer, javax.swing.text.Segment, java.lang.String, java.lang.StringBuffer, ...

Read More »

Java String trim() method with Example

1. Introduction The java.lang.String class represents character strings. It provides a trim() method since version 1.4 to return a new string object whose value is the copy of the original string without any leading or trailing white-space. Note: a white-space is when the ASCII code of the character is less than or equal to the space character, which is \u0020. ...

Read More »