Function:
Use fun to define a function. Use functions to organize your code and make it more reusable.
Function parameters are written within parentheses ()
Each parameter must have a type, and multiple parameters must be separated by commas ,
The return type is written after the function's parentheses (), separated by a colon :
The body of a function is written within curly braces {}
The return keyword is used to exit or return something from a function.
A function uses parameters. A caller passes it arguments.
Arguments are the things you pass into the functions. An argument lands face-down into a parameter. And a parameter is nothing more than a local variable: a variable with a name and type that’s used inside the body of the function.
If a function has a parameter, you must pass it something.
You can get things back from a function. If you declare that a function returns a value, then you must return a value of the declared type.
If you don’t want your function to return a value, you can either omit the return type from the function declaration, or specify a return type of Unit. Declaring a return type of Unit means that the function returns no value.
Functions with single-expression bodies:
If you have a function whose body consists of a single expression, you can simplify the code by removing the curly braces and return statement from the function declaration.
Package:
packages are used to organize code, manage namespaces to avoid naming conflicts, and control the visibility of declarations across your project.
Key Roles of Packages in Kotlin:
1. Code Organization: Packages act as a logical grouping mechanism, similar to folders in a file system, for related functions, classes, interfaces, and objects. This makes the project structure easier to understand and maintain.
2. Namespace Management: In large projects where different teams or libraries might use the same class or function names (e.g., a User class), packages ensure that each name is unique by providing a specific namespace (e.g., com.mycompany.crm.User vs. com.thirdparty.library.User).
3. Visibility and Access Control: Packages play a role in defining the scope of visibility for code elements.
Declarations within the same package can be freely used in any other file within that package without an import statement.
4. Code Reusability: Once code is organized into a package, it can be easily imported and reused in other parts of the program or in entirely different projects.
5. Modularity: They help break down a large application into manageable, interdependent modules, which improves overall project structure and build times.
Guide to watch:
00:00 Introduction
00:17 Function in kotlin
08:30 return value in function in kotlin
13:00 Default parameter in Function in Kotlin
17:07 Function with single expression body in Kotlin
24:55 Package and it's role in kotlin
30:40 Revision of Function in kotlin
#function #kotlinFunction #FunctioninKotlin #package #parameter #argument #defaultParameter #KotlinTutorial #HindiTutorial #KotlinHindi #KotlinHindiTutorial #KotlinCompleteTutorial #KotlinForAndroid
Disclaimer- Some content are used for educational purposes under fair use.
Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips the balance in favor of fair use. All credit for copyright material used in the video goes to the respected Owner.
Thank you guys.