Java Pointers and Missing method body

In summary, the conversation discusses a problem with declaring a pointer and a function in Java. The Java compiler is giving an error for an identifier at the pointer declaration and for the missing method body in the function. The person speaking is unsure of what is causing the error and asks for help. The listener suggests that Java does not use pointers and does not require function definitions. They provide a resource for more information on the differences between Java and C.
  • #1
Pattielli
296
0
I declare my pointer as char* ptr and my function as public boolean FuncFoo() but java compiler complains that I have some problem with identifier right at * and my function is missing the method body...
I couldn't figure out what was wrong with them. Would you please help me ?
Thank you,
 
Technology news on Phys.org
  • #2
Firts part: Java doesn't have pointers.

Second part
Code:
public boolean FuncFoo()
     {
          you need a body even if you leave it bank
     }

Java doesn't require function definitions either (is that why you're not using the {}?). Simply create your function and call it.

http://leepoint.net/notes-java/10background/10applications_and_applets/05intro/60JavaVsC.html
 
Last edited by a moderator:
  • #3


Sure, I'd be happy to help. It sounds like you may be confusing Java with another programming language, as Java does not have pointers or a char* data type. Pointers are commonly used in languages like C and C++, but in Java, objects are passed by reference instead. This means that when you declare a variable, you are actually creating a reference to an object, rather than a direct pointer to its memory location.

As for the missing method body, it's important to remember that in Java, all methods must have a body. This means that you need to include curly braces {} after your method declaration, even if the method does not have any code inside it. For example:

public boolean FuncFoo() {
// method body
}

If you are still having trouble, it might be helpful to provide more specific information about the error message you are receiving. I hope this helps clarify things for you. Happy coding!
 

1. What are Java pointers?

Java pointers are variables that store memory addresses of other variables. They are used to indirectly access and manipulate data stored in memory.

2. How do Java pointers work?

Java pointers work by storing the memory address of a variable, which allows the program to access and modify the data stored in that memory location. This means that the value of the pointer can change, but the data it points to remains the same.

3. What is a missing method body in Java?

A missing method body in Java refers to a method declaration that does not have any code inside its curly braces. This usually occurs when a method is created but not implemented, or when the code inside the method is accidentally deleted.

4. How do you fix a missing method body error in Java?

To fix a missing method body error in Java, you need to add the necessary code inside the method's curly braces. This could include statements, expressions, or return statements, depending on the purpose of the method.

5. Can Java pointers cause memory leaks?

No, Java pointers cannot cause memory leaks. Java has automatic memory management, so when a pointer is no longer referencing a variable, the memory used by that variable will be automatically freed. This prevents memory leaks from occurring.

Similar threads

  • Programming and Computer Science
Replies
2
Views
831
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
5
Views
872
  • Programming and Computer Science
Replies
3
Views
767
  • Programming and Computer Science
Replies
11
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
13
Views
4K
Back
Top