Topic: 大虾请来看一下(在C++ 可将函数放在.h文件 在java里怎么实现)

  Print this page

1.大虾请来看一下(在C++ 可将函数放在.h文件 在java里怎么实现) Copy to clipboard
Posted by: pursuer2004
Posted on: 2005-07-28 08:36

请使用准确的文字描述作为标题
Your next post without a proper Subject will be removed.

Original subject :
大虾请来看一下

C++ 里分.cpp 和 .h文件,我可以将函数放在.h文件里,可在java里怎么实现呢?一个菜鸟的困惑


////////////////////////////////////////////////
public class mm
{
  public static void main(String[] args){
    int a=1,b=2,c;
    c=max(a,b);
    System.out.printlnCoffee;
  }
}
///////////////////////////////////////////////
public class fun
{
  public int max(int p1, int p2)
  {
    int tmp;
    if (p1>p2)
      tmp=p1;
    else
      tmp=p2;
    return tmp;
  }
}

2.Re:大虾请来看一下(在C++ 可将函数放在.h文件 在java里怎么实现) [Re: pursuer2004] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-07-28 11:09

pursuer2004 wrote:
C++ 里分.cpp 和 .h文件,我可以将函数放在.h文件里,可在java里怎么实现呢?一个菜鸟的困惑


First of all, Java does not support header files in compiling process. You must put the methods in the class.

Second, you can obtain it just for the purpose of profile or documentation or just for yourself to understan the code.

A Java utility officially called Java Class File Disassembler. It can disassemble your class by type:
javap -c Test
on your Test.class file. Then you got the assembly code, You must have compiled class Test.class before using it. What a nice feature???!!! Big Smile

However, javap is commonly used as a kind of profiler, which profiles your class. It generates something similar to c/c++ *.h file, if you use no option or options like -private.
javap Test
javap -private Test
to include even private class members and methods.

If you were c/c++ programmer in your previous life , and missed the *.h file convenience, then you have a utility to do the job for you. Who said the life is not beautiful? Beer

See
http://java.sun.com/j2se/1.3/docs/tooldocs/solaris/javap.html
for more options and details.

3.Re:大虾请来看一下(在C++ 可将函数放在.h文件 在java里怎么实现) [Re: pursuer2004] Copy to clipboard
Posted by: pursuer2004
Posted on: 2005-07-28 11:58

还是不太明白阿,能不能给个例子

4.Re:大虾请来看一下(在C++ 可将函数放在.h文件 在java里怎么实现) [Re: pursuer2004] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-07-28 12:04

You have you mm.class and fun.class from javac compiler, just do the following commands. Then see what is generated in your directory.

javap mm
javap fun

Read the generated file, you also can learn many important Java concepts too. Smile

5.Re:大虾请来看一下(在C++ 可将函数放在.h文件 在java里怎么实现) [Re: pursuer2004] Copy to clipboard
Posted by: pursuer2004
Posted on: 2005-07-28 13:54

能不能放在两个.java文件里呢?

6.Re:大虾请来看一下(在C++ 可将函数放在.h文件 在java里怎么实现) [Re: pursuer2004] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-07-28 18:44

You don't read at all, I've no way to help anymore. Sad

7.Re:大虾请来看一下(在C++ 可将函数放在.h文件 在java里怎么实现) [Re: pursuer2004] Copy to clipboard
Posted by: Reeves1016
Posted on: 2005-07-28 19:53

事实上,我最讨厌的就是header文件,因此我最讨厌C++


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923