Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

can someone pls explain what a function is in java cause im new to coding

MatthewXia
MatthewXia

i have no idea. pls help. (but u dont have to if to decide not to)

2 years ago

Voters

Comments

TopNew
1
Coder100
Coder100

A functions a block of code that can be used to repeat code more than one time.

2 years ago
1
MatthewXia
MatthewXia

@Coder100
then why is it not called repeat?

2 years ago
1
Coder100
Coder100

because a repeat would be like a loop.

@MatthewXia

2 years ago
1
MatthewXia
MatthewXia

@Coder100
the why is it called function?

2 years ago
1
Coder100
Coder100

coding is really just math theory. At the start, functions were literally just to do: f(x) = x in math.

@MatthewXia

2 years ago
1
Coder100
Coder100

For example:

String name = "Coder100"; Console.WriteLine("Hello world"); Console.WriteLine("Your name is "+name);

if you would want to do that a lot of times, at the end, it will be pretty tedious. Using a function will simplify that:

void greet(String name) { String name = "name"; Console.WriteLine("Hello world"); Console.WriteLine("Your name is "+name); } greet("Coder100");
2 years ago
1
Coder100
Coder100

In case of java, that would be a method.

2 years ago
1
Coder100
Coder100

its the same as a function, but in java, it's part of a class

@MatthewXia

2 years ago
1
MatthewXia
MatthewXia

@Coder100
whats a class. also sry for the hassle

2 years ago
1
gibbsfreenergy
gibbsfreenergy

Have a great day and fun coding! :)

2 years ago
1
gibbsfreenergy
gibbsfreenergy

If this answered your question please mark it as correct!

2 years ago
1
gibbsfreenergy
gibbsfreenergy

*** A JavaScript function is a block of code designed to perform a particular task. A function can be defined using function keyword and can be executed using () operator.***

2 years ago
1
MatthewXia
MatthewXia

@JosephSanthosh
can you pls explain the function keyword?

2 years ago
1
gibbsfreenergy
gibbsfreenergy

@MatthewXia
The function keyword can be used to define a function inside an expression. You can also define functions using the Function constructor and a function declaration.

2 years ago
1
gibbsfreenergy
gibbsfreenergy

@MatthewXia

image

2 years ago
1
MatthewXia
MatthewXia

@JosephSanthosh
can you pls also explain the function constructor and a function declaration. sry for the hassle

2 years ago
1
MatthewXia
MatthewXia

@JosephSanthosh
im still confuzzled on how it works

2 years ago
1
MatthewXia
MatthewXia

@JosephSanthosh
he already is but thx for the suggestion

2 years ago
1
Load more