J2K FREQUENTLY ASKED QUESTIONS:




Library: J2K Lib
Meaning: Java 2000, Java to C++, C++ to Java, Java to Kewl, got it?
Author: Fred P.
Email: fprog26 -at- hotmail.com
Date: June 15th, 2000 - August 22th, 2000
License: GNU LGPL, except that it can be include in commercial package, such as Arcom, QNX, pSOS, VxWorks, etc. without any extra charge. Perhaps, any derivation of this library must be kept
under GNU LGPL licence.
Notice: LGPL = Lesser General Public License
Used for GNU libraries with less restrictions.







01. Why doing such a library ?

  - It's portable to ANY primitive, prehistoric, stupid C++ compiler
  - It's portable to ANY OS or RTOS that support C++
  - It's portable to ANY microprocessor (I hope so)
  - It mimics Java Tree for classes.
  - It's conform to Embedded C++ subset for most of it.
  - It's also made to be a Standard Library for Embedded C++ application
    and a Standard Library for Portable C++ application,
    in an Upward and Downward compatibility amongs compiler, OS, etc.
  - It implements Java stuff in a very efficient, non costly 
    and portable way.

  - It doesn't use: 

     - Templates, STL
     - Constructor with predefined value
     - Run-Time Exception Handling
     - Costly Run-Time Type Detection technique
     - Namespace (facultative)
     
     Why ?

     - Templates, STL are not supported everywhere (e.g. Watcom C++ for QNX),
       they are costly, unreadable and difficult to maintain and test.
     - Constructor with predefined value are not supported in some early
       version of Borland C++ and Turbo C++. Some Boards such as Arcom  
       still used these old compilers.
     - Run-Time Exception Handling too costly,
       samething for Standard Run-Time Type Detection technique.
       (See Embedded C++ by O'Reilly)
       
  - It use it's own Type Detection technique using Serialization
    and ClassInfo Macros.
  - There is no such a thing as multiple inheritance or diamond inheritance
    in this library. However, any user class using this library classes
    are capable of doing such a thing successfully.
  - Multiples inheritance is replaced, if needed, by MACROS that mimics
    the interface model. Most single inheritance also use this technique.




02. How to install it ?

  - Uncompress it under your include directory.
    e.g. /usr/include
    so it becomes /usr/include/j2k/...
  - You can also uncompress it elsewhere, but make sure
    you create a link to that directory or that you specify it
    to your compiler.




03. Why does your headers names are not ANSI-C++ conform ?

  - I type them like that since 1992 (!)
  - I don't see any reasons to be so much restrictive,
    since it doesn't end up with any better solution
    as before this rule was written.
  - Nobody cares anyway, as long as it doesn't screw up your project.

  - I strongly suggest that headers names should be uniformed as follow:
    __PACKAGE__NAME_HH__
    __PACKAGE__NAME_CC__
    OR
    __PACKAGE__NAME_H__
    __PACKAGE__NAME_C__
    OR
    __PACKAGE__NAME_HPP__ 
    __PACKAGE__NAME_CPP__

    The choice should be made once for all for the package
    and be conserved all the way.
    This way

    e.g.  __J2K__OBJECT_HH__
    e.g.  __ISO__STDIO_H__

    Also, for global things __J2K__ should be used.

    Why ?
    - Just look at MFC checking for  is included,
      it's kinda funny. They have about 3 of checking
      and rechecking the include file through all the MFC lib !
       _CSTDIO_
       _STD_USING
       _INC_STDIO

       others I saw: (ALL Illegal by the new ANSI C++ rule)
       _STDIO_USING
       _STDIO_INCLUDED
       _STDIO_HEADER
       _STDIO_H_
       __STDIO_HEADER__
       __STDIO_HEADER
       __STDIO_H__             (That's not bad)
       __ISO__STDIO_H__        (That's better)
       __ANSI_ISO__STDIO_H__   (Good, but long tough)

    The rule:
    Can't start with _
    Can't put __ anywhere!

    Why PACKAGE ?
    - Well, let's say I do __WINDOW_H__ and MFC have __WINDOW_H__
      that's a problem, right ?  
      If we do:
      __J2K__WINDOW_H__
      and
      __MFC__WINDOW_H__   

      No problems occurs, the namespace will do the rest.
      namespace PACKAGE

    - Since old compilers doesn't check for multiple include, 
      there is a directory call < j2k/include/... >
      that is equivalent to MODERN include file.
      e.g. < j2k/include/stdio.h >  ==  < stdio.h >  with an ISO header !

  - You think this is a good idea ?  Well, write to ANSI C++ commity !
  - You think this is awful ?
    Well, take your favorite editor and replace it by HAND,
    then submit it as J2K_WITHOUT library.




04. What is the current status (22 june 2000) ?


- Garbage Collection is a very low priority for now,
  some exist already, but it's not the main point for this lib,
  since garbage collection is a bad thing. Especially 
  for inefficiency and missed critical conditions
  (Games, Hard/Soft Real-Time)

- AWT is a very low priority for now, might be a priority this fall.

- Currently, I still develop classes, I will see after,
  if interpreters or converters will be made.

- Currently, I focus on Math class:
  - Demo Math (Matrix, Vector, Scaling, Rotating, Fractals)
  - Linear Algebra(Matrix Solvers, etc.)
  - Engineering Maths(Complex Z-Plane, etc.)
  - Numerical Analysis(Newton Poly, Forward/Backward difference, 
    Search, Lagrange Poly, Richardson Extrapolation, etc.)
  - General Algebra solving, I got code for an algebra calculator !
    from a tough bonus assignment I made in my C++ course.
  e.g.  y = x + x * a;
        x = 1;
        a = 2;
        y
        print the answer 3

- File format, decoders/encoders
- Sort engine (I got many ready in pre-alpha stage)
- DataStructure class (I got many ready in pre-alpha stage)
- DataBase stuff (I got many ready in pre-alpha stage)
- Basic Gaming engine (Still pre-pre-alpha stage =)
- Language interpreters (QBasic, Perl, pseudo-asm)
Token from a reply on the Java/Lang forum.




05. How Java interface will be handle ?

Interfaces would be an abstract class and have pseudo-inheritance backing it up.




06. What verstion of JDK are you using ?

Gabriel: 1.2.2
Fred: 1.1.8, but I don't really look at Java stuff anymore.
There is too much native and useless crapt.




07. What Gabriel will work on:

Dictionary.cpp  (note: entire class is abstract.  Not much work to do there)
Enumeration.cpp   (I see this as an interface so it should have no code.  Unless you want to turn it into a full class)
Observable.cpp
Observer.cpp
SimpleTimeZone.cpp
Locale.cpp


Hashtable.cpp
HashtableEnumerator.cpp   (wouldnt thiese 2 make more sense as nested classes in HashTable, since they arent public in java?)
HashtableEntry.cpp   

Hash Table period for these.
Take a look at Shaffer implementation also, in Java/Ref.
They are many way to implement hash table.
The Java one is using LinkList, for a same hashcode error, that's ok with me.

This are done already, I will take care of these:

BitSet.cpp
StringTokenizer.cpp
Stack.cpp
Vector.cpp
VectorEnumerator.cpp
I just uploaded ArrayStack and LinkedStack
also ArrayQueue and LinkedQueue.

Those will have to be morph in MACROS,
using ELEM as a parameter.




08. Just so I make sure of the convention, the classes of yours I looked at all mimiced the java names but added a J at the begining. Should I treat all names like that?

The J is obligatory. This is for not using already well-known names.
The Alias.hpp, typedef JObject Object; etc.
Do the same.
We don't use namespace, so we have no choice.




09. How are we throwing exceptions in C++ ?
Since were not using real C++ exceptions, then how are we doing it?


Same as in Java. try() { } catch() { }
but (Read the FAQ), I don't want to use it,
it's too much costly, try to use around ways
to avoid them. 

e.g. Array class

Use: unsigned long/size_t instead of int
(No negative number allowed and MAX is too far)

Use MODULO if you have to round up,
values allowed from 0 to 31, value = (value % 32);
Use enum, for a bounded array of things.
Use assert()
My new Double, Long, Integer, Float
will handle divide by 0, infinity, NaN, FP error ! =)
etc.

So,

Double x = 1;
x /= 0;

x == "Inf"

x *= -1;

x == "-Inf"

x *= 0;

x == "NaN"

=)




10. Pure Object, Reference or Pointers !?

How are we dealing withg Java's use of references ?
Are we passing everything as pointers
(this would make sensee since java's references are really just pointers to the actual data)?
If not, how do we deal with things like null objects and the fact that in java, going like

SomeClass a,b;
b=somedata1;
a=b;
b=somedata2
And now a would have the value somedata2?

SomeClass& here.

a = b, else must be reference not pointers.

This is what I answered on the Java forum.
It's NOT a no brain job.

You must decide if it's JObject&, JObject* or JObject
that's why you must know C++ well, to handle these.

If you know it might return (NULL),
put a JObject*

I also suggest you take a look at C++ stuff
or similar and then try to match C++ to Java,
not the inverse. Unless the equivalent doesn't exist nowhere.




11. The difference between Java and C++ for private/protected/public

public/protected/private is declare for a block, 
instead for each things. 

using 

public: 
void f(); 
void g(); 
private: 
int a; 

instead of: 

public  void f(); 
public  void g(); 
private int a; 




12. How operators functions are implemented in C++

operators functions are like functions, in fact if you write. 

Point a; 
Point b(1,1); 
a = b; 

the compiler will write this (not friend functions): 
a.operator=( b ); 

the compiler will write this for friend functions: 
operator=( a, b ); 

Useful for Math stuff, example: 

Complex a( 1, 2 );  // 1 + 2j 
Complex b(); 

If you declare operator+(const Complex& c) 
like a normal function (NOT FRIEND) 

i.e. 

Complex operator+(const Complex& c) { 
real += c.real; 
imag += c.imag; 
} 

b = 5 + a;  // Illegal, can't add this. 

If you declare operator+() as a FRIEND function 

i.e. 

inline friend Complex operator+(const double d, const Complex& c) { 
return Complex( d + c.real, c.imag ); 
} 

b = 5 + a;  // Correct, b = 5 + (1 + 2j) = 6 + 2j 

in fact, the compiler will do this, 
the private parts (real, imag) will be accessible, 
since the first pass, will check for it, before optimization: 

b = Complex( (double)5 + a.real, a.imag );  // since inlined... 


inline: means the compiler implements it directly, if possible, 
       instead of doing a function call. 
       (Won't be allowed, if too long or recursive) 




13. Why should I care about Copy Constructor and operator=, I don't want them.

Copy Constructor and operator=  ARE ALWAYS implemented, that you want it or not !

If you don't implement those or if you just don't declare them, 
the compiler WILL declare and implement what he think is okay ! 
Furthermore, he might call them or class users might call them ! 
The conclusion is: ALWAYS IMPLEMENTED THEM YOURSELF. 
Can't be implemented:  declare them as private without implementation. 
The compiler won't do anything, which is what you wanted... 




14. How to write efficient Constructor

NOT Optimize Constructor: 

Point::Point( int x1, int y1 ) { 
x = x1; 
y = y1; 
} 

// This is purely inefficient, here's why: 

int x; 
int y; 

x = 0; 
y = 0; 

x = x1; 
y = y1; 

// The optimize way using copy constructor 

Point::Point( int x1, int y1 ) 
: x( x1 ), y( y1 ) { } 

// This is efficient, here's why: 

int x = x1; 
int y = y1; 

YOU:   You're kidding right ? =) 
Fred:  Nope ! =) 

Perhaps don't do this: 

Square::Square( int x1 ) 
: x( x1 ), y( x ) { }  // Trivial, x is ???? 

// Don't use something that you just assigned. 

Square::Square( int x1 ) 
: x( x1 ), y( x1 ) { } // Correct. 




15. OOP Concepts

Well, do you know polymorphism ?

Because OOP is about class, objects, inheritance, composition,
interface and polymorphism.

If not try to compile and understand this:

main.cpp
========

class Root { 
public:
  void print() { printf("I'm a Root"); }
  int root;
};

class Branch1 : public Root { 
  void print() { printf("I'm a Branch1"); }
  int branch1;
};

class Branch2 : public Root { 
  void print() { printf("I'm a Branch2"); }
  int branch2;
};

class Derived1 : public Branch1 { 
  void print() { printf("I'm a Derived1"); }
  int derived1;
};

class Derived2 : public Branch2 { 
  void print() { printf("I'm a Derived2"); }
  int derived2;
};

class Diamond : public Derived1, public Derived2 {
  void print() { printf("I'm a Diamond Derived"); }
  int diamond;
};

cout << Diamond.root;           // is unknown
cout << Diamond.Derived1::root; // Oh that root
cout << Diamond.Derived2::root; // Oh that root

Diamond can be casted down.

(Derived1*)d->print();
(Derived2*)d->print();
(Branch1*)d->print();
(Branch2*)d->print();
(Root*)d->print();      // Is this correct ?

Play with this until you catch it. =)




16. DataStructure concepts

Do you know DataStructure stuff ?
(Stack, LinkList, Queue, Circular buffer) 

Stack: Think about plates or cans that you put one on top of the other, the only one
that you can put or remove is the top ones
(Else all the cans drop on the floor and a big mess happens =)
Last In, First Serves.

Queue: Never waited, First in, First Serves (Like at the bank)

Circular Buffer is like the cylinder thing in the old days
where you put little cards with people informations,
that every old secretary has.

LinkList is a dynamic array kind of:

[HEAD|ptr]->[A|ptr]->[B|ptr]->[C|ptr]->[D|ptr]->[E|ptr]->NULL

Link[0] = HEAD + a pointer to Link[1]
Link[1] = A    + a pointer to Link[2]
Link[2] = B    + a pointer to Link[3]
Link[3] = C    + a pointer to Link[4]
Link[4] = D    + a pointer to Link[5]
Link[5] = E    + a pointer to NULL  (no more elements)
Link[6...] = NONE;

This is a single link list,
there's also the double link list where you also store
the backward pointer.

It's very useful if you have to add and remove elements
rapidely. But you must travel from the Head to 'n' element
to be able to get that 'n' element.

With an array you have to move (n-1) elements one by one
(SiftDown or SiftUp) each time you add or remove new elements.




17. How does Serialization works ?

  Why does it work ?

  The bunch of bytes pointed by the pointer are assign in memory as follow:
  [Serialization bytes][might have a gap (rare)][Verify bytes][ ... ]

  So even, if Serialization is Private, it only matters for the Compiler
  and not for the compiled assembly code which can modify anything in memory
  that is allocated by the program.
  
  So, if you cast the pointer to get that first bunch of bytes,
  you could then access its content and verify what kind of data it is...
  It could be compared to an message header which it's purpose is to
  identify what the message is about.

  The idea is base from Java where you have a Serial and a Hash value
  to identify things like 'Object', the equivalent base root of void*
  but in the reference world.




18. LGPL Portable C++ Library looking for serious C++ programmers and Embedded C++ programmers.

Hi everyone,

I have started, few weeks ago, a portable C++ library that will offers plenty 
of very useful features, at a very reasonnable cost (FREE).    =)

It will provide a very safe, efficient and portable environment
to everyone, by providing a standard set of classes similar to
Java Common API with even more reusable objects for all kinds of duty.

By portable, I mean that it works on Standard C++ code that follows
the Embedded C++ Standard. 

It's LGPL licensed, which means that you can sell your application ($$)
even if it used this library.

Only derivation of this library most be kept free.

****************************************************************************************
You are tired of porting applications from a platform to another ?
e.g.  Windows <--> MAC <--> UNIX <--> Linux <--> 
         QNX <--> SunOS <--> HP-UX  <--> ...

You are tired of reinventing the wheel each time,
when you move from a compagny to another one ?

You are tired of spending money on commercial libraries that claims
to be portable, but you just had to port an application on a platform
which only have a single supported C++ compiler that is too restrictive 
and doesn't handle STL, templates and all the those new features ?

i.e. I know many platforms or specific hardware that are driving
      C++ programmers and Embedded C++ programmers crazy.

Furthermore, you didn't have the source code of that library to play with it ?

i.e. That's too bad. How many times did it happens to you ?

You write an application that must run on Windows, Linux/Unix and MacOS,
but MFC is just getting you crazy, since the previous guy that programmed 
this application is no more working at your compagny and he used all 
those non-portable MFC features, so that your life is getting 
a 'little' bit complicated ?  =)

You can't afford to buy another costly C++ library that doesn't fit fully 
your needs ?

****************************************************************************************

Well, I'm also tired of all those problems that makes my life painful,
so I decided to solve it using a library that will be freely available to everyone !


So, like I said I am looking for C++ experts that could help me with this library.

We are developing a HUGE C++ library that will or actually 
contains the following: 

                - Complex Class (done) 
                - String Class with StringData Rep (done) 
                - Safe Extreme cases Numerical Datatype (In development...) 
                   Long, Double, Integer, Float, etc. (That can handle infinity, 
                   divide by 0, NaN, Float Error, etc.) 
                - Engineering Mathematics, Numerical analysis, 
                   Vectors, Matrix, Fractals, Probability, etc. 
                - Newton, Lagrange, Richardson extrapolations, Iterative Search,
                  Gauss, Jordan, etc. 
                - File Classes (Random, Append, Database, Output, Input, etc.)
                - File Format Decoders/Encoders 
                for graphics (TIFF, GIF, BMP, PCX, JPEG, XPM, etc.) 
                for sound files (WAV, MID, MP3, AU, etc.) 
                for Documents (DOC, XLS, WPD) 
                for Archives (LHZ, ZIP, JAR, ARJ, RAR, ACE, etc.) 
                - DataStructure Classes (in development...) 
                - Trees, Graph, Iterative Tree, Map solver, Huffman, etc. 
                - Artificial Intelligence 
                - File Parser
                - File interpreters (Perl, Script, etc.)
                - Utilities 
                - Portable GUI 
                - Exception Handling, Error and Throwable Class (about done) 
                - Portable POSIX/QNX/Win/Mac compatible Real-Time classes. 
                - Geometry classes. (In progress) 
                - Other Maths class
                - Database support (SQL, ORACLE, DBase, Access)
                - Common API stuff (what you use so often...)
                - Extensive Testing of every classes...
                 (I plan to write a script to create a .cpp with all the functions 
                  being called in all the possible ways...)

                More ideas of what should be in it ? 
                Then post it on the "Requested Features" Forum 

                The language used is Embedded C++, which is a subset of C++. 
                There is no big difference between Embedded C++ and C++, 
                in fact Embedded C++ is C++ without all the "New Features". 
                (Templates, STL, Exceptions Handling, 
                 Type Checking, namespace, etc.)

                I'm developping the library on a FULL-TIME basis, 
                which is I release new stuff on a daily basis. =)
                (New file release) 

                There is a  CVS Repository also getting updated.

                Please take a look at the task manager and 
                the http://j2k.sourceforge.net homepage, 
                for more information about what has to be done. 

                It's a huge project by itself. 
                So, any help of any kind is DEEPLY appreciated. 
                I try to finish most of it this summer ! 

                If you think you can help, please send me an email 
                (fprog -at- users.sourceforge.net)

                Don't forget to include your SourceForge Username, 
                so I can add you to the list. 

                Don't forget to include a valid Email address, 
                so I can answer you back. 

                There is no specific selection process, if you wish to help,
                I suppose that you are serious enough to provide few hours
                of development per week. To get the project moving.

                I don't force people, neither I assign you task. 
                You are free to do whatever you want 
                from the list of things todo as long as it doesn't create 
                conflicts with someone else job. I'm very flexible on this.

                I espect from you to submit good working code, that looks 
                pretty similar to the one already submitted. 

                Which is efficient, portable and heavily readable. 
                If you are not sure what heavily readable means,
                you should read the following:

                How to Write Unmaintainable Code ! - what not to do. 
                http://mindprod.com/unmain.html

                It should also run on every platform, on any processor, on any OS 
                and on every C++ compiler on the market or that was on the market... 
                
                Simply, don't use code that are too platform specific 
                else you will end up with a huge club sandwich 
                of #ifdef and #endif everywhere in your code.

                It's not as hard as it sounds... 
                The current release theorically does that.
                Perhaps, I do not have access to every OS, 
                micro-processor and compiler on the market ! =) 
                So, if you got some special hardware or configuration, 
                it will please me that you try it on it ! =) 

                Anyway, 
                if you still think you can help, 
                then email me ! 

                Thanks, 
                Fred P. 

                fprog -at- users.sourceforge.net
                




19.











Some of these questions were asked by C++ folks
and my answer to them was reorganized to make this FAQ possible.
If you have any other questions that was not answered yet,
feel free to email me at the following ( fprog26 -at- hotmail.com ) email address.
If your question might help others, it will be add to this web page.

Thank you!
    
Send your comments, suggestions, modifications ?
to ( fprog26 -at- hotmail.com )
    







Page Size: 32 Ko
Creation date: June 15, 2000

You are visitor #


Last Update, visitor #5115 - Jan  26, 2001 - 20h20  (WEEKLY=83.42 / ALL=98.46) 368/206/34