Fundamentals?!!!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Fundamentals?!!!!

  1. #1
    Join Date
    Jul 2006
    Posts
    1

    Fundamentals?!!!!

    Hi all,

    I have some basic questions with Java langauge.

    1. In Java, why the main() fn should be inside some class. Main is a place where objects interact, so it can be anywhere as in C++. Why does it restricts us to place the main inside some class.

    2. Why Java restricts us to dynamic memory allocation. I mean, why cant objects be created at compile time and only at Run time.

    I need a justifying explanation

    Thanks,
    Pradeep

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    The fundamental unit of structure for Java is the object which is defined by a class abstract data type. Afterall, Java is an Object Oriented Programming language. Everything is a java program is an object (except the primitive data types). It makes sense and, when you think about it, is imperative for this language to include its method main (and all other code) within the definition of a class which defines an object.

    Not all allocation is dynamic - any static member is created in the program stack.

    I propose two main design decisions in the answer to your question: to provide a uniform process of creation of objects and reference to those objects and memory management.

    All objects are created through a call to new. All objects are accessed through reference.

    Too many people are unable to learn, or get messed up by, memory management in languages such as C and C++. A key design feature of Java is that the language provides memory management, behind the scenes, in the JVM. Makes sense, since the organizing element of program design is objects, and the performance of instances of objects which are created and destroyed.

    Yet another design decision which may play a part in this is that since Java is a write once, run anywhere language, "compilation" is the process of creating "byte code" which is then interpreted execution to the Java Virtual Machine. Static binding is operating system specific. That binding should be implemented by the JVM, not the compiler.

    I expect you can access MANY articles and papers on these design decisions on the Internet. Take a look at the Java Developer site.

Similar Threads

  1. Replies: 0
    Last Post: 03-05-2003, 01:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center