[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-347079-105":59,"doc-detail-347079-en":130},{"code":4,"msg":5,"data":6},0,"success",[7,13,18,23,28,33,38,43,48,51,55],{"id":8,"doc_module":4,"doc_module_name":9,"category_name":10,"show_sort_weight":11,"slug":12},1,"Document","Story & Novel",90,"story-novel",{"id":14,"doc_module":4,"doc_module_name":9,"category_name":15,"show_sort_weight":16,"slug":17},2,"Literature",80,"literature",{"id":19,"doc_module":4,"doc_module_name":9,"category_name":20,"show_sort_weight":21,"slug":22},4,"Exam",70,"exam",{"id":24,"doc_module":4,"doc_module_name":9,"category_name":25,"show_sort_weight":26,"slug":27},5,"Comic",60,"comic",{"id":29,"doc_module":4,"doc_module_name":9,"category_name":30,"show_sort_weight":31,"slug":32},6,"Technology",50,"technology",{"id":34,"doc_module":4,"doc_module_name":9,"category_name":35,"show_sort_weight":36,"slug":37},7,"Healthcare",40,"healthcare",{"id":39,"doc_module":4,"doc_module_name":9,"category_name":40,"show_sort_weight":41,"slug":42},8,"Research & Report",30,"research-report",{"id":44,"doc_module":4,"doc_module_name":9,"category_name":45,"show_sort_weight":46,"slug":47},9,"Religion & Spirituality",20,"religion-spirituality",{"id":46,"doc_module":4,"doc_module_name":9,"category_name":49,"show_sort_weight":46,"slug":50},"World Cup","world-cup",{"id":52,"doc_module":4,"doc_module_name":9,"category_name":53,"show_sort_weight":52,"slug":54},10,"Lifestyle","lifestyle",{"id":56,"doc_module":4,"doc_module_name":9,"category_name":57,"show_sort_weight":24,"slug":58},19,"General","general",{"code":4,"msg":60,"data":61},"ok",{"site_id":62,"language":63,"slug":64,"title":65,"keywords":66,"description":67,"schema_data":68,"social_meta":123,"head_meta":125,"extra_data":127,"updated_unix":129},105,"en","functions-java-function-basics","Functions - Java Function Basics","","Java functions notes covering core concepts needed to write and use methods effectively. Topics include function inputs (zero or more arguments), computation and possible side effects, and returning a single output value. The material explains static methods, modularity and avoiding copy-pasted code, and the anatomy of a Java function including method signature, return type, method name, and arguments. It also describes flow of control during a call and introduces variable scope with examples and the best practice of limiting scope.",{"@graph":69,"@context":122},[70,84,105],{"@type":71,"itemListElement":72},"BreadcrumbList",[73,77,79,82],{"item":74,"name":75,"@type":76,"position":8},"https://docshare.wps.com","Home","ListItem",{"item":78,"name":9,"@type":76,"position":14},"https://docshare.wps.com/document/",{"item":80,"name":30,"@type":76,"position":81},"https://docshare.wps.com/document/technology/",3,{"item":83,"name":65,"@type":76,"position":19},"https://docshare.wps.com/document/functions-java-function-basics/347079/",{"url":83,"name":65,"@type":85,"image":86,"author":91,"headline":65,"publisher":94,"fileFormat":97,"inLanguage":63,"description":67,"dateModified":98,"datePublished":99,"encodingFormat":97,"isAccessibleForFree":100,"interactionStatistic":101},"DigitalDocument",{"url":87,"@type":88,"width":89,"height":90},"https://docshare.wps.com/thumbnails/functions-java-function-basics/347079.png","ImageObject",300,407,{"name":92,"@type":93},"Angel","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-11-25","2026-09-22",true,{"@type":102,"interactionType":103,"userInteractionCount":44},"InteractionCounter",{"@type":104},"ViewAction",{"@type":106,"mainEntity":107},"FAQPage",[108,114,118],{"name":109,"@type":110,"acceptedAnswer":111},"What are the essential parts of a Java function?","Question",{"text":112,"@type":113},"A Java function includes a return type, method name, and arguments, forming the method signature (excluding the return type). The function body contains the implementation and must include a return statement when returning a value.","Answer",{"name":115,"@type":110,"acceptedAnswer":116},"How does control flow work when a function is called?",{"text":117,"@type":113},"When called, control transfers to the function, argument values are assigned to the parameter variables, the function code executes, the return value replaces the call in the calling code, and control transfers back.",{"name":119,"@type":110,"acceptedAnswer":120},"What does variable scope mean in Java, and what is the best practice?",{"text":121,"@type":113},"Scope is the portion of code that can refer to a particular variable, typically the code block after its declaration, including nested blocks. A best practice is to declare variables to limit their scope.","https://schema.org",{"og:url":83,"og:type":124,"og:title":65,"og:site_name":95,"og:description":67},"article",{"robots":126,"canonical":83},"index,follow",{"doc_id":128,"site_id":62},347079,1790795987,{"code":4,"msg":5,"data":131},{"doc_id":128,"user_id":132,"nickname":92,"user_avatar":133,"doc_module":4,"category_id":29,"category_name":30,"doc_title":65,"doc_description":67,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":44,"is_deleted":4,"is_public":8,"is_downloadable":8,"audit_status":8,"page_count":46,"language":139,"language_code":63,"site_id":62,"html_lang":63,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":67,"update_tm":143,"read_time":31,"preview_page_count":19,"preview_urls":144},687207412472,"https://ap-avatar.wpscdn.com/davatar_155a257f0dc6eb9ab79c44ca47cae57d","2.1 Functions  \nFunctions  \n• Take in input arguments (zero or more)  \n• Perform some computation  \n- May have side-effects (such as drawing)  \n• Return one output value  \nInput Arguments  \nReturn Value  \nx y  \nz  \nf   \nf (x, y, z)  \nFunctions (Static Methods)  \n• Applications:  \n- Use mathematical functions to calculate formulas  \n- Use functions to build modular programs  \n• Examples:  \n- Built-in functions:  \nMath.random(), Math.abs(), Integer.parseInt()  \n- I/O libraries:  \n[StdDraw.circle](StdDraw.circle) (), [StdDraw.show](StdDraw.show) ()  \n- User-defined functions:  \nmain()  \nModularity  \n• Breaking programs into smaller pieces  \n• Avoid copy pasted code  \n• Each function can be checked separately  \nAnatomy of a Java Function  \n• Java functions – It is easy to write your own  \n- Example: double sqrt (double c)  \ninput output  \n2.0 ~~ ~~ sqrt(c) = 􀂗c ~~ ~~ 1 .414213…  \nreturn type  \nmethod name  \narguments  \npublic static double sqrt(double c) {  \n...   \nmethod signature  \n(excludes return type)  \nPlease note that the method’s signature is defined incorrectly in the figure on pg 188 of your textbook  \nAnatomy of a Java Function  \nExample - absolute value  \n• think of what the function is doing. Finding absolute value  \n• give it a name. Name of a function = important!! abs  \n• What goes ͚iŶto͛ the fuŶctioŶ . What are the arguŵeŶts . What type are the arguments?  \nsingle integer. abs (int x)  \n• What does it return? what datatype comes out of the function.  \nAnother integer. int abs (int x)  \n• Put public static before it and create a method body  \npublic static int abs(int x){  \n// fill your code here}  \n• Do not forget a return statement  \nFlow of Control  \nFunctions provide a new way to control the flow of  \nexecution  \nimplicit  \n at end  \nThe sqrt function is written here using the Newton method. Do not worry about the actual code inside sqrt  \nreturn statement of void function  \n8  \nFlow of Control  \nWhat happens when a function is called:  \n- Control transfers to the function  \n- Argument variables are assigned the values given in the call  \n- Function code is executed  \n- Return value is substituted in place of the function call in the calling code  \n- Control transfers back to the calling code  \nNote: This is known as\"pass by value\"  \n1  \n3 2  \n9  \nScope  \nScope: the code that can refer to a particular variable- A variable's scope is the entire code block (any any nested  \nblocks) after its declaration  \nSimple example:  \nint count = 1;  \nfor ( int i = 0; i \u003C 10; i++){  \ncount *= 2;  \n}  \n// using 'i' here generates  \n// a compiler error  \nBest practice: declare variables to limit their scope","cbCaiiEtvbtn6kK5","https://ap.wps.com/l/cbCaiiEtvbtn6kK5","pdf",830773,"English","# Functions\n## Input Arguments and Return Values\n## Functions (Static Methods)\n## Modularity\n## Anatomy of a Java Function\n## Flow of Control\n## Scope","[{\"question\":\"What are the essential parts of a Java function?\",\"answer\":\"A Java function includes a return type, method name, and arguments, forming the method signature (excluding the return type). The function body contains the implementation and must include a return statement when returning a value.\"},{\"question\":\"How does control flow work when a function is called?\",\"answer\":\"When called, control transfers to the function, argument values are assigned to the parameter variables, the function code executes, the return value replaces the call in the calling code, and control transfers back.\"},{\"question\":\"What does variable scope mean in Java, and what is the best practice?\",\"answer\":\"Scope is the portion of code that can refer to a particular variable, typically the code block after its declaration, including nested blocks. A best practice is to declare variables to limit their scope.\"}]","Functions - Java Function Basics | PDF",1790065174,[145,149,152,156],{"page_no":8,"url":146,"width":147,"height":148},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-16/bb75a992ab95a728cb97f938be52a0f7.webp",983,736,{"page_no":14,"url":150,"width":151,"height":148},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-16/35365552630c583e70459ea4ad995e63.webp",982,{"page_no":81,"url":153,"width":154,"height":155},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-16/8b12099aea968c80cd0edb11078b4b3b.webp",981,735,{"page_no":19,"url":157,"width":158,"height":159},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-16/aa341430a260706d77db056dc221b5d1.webp",980,734]