What is null? ]

** 1. Trigger**

The reason I chose this theme was because when I was educating a new engineer, I was asked to explain null and couldn't say anything.

String A = null;
String B = "";

When I set null and "" (empty string) for the String type, I couldn't explain what was different, so I'll dig into that and deepen my understanding. (At that time, I answered that "null" has no value and "" is an empty string. Reflection.)

2.NullPointerException

When does the so-called "nullpo" occur? As an example, it looks like this.

public class Sample {
	public static void main(String[] args) {
		String str = null;
		System.out.println(str.length());
	}
}

I get a NullPointerException when I try to execute a method with null. (Null cannot use any method), so if there is a possibility that a null value will be set, I think it is common to put a check process called "null check" as shown in the code below.

public class Sample {
	public static void main(String[] args) {
		String str = strMake();
		if (str != null) {
			System.out.println(str.length());
		} 
	}
	private static String strMake () {
		return null; //Write something
	}
}

** 3. Methods provided in the string class **

The String class has various methods. As a defense record, I will post a link to the reference site.

[Official document] https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html

** 4. String type = reference type **

Recommended Posts

What is null? ]
What is Cubby
What is Docker?
What is java
What is Keycloak
What is maven?
What is Jackson?
What is Docker
What is self
What is Jenkins
What is ArgumentMatcher?
What is IM-Juggling?
What is params
What is SLF4J?
What is Facade? ??
What is Java <>?
What is Gradle?
What is POJO
What is Java
What is centOS
What is RubyGem?
What is programming?
What is before_action?
What is Docker
What is Byte?
What is Tomcat
What is Maven Assembly?
What is `docker-compose up`?
What is a constructor?
What is vue cli
What is an interface?
What is Ruby's self?
What is hard coding?
What is a stream
What is Ruby's attr_accessor?
What is Java Encapsulation?
What is permission denied?
What is instance control?
What is an initializer?
What is Spring Tools 4
What is an operator?
What is object orientation?
What is Guava's @VisibleForTesting?
What is MVC model?
What is an annotation?
What is Java technology?
What is Java API-java
What is @ (instance variable)?
What is Gradle's Artifact?
What is JPA Auditing?
[Swift] What is dismiss?
[Java] What is flatMap?
What is a Servlet?
What is web development?
[Java] What is JavaBeans?
[Android] What is Context? ??
[Java] What is ArrayList?
[Ruby] What is true?
What is object-oriented after all?
What is HttpSession session = request.getSession ();
What is docker run -it?