structure/package data types..

Posted on 2005-04-13
Last Modified: 2013-12-03

working on java 1.5 for windows platform.

I have a base class CMainBase and have 4 classes derived from it , cboolean,

cintvalue, cstring and cother.

every data type(boolean, intvalue, string, other) has some attribute(s ) associated with it.


these attribute, can be any or combination for each datatype (string,

boolean, other, value). The length of each attribute is 1 byte.

I am planning to make a structure containing alll these types like:

public abstract class CMainBase {

class attrib{
byte read-only;
byte read-write;
byte execute-only;
byte hidden;

and then use the same. Is this the right way to proceed ?? How to use this

class to package all the attribtutes so that overall length should not exceed 1 byte ?? i mean to say looking at the value i can deduce the attributes present for a datatype.

All suggestion are welcome.  


Question by:rohitdivas
    LVL 15

    Expert Comment

    You can have one int variable (e.g int attributes)
    and then have constants like:
    public int READ = 1;
    public int WRITE = 2;
    public int EXECUTE = 4;

    (each value is bigger then its previous one by multiply of 2).
    Then you can assing to a type something like this:

    intvalue intVal = ..
    intVal.setAttributes( READ | WRITE); // or READ + WRITE;
    which means that this value has RW attibutes.
    If you want to check if this value has WRITE persmissions then you can do something like this:

    if ((intVal & WRITE) > 0) ... // then this value has write persmissions.
    There are many examples of the JDK for such technique (e.g.
    LVL 15

    Expert Comment

    For the Font class it is they way its store its style atributes (PLAIN , BOLD, ITALIC)
    or FlowLayout with its alignment attributes:

    Author Comment

    The combination of all of them should not exceed 1 byte.  but here it is exceeding.

    i need to achieve the functionality provided by enum data type (and enum is not provided in java) .  The method suggested by you will work, but  i am in search of alternatives methods.

    LVL 15

    Accepted Solution

    You can still use byte and apply the same technique (as long as you have less then 8 combinations).
    public byte READ = (byte) 1;
    public byte WRITE = (byte) 2;
    public byte EXECUTE = (byte) 4;
    public byte HIDDEN = (byte) 8;

    There is enum in Java 5.0
    Though they will not be one byte only (they are treated as objects).


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now