Java Pointers and Missing method body

Click For Summary
SUMMARY

Java does not support pointers, which is a fundamental difference from languages like C or C++. The discussion highlights a common error where a function is declared without a body, specifically in the example of the method public boolean FuncFoo(). The compiler error arises from the absence of curly braces, which are necessary even if the body is left empty. To resolve this, users must ensure that all methods in Java include a defined body.

PREREQUISITES
  • Understanding of Java syntax and structure
  • Familiarity with Java method declarations
  • Knowledge of Java data types, specifically primitive types
  • Basic concepts of programming logic and flow control
NEXT STEPS
  • Study Java method definitions and their requirements
  • Learn about Java data types and their differences from C/C++
  • Explore Java's object-oriented programming principles
  • Review common Java compiler errors and their resolutions
USEFUL FOR

Java developers, programming students, and anyone transitioning from C/C++ to Java who needs clarification on Java's handling of methods and data types.

Pattielli
Messages
296
Reaction score
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
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:

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
2K
Replies
11
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 23 ·
Replies
23
Views
2K