Solved

Modules in java?

Posted on 2004-10-22
505 Views
Last Modified: 2013-11-23
Is there a java equivalent to a module in VB. I am converting a VB application to java and the current VB app. uses a couple of modules. Is this functionality available in java?
0
Question by:ceasley
    6 Comments
     
    LVL 13

    Expert Comment

    by:petmagdy
    Java heirarchy is packages and classes

    A class is an OOP class and a packages is a group of classes, also if ur platform is J2EE then their are Enterprise application that contains multiple modules, each module contains a group of packages + other things the module types mainly are:
    1- Client Module correspondent to VB desktop application
    2- Web Module that is web based application correspondent to asp.net and others
    3- EJB module that is the business beans and the persisitance tier
    4- other type of modules

    0
     

    Author Comment

    by:ceasley
    So I can just create another class within the same package and my other classes will have access to the variables it holds? Or would it be better to create another package and import that package into the classes that need it. Thanks for the help ! ! !
    0
     
    LVL 8

    Accepted Solution

    by:
    No. if you dont specify any access specifiers for the variables in the class then all the classes within the same package will have access to it. if you specify like protected then only classes extending/inheriting it will get access, if it is public everyone will be having access which is not usually recommended, if private only that particular class can access it.
    Even if you create a new package and import the package into your class, the same rules apply as told above while accessing the variables.

    check out this
    http://www.artima.com/objectsandjava/webuscript/PackagesAccess1.html
    0
     

    Author Comment

    by:ceasley
    Thanks for the help guys . . .
    0
     
    LVL 13

    Expert Comment

    by:petmagdy
    u can create ur whole application in one package, but if 2 classes are in different packages they can still access each other it is the matter of OOP, here is a simple example suppose Class1 is in package1 and Class2 in package2 wants to access it then here is the code

    ****************** Class1 code ***************************
    package package1;

    public class Class1
    {
       protected String data;

       public Class1()
       {
       }

       public String getData()
       {
         return data;
       }
    }




    ******************** Class2 code

    package package2;

    import package1.Class1;

    public class Class2
    {
     public void main(..)
     {
        Class1 cls1 = new Class1();
        String theData = cls1.getData();
        System,out.println(theData);
      }
    }
    0
     

    Author Comment

    by:ceasley
    My problem is the way the VB application is set up it accesses and changes the values withing the module. The module also has a couple of functions which it uses and passes the variable it holds to these functions. The variables are set by other classes outside the module. Basically the module is used as a set of global variables that all other functions use/modify. I need this same functionality in java or I am going to be rewriting a bunch of variables over and over. If I instantiate a variable in two different classes the main class will not have access to the same value I need it to have. I guess I am having a hard time saying what I need to, but it sounds like I can't accomplish what I want in java....
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Lean Six Sigma Project Manager Certification

    There are many schools of thought around successful project management, but few as highly regarded as the Six Sigma and Lean methods. With 37 hours of learning, this training will explain concrete processes for increasing efficiency and limiting wasted time and effort.

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    884 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

    19 Experts available now in Live!

    Get 1:1 Help Now