Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is an int array (int[]) apart of the Java Collections or Java Library?

 
Luke Winter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an assignment for class and the teacher has explicitly said No use of Java libraries, or any other libraries. (That precludes, for instance, the use of any Java Collections.) This means that NO IMPORT CLAUSES ARE ALLOWED.

I have used:



I didn't use any imports and from what I can see, is not apart of the Java Collections or Libraries. I just want to make sure otherwise I get a 0. Is it?

Thanks.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15281
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays are a built-in Java language feature. They're not part of the Java collection classes or standard Java library.
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you also don't use anything from java.lang. These don't need to be imported but are part of the core library. That means you can't use String, Object, Integer etc.
 
Luke Winter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Make sure you also don't use anything from java.lang. These don't need to be imported but are part of the core library. That means you can't use String, Object, Integer etc.


Thank-you Rob!
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luke Winter wrote:
Rob Spoor wrote:Make sure you also don't use anything from java.lang. These don't need to be imported but are part of the core library. That means you can't use String, Object, Integer etc.
Thank-you Rob!

Hmmm. It depends what your tutor's 'rule' actually means. Is it "no import statements" or "no use of any libraries"?
Rob's quite right that java.lang is a library; but not allowing it means that you can't use any objects at all except arrays (because Object itself is also part of java.lang), which seems an odd way to learn an Object-Oriented language.

You might want to check with him/her to make sure exactly what the rule means.

Winston
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The teaching goal of this exercise completely eludes me. "Here's a bicycle, learn how to ride it but don't use the pedals." WTH?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15281
39
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also wonder how strict the rules are - because really, it's impossible to write a Java program without using anything from the java.lang package at all.

Look at this super simple program.

What could be "wrong" with this?

  • Class Example implicitly extends java.lang.Object. So, we're already (implictly) using a class from java.lang there.
  • The main method takes a String[] as its argument. That's just how you have to write it. No escaping from using class java.lang.String here.
  • Class System is also a class from the java.lang package. If you were not allowed to use this, your program couldn't print any output at all.

  •  
    Rob Spoor
    Sheriff
    Pie
    Posts: 20529
    54
    Chrome Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Don't forget the PrintStream (from java.io!) you're using there.
     
    Matthew Brown
    Bartender
    Posts: 4567
    8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Of course, if the rule was just "no imports", you can fully qualify all your class names and use whatever you want!
     
    fred rosenberger
    lowercase baba
    Bartender
    Posts: 12124
    30
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This assignment seems about as useful as

    Can you write a program that doesn't use the letter 'e' in it anywhere. Even if you can, what would be the point?

     
    Matthew Brown
    Bartender
    Posts: 4567
    8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    More seriously, I suspect it's a clumsy way of phrasing an exercise in using arrays and loops to stop people using collection classes that would make life too easy and side-step the things that are actually being tested.
     
    Winston Gutkowski
    Bartender
    Pie
    Posts: 10417
    63
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Jesper de Jong wrote:Class Example implicitly extends java.lang.Object...

    Which raises an interesting point. Does xxx[] actually extend java.lang.Object or not? I suspect so since, as we all know, arrays are objects; but since it's part of the language it could simply be a structure dressed up to look like an Object.

    I suspect it's stated in the JLS somewhere; I've just never had reason to find out.

    Winston
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 48954
    60
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote: . . . Does xxx[] actually extend java.lang.Object or not? . . . I suspect it's stated in the JLS somewhere; . . . Winston
    Of course it is in the JLS.
     
    Jesper de Jong
    Java Cowboy
    Saloon Keeper
    Posts: 15281
    39
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston Gutkowski wrote:Does xxx[] actually extend java.lang.Object or not? I suspect so since, as we all know, arrays are objects; but since it's part of the language it could simply be a structure dressed up to look like an Object.

    That's really a theoretical discussion for which I'm not sure if there's an answer, but it doesn't matter. If an int[] looks like an Object, behaves like an Object, has all the methods of class Object, then does it matter if it really extends Object or if the compiler just makes it look like an Object? What does the difference even mean if there's no practical difference when using arrays?

    The JLS paragraph that Campbell linked to says that arrays inherit the members from Object, which seems to imply that arrays indeed extend Object.
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 48954
    60
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    …And if you scroll up, it says you can assign any array to an Object reference. If you scroll down there is an example where it prints the name of the superclass.
     
    Winston Gutkowski
    Bartender
    Pie
    Posts: 10417
    63
    Eclipse IDE Hibernate Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Jesper de Jong wrote:If an int[] looks like an Object, behaves like an Object, has all the methods of class Object, then does it matter if it really extends Object or if the compiler just makes it look like an Object?

    Because of the rather ambiguous "rules" that started off this whole thread. It may be splitting hairs to you, but it might mean a 0 for poor Luke.

    Winston
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic