473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

no header files in java

65
why java does not need to have header files like C and C++ ?
in java RTTI enables the programmer to identify the interface of classes and methods, is this the only reason? or what else?

thanks in advance...
Sep 10 '07 #1
3 4023
r035198x
13,262 8TB
why java does not need to have header files like C and C++ ?
in java RTTI enables the programmer to identify the interface of classes and methods, is this the only reason? or what else?

thanks in advance...
Everything belongs to a class. If you want to use a class or anything inside a class you need it available by importing that class' package.
There is no need for anything else.
Sep 10 '07 #2
kreagan
153 100+
why java does not need to have header files like C and C++ ?
in java RTTI enables the programmer to identify the interface of classes and methods, is this the only reason? or what else?

thanks in advance...
I just started writing in C, and I see header files as a way to expose methods and classes (makes them public). I think java made that idea more self contained. Now methods are declared public/private/protected within the class itself. I'm sure there is more to this ... just a relationship I saw from switching from java to C.
Sep 10 '07 #3
JosAH
11,448 Expert 8TB
why java does not need to have header files like C and C++ ?
in java RTTI enables the programmer to identify the interface of classes and methods, is this the only reason? or what else?

thanks in advance...
The java compiler (notably "javac") is able to read compiled code; compiled
code is not supposed to lie; given a compiled class (example):

Expand|Select|Wrap|Line Numbers
  1. package foo;
  2. Class Foo {
  3.    public int bar;
  4.    // possibly more stuff here ...
  5. }
  6.  
When you reference this class (example):

Expand|Select|Wrap|Line Numbers
  1. class Bar {
  2.    foo.Foo foo= new foo.Foo();
  3.    void someMethod() { foo.bar= 42; }
  4. }
  5.  
When you compile class Bar the compiler searches for a compiled class foo.Foo
(package and class name) and checks whether or not there is some 'bar' member
in there. If there is, it continues, if there isn't it starts to whine at you about a
member 'bar' not being available in a 'foo.Foo' or even worse, if it can't find a
compiled 'foo.Foo' it'll whine about that.

You can help the compiler a bit by 'importing' the package and optionally the class
itself:

Expand|Select|Wrap|Line Numbers
  1. import foo.Foo; // or 'import foo.*;'
  2. class Bar {
  3.    Foo foo= new foo.Foo();
  4.    void someMethod() { foo.bar= 42; }
  5. }
  6.  
But still the compiler wants to see a compiled foo.Foo class when it has to compile
this Bar class.

You can even give a path to where the source files (the .java files) exist to the
compiler in which case it does something like this: 1) look for a compiled foo.Foo
class and if it isn't found but a Foo.java source file is found, compile that and then
continue. If nothing was found start whining about it. This mechanism effectively
cancels the need for #include'd files and is a bit more trustworthy.

kind regards,

Jos
Sep 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Hattuari | last post by:
I'm learning C++ after having spent several years in the computer industry doing both system administration and engineering. I've written code in Perl, Bash, Pascal, Ada, C, Mathematica (hundreds...
4
by: Steven T. Hatton | last post by:
Now why didn't *_I_* think of that! Declarations and Definitions in One Header C++ object definitions can be quite complex. In principle, your source code will need two kinds of things for...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
4
by: rajkirangrandhi | last post by:
Hi, I have several classes written in Java that I am trying to convert into C++. They are fairly simple classes, no gui stuff etc, just some math routines. I was able to do it without any problem....
15
by: Kannan Goundan | last post by:
Maintaining a C++ header file can be painful. I want a way to automatically generate header files from the implementation file. Does anybody know of a program that does this? If not, I'd like...
4
by: crs2003c | last post by:
For some time now, other teachers have had this problem. Visual C++ 6.0 was once installed on a WIN98 platform and apstring.h and graphic.h worked. However, since moving to WIN2000 and WINXP,...
0
by: Daniel Thune, MCSE | last post by:
I am having a problem with formatting a SOAP Header in a .Net client. The client calls a Java Axis 1.1 based web service. In order to authenticate the caller, the web service call is intercepted by...
7
by: Nadav | last post by:
Hello, When I create an XML header using this code: XmlDeclaration header = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement rootElement = doc.DocumentElement; ...
1
by: Swapnil Kale | last post by:
Hi, I'm working on a Migration project (Forte to JAVA). The forte client had a C++ dll which used to call one more FORTE dll for a complex database calculations. Now all the forte code has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.