{"id":17285,"date":"2016-08-12T16:12:42","date_gmt":"2016-08-12T16:12:42","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=17285"},"modified":"2016-08-12T16:12:42","modified_gmt":"2016-08-12T16:12:42","slug":"java-why-null-might-be-used-as-an-input-parameter-aka-argument","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/java-why-null-might-be-used-as-an-input-parameter-aka-argument\/","title":{"rendered":"Java:  why null might be used as an input parameter (aka argument)"},"content":{"rendered":"<h1>The tutor looks into passing <span style=\"font-family:monospace\">null<\/span> as an argument.<\/h1>\n<p>Sometimes, reading Java code, you encounter <span style=\"font-family:monospace\">null<\/span> being passed as an argument aka parameter:<\/p>\n<p><span style=\"font-family:monospace\">method0(null);<\/span><\/p>\n<p>Apparently, when a method expects an object parameter, but doesn&#8217;t (necessarily) use it, you can pass it <span style=\"font-family:monospace\">null<\/span> to satisfy its need for a parameter.  A very simple example might be as follows:<\/p>\n<p style=\"font-family:monospace\">method0(Object obj0){<br \/>\nSystem.out.println(&#8220;Hello!  I&#8217;m here!&#8221;);<br \/>\n}\n<\/p>\n<p>Above, the method <span style=\"font-family:monospace\">method0<\/span> requires a parameter of type Object.  Although <span style=\"font-family:monospace\">method0<\/span> doesn&#8217;t use that parameter, the compiler will protest if <span style=\"font-family:monospace\">method0<\/span> is called without it.  Calling <span style=\"font-family:monospace\">method0<\/span> with <span style=\"font-family:monospace\">null<\/span> as the parameter will apparently satisfy the compiler, which is why you might see<\/p>\n<p><span style=\"font-family:monospace\">method0(null);<\/span><\/p>\n<p>in Java code examples.<\/p>\n<p>I&#8217;ll talk more about this in future posts.<\/p>\n<p>Source:<\/p>\n<p><a href=\"https:\/\/coderanch.com\/t\/384572\/java\/java\/Passing-Null-argument\">coderanch.com<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor looks into passing null as an argument. Sometimes, reading Java code, you encounter null being passed as an argument aka parameter: method0(null); Apparently, when a method expects an object parameter, but doesn&#8217;t (necessarily) use it, you can pass &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/java-why-null-might-be-used-as-an-input-parameter-aka-argument\/\"> <span class=\"screen-reader-text\">Java:  why null might be used as an input parameter (aka argument)<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105,1801],"tags":[1804,1802,1803],"class_list":["post-17285","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-java","tag-passing-null-as-a-parameter","tag-passing-null-as-an-argument","tag-the-null-parameter"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/17285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=17285"}],"version-history":[{"count":6,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/17285\/revisions"}],"predecessor-version":[{"id":17291,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/17285\/revisions\/17291"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=17285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=17285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=17285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}