Whilst pre-preparing for java certification, one of the online mock exams has slightly confused me by saying my answer was incorrect for multi-dimension array 'declaration and instantiation'.
This is one of the answers i chose - which was marked as incorrect
a) int[][] array2d = {{123}, {4,5}};
Which looks absolutely fine to me.One of the other answers, which i agree is correct and so does the mock exam is
public class Person { private String name; private int age; public Person (String name, int age) { this.name = name; this.age = age;
[Code] .....
And I need to write a simple main method that creates lots of instances of the Person class and adds them to a generic instantiation of a Collection (ArrayList). And I need to make it so I as a programmer can define how many instances to create.
Where usually to instantiate and declare variables to be used in a loop. If you declare it outside to be used in the loop it will still be there when the loop is done, never to be used again and is just sitting there taking up memory. However, if you declare it inside the loop, you have the issue of it constantly creating space for said variable, but once it's out of scope it's gone. Is there any advantage performance wise to doing it either way?
I am doing a Junit test case, but I keep having issues with AssertEquals ( object expected, object actual). I don't know how to reference the other actual object so that it can compare to the expected.
public void add (Distance d) throws CustomException { //I can also convert feet to inches and add all inches together and then divided inches to feet and inches Distance result = new Distance(); int newFeet = this.feet + d.getFeet(); int newInches = this.inches + d.getInches(); if(newInches > 11) { newFeet = newFeet + (newInches/12);
I don't really know what this means and it is sending an error when I try to run my program I am trying to set the x and y value (Int x and int y) to setVisible false at a specific time in my game but it keeps sending the error that int is not a reference type.
I'm fairly new to Java, I'm very experienced with C++ and C# in which you can pass by reference - extremely useful. Take for example this bit of code in C#:
class MyClass { public MyClass(int i) { m_i = i; } public int m_i;
[Code] ...
Just at the end of this program x.m_i will be equal to 8. As far as I can see this is not possible in Java: you can't pass a double by reference, using a Double will kick in the autoboxing so that won't work either. The only "solution" in Java would be to pass in a double[] (of length 1) or to make a wrapper class, both nasty solutions because a user may want to just hold a double as a member of their class just as I have, for reasons such as not allocating more memory for a class and generally not being bloated.
I am making an MVC program and I am not allowed to put the action listeners in the view class. I was able to get one button working fine but since I am unable to reference them I cannot give them both individual responses.
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Controller { HobbyList model; ListView view;
public class { public static void main(String[] args) { Scanner input = new Scanner(System.in); double[] numbers = new double[10]; System.out.println("Enter " + numbers.length + "numbers"); for (int i = 0; i < numbers.length; i++) { numbers[i] = input.nextDouble();
[Code] .....
I am trying to reference the input "numbers[i]" to my mean method, how do i do that?
I know in C++ It's possible to pass by reference but what about java?
For example, can i pass the address of a health variable into a Ninja class and then
Since Ninja inherits from an enemy class pass the health into the enemy class and within there have a function that returns that same health address and takes 5 from the health returning 95.
I passed my abstract class private final reference to another concrete class and I used abstract class reference as parameter to that concrete class constructor and in my main method and null to that parameter then only that program executes correctly...i placing my code below ..if there is any error tell me where is error occurring then i will check my code...i think my code is right but little bit doubt abstract class concept.
{ } class concept1 extends concept { private final concept parent; public concept1(concept aparent) { parent=aparent; System.out.println(parent); } public static void main(String args[]) { //concept p=new concept1(null); concept c=new concept1(null); }}
This means that x is a reference to objects of type, "myType" and no memory has been set aside for an instance of this object. I think it's true that x also has the starting memory address of this object.
What I feel uncertain about is if x is telling the JVM(?) where it can find the starting address of this object, why do we care about the type that x is?
i.e., if we assign x to an object totally unrelated to this type then the compiler would complain - correct? If so, how come, since all x is doing is telling the JVM(?) where to find your object (via the address it contains).
I suppose all, hy a reference has a type associated with it if all the reference does is point you to the object?
1. A reference variable can be of only one type and once declared, that type can never be changed(although the object it references can change)
2. A reference is a varaible ,so it can be reassigned to other objects(unless the reference is declared final)
3. A reference variable's type determines the methods that can be invoked on the object the variable is referencing.
4. A reference variable can refer to any object of the same type as the declared reference , or - it can refer to any subtype of the declared type.
5. A reference variable can be declared as a class type or an interface type. If the variable is declared as an interface type, it can reference any object of any class that implements the interface.
How can i check the reference that is not duplicate and date format is DDDCCYYnnnnnnn, CC must be 20 and YY must not be less than the current year, nnnnnnn is the sequetial number of the file and to complete the 7 numeric characters, zero's must be populated in front of the number. DDD must be a valid reporting entity code. there must not be a duplicate. Code I try
I am unable to understand the meaning of this sentence "final reference variables must be initialized before the constructor completes.",What is trying to imply?
I have started working on a little project in my free time. It is just a simple text rpg that runs in a counsel window. I have 5 files each file contains 1 class.
public class SomnusCharacter { private String gender = ""; private int age = 0; private String race = ""; private int level = 0; private int xp = 0;
[Code] ....
The chain of events right now is:
1. MainMenu is run 2. If user inputs n CreateCharactor is run 3. User inputs name, age, ect in SomnusCharacter object made in CreateCharacter 4. Intro (just rough demo for testing purposes) is run 5. If user inputs m Menu is run 6. Menu calls and prints out all the information from the object made in CreateCharacter
Step 6 is where I am having my problems. How can I reference (lets say the SomnusCharacter object made is called player) player from my Menu class? I know that if I made a new character that it would just create another SomunsCharacter object with the default values again.
I read somewhere : "Java use clone() method of Object class to copy content of one object to the other. The problem will arrive if the Class that needs to be copied also contains reference to the other object."Not able to understand the second line.
next.xhtml: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
[Code] ....
`MyQueueBean` is intended to give out a bird once only, to exactly one end-user. Because it's application scoped, and not session scoped, getting attributes directly from the bean would give inconsistent results.
The birds application is from Facelets Essentials Guide to JavaServer Faces View Definition Framework: [URL] ....
how is the variable passed to the file? Once it's passed, how is it referenced?
Is there a short term that means: "using an object reference with the datatype of a supertype to refer to an object with the datatype of a subtype"?
Saying "polymorphic reference" doesn't seem to be specific enough because ALL references other than those with the Object datatype are polymorphic. I saw one post that referred to these reference variables as a "supertype reference." In the absence of any other (more official) term, I may just use that term because calling a reference a "supertype reference" implies that there is a subtype. It sure beats what I was thinking about using: "sub-as-super." Which, when the inevitable mispronunciations occur, would lead to all kinds of off-color jokes.
Is there an "official" term that all of the dozens of Java books I have read seem to have missed? Or does everyone stumble along, spelling things out with a nearly sentence-long phrase.
I have just started to work on Java EE and I am not able to put the refrence of css and javascript in jsp page.
My senario is below: I have created script file inside myJavaScript Folder like Web Container-> myJavaScript ->Home.js. Similarlly for css:Web Container-> myCss ->Home.css.
My Jsp page palced inside Like: Web Container-> Home ->Home.jsp.
How to give the reference of js and css file in my Home.jsp page.
i'm having issues with pass by reference between remote EJB method calls. Below is what i'm trying to do. The EJB method calls are made using remote (EJBObject) interface.
Check out the following basic code (assume that dog has a method called bark):
Dog d = new Dog(); Object o = d;
o.bark(); // error
But why? Isn't o just a pointer to a memory address which has the dog object? If so, why can't the compiler see that the object has a method called bark? Or, to ask the question another way, why is Java designed to check the object reference to see if the method exists instead of the object itself?