class Animal { void makeNoise() {System.out.println("generic noise"); } } class Dog extends Animal { void makeNoise() {System.out.println("bark"); } void playDead() { System.out.println("roll over"); }
[Code] .....
The book states that the above code will compile if there is a downcast in the line 14 . But there is a compiler error saying playDead method is not defined for type animal even after downcasting.
I have implemented a deployment rule set for our JRE enterprise deployments and it is working fine. We are currently deploying JRE version 1.8.0_25. I have stumbled upon a Java App (a webcam) on an internet site that I cannot get to run with the deployment rule set.
The rule set works with other java apps, but it’s as though it is ignored for this one. The rule set section in the ruleset.xml with the intention of allowing the webcam to work is as follows:
<rule> <id location="IP Address of I assume the webcam, address specified in error when launching app" /> <action permission="run" /> </rule> <rule> <id location="URL of website hosting the webcam" /> <action permission="run" /> </rule>
I pulled it out of the deployment rule set and added it to the exception list without any luck getting it to work that way. How I can get this app to work with my Deployment Rule Set?
I have to use wrapper class for this assignment. I need to know if my code is more like object oriented or not and am I using the wrapper class properly here? Let me know if I can make this code better.
I also need to know if I can mask this password input (STRING) using NetBeans/Eclipse IDE?
Password rule is as followed : Length of Password 8-12, with no special characters, including minimum one uppercase letter, and only one numeric value.
Java Code:
import java.util.Scanner; public class Assignment1 { private static String password=null; private static void password_input()
I tried running the code for trapezoidal rule. It's my project in Numerical Methods, here's the code:
static double trapezoidRule (int size, double[] x, double[] y) { double sum = 0.0, increment; for ( int k = 1; k < size; k++ ) {//Trapezoid rule: 1/2 h * (f0 + f1) increment = 0.5 * (x[k]-x[k-1]) * (y[k]+y[k-1]); sum += increment;
[Code] ....
It cannot be compiled and I always get FileNotFoundException. I found on Javadocs that this will be thrown when a file with the pathname does not exist.
I have a signed certificate from Entrust which I used to sign a DeploymentRuleSet.xml file. I placed the DeploymentRuleSet.jar in the proper location C:WindowsSunJavaDeployment, afterward the java control panel's security tab shows a link to "show the active deployment rule set" which did not exist prior to coping the file to the directory. When I click on the link a new window opens and says "Rule Set not found" ....
I have to use wrapper class for this assignment. I need to know if my code is more like object oriented or not and am I using the wrapper class properly here? Let me know if I can make this code better.
I also need to know if I can mask this password input (STRING) using NetBeans/Eclipse IDE?
Password rule is as followed : Length of Password 8-12, with no special characters, including minimum one uppercase letter, and only one numeric value.
Here is the code :
import java.util.Scanner; public class Assignment1 { private static String password=null; private static void password_input() { Scanner input = new Scanner(System.in); password = input.nextLine();
I have to use wrapper class for this assignment. I need to know if my code is more like object oriented or not and am I using the wrapper class properly here? Let me know if I can make this code better.
I also need to know if I can mask this password input (STRING) using NetBeans/Eclipse IDE? I did search, but I found the console method.
Password rule is as followed : Length of Password 8-12, with no special characters, including minimum one uppercase letter, and only one numeric value.
public class CheckingPassword { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Please enter a Password: "); String password = input.next();
I have to use wrapper class for this assignment. I need to know if my code is more like object oriented or not and am I using the wrapper class properly here? Let me know if I can make this code better.
I also need to know if I can mask this password input (STRING) using NetBeans/Eclipse IDE?
Password rule is as followed : Length of Password 8-12, with no special characters, including minimum one uppercase letter, and only one numeric value.
Here is the code :
import java.util.Scanner; public class Assignment1 { private static String password=null; private static void password_input()
Make a password rule, and take input of the password from the user and compare the password with your rule, if the user had entered valid password then print the message, password valid, else the password is invalid for (the whatever) reason.
Rules:- -Length 8-12 -Should have one numeric character -No Special Character -Atleast one UPPERCASE letter
PHP Code:
import java.util.*; import java.lang.String; import java.lang.Character; public class PasswordSpence { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Please enter a Password: "); String password = input.next(); if (isValid(password)) {
I have studied that Generics are used to shift the Class Cast Exception into Compile time errors , So that we get errors at compile time error and we do correct them before executing ,but Here is a program in which i am getting Class Cast Exception
class Animal { } class Dog extends Animal { } class Cat extends Animal
[code]..
Getting Exception at line no 29 which i know why it occurs but just wanna ask that isn't it should be caught at compile time According to Generics ?
Set<? super TreeMap> s = new HashSet<SortedMap>();
SortedMap<String,String> sm = new TreeMap<String,String>(); TreeMap<String,String> tm = new TreeMap<String,String>(); s.add(sm); //This fails s.add(tm);
Why does adding sorted map to a Set that allows ? super TreeMap and instantiated as such fail?
public int[] allIndicesOf(E itemSought) { ArrayList<Integer> toUse = new ArrayList<>(); for (E anArray : container) { if (anArray.equals(itemSought)) { toUse.add(container.indexOf(itemSought));
[Code] ....
I have an array list of strings. I want to be able to return an array of integers telling me which indexes in the string array list contain the itemSought object.
Why java uses the keyword extends when setting the bound of a type parameter(Generic) to an interface. I think using the keyword implements is more intuitive.
public static <T extends Comparable<T>>
why use extends? and not implements.
int countGreaterThan(T[] anArray, T elem) { int count = 0; for (T e : anArray) if (e.compareTo(elem) > 0) ++count; return count; }
I know if I want to set multiple bounds I will use extends keyword, and I will concatenate the bounds using & operator.
Is this a design decision to always use extends keyword to set bounds?
public static <E extends Comparable<E>> void sort(E[] list... mh_sh_highlight_all('java');
Comparable is an interface and from how i look at this piece of code is that I can only use a class that implements the Comparable interface; however, this is the context my book uses when explaining the following code
First, it specifies that E is a subtype of Comparable.
Second, it specifies that the elements to be compared are of the E type as well.
I've an interface with generic methods in it. I would like to have specialized methods in the sub types. While doing that I'm seeing the following warnings in eclipse.
class Sorter { <E> void sort(E[] elements); };
class StringSorter {
// This gives me a warning 'hiding' to 'sort' <String> void sort(String[] elements) { }
// Gives me an error "The method someCrap(String[]) in the type StringSorter is not applicable for the arguments (String[])" void someCrap(String[] elements) { } };
I would like to understand why eclipse gives the above warnings and errors.
I'm working with Doubly Linked Lists and using Java Generics..
My nodes looks like this: class DNode<E> { DNode<E> previous; DNode<E> next; E element;
//and all methods inside }
My list of Nodes looks like this: class DLL<E>{ private DNode<E> head; private DNode<E> tail; private int size;
[code]....
As you can see, as arguments they get "E o"...I need to write a program, which from the main function asks the users how long is the list, and after they type it's length, I ask them to start typing the elements (integers)...and this is how my main method is written, but I can't seem to make it work, specialy when I call the "insLast" method,I guess it's because the arguments i'm giving to the function...how to read the elements and write them into the list?
public static void main(String[] args) throws IOException { DLL<Integer> lista=new DLL<Integer>(); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String s = stdin.readLine(); int N = Integer.parseInt(s); s = stdin.readLine(); String[] pomniza = s.split(" "); for (int i = 0; i < N; i++) { lista.instLast(Integer.parseInt(pomniza[i])); }
i am interested to add integer objects and String objects into any collection object ..... while iterating the collection object i am not interested to do any type cast in java
I am trying to make a generic method that will replace the data type T with those number types usable with a Scanner object. However, whenever I try to compile, I get errors saying that a Byte/Integer/Double etc are found when only a type T is allowed. This is the beginning of my method. I can;t understand what is wrong with it.
Java Code:
public <T extends Number> T nextRanged(T lowerBound, T upperBound, boolean inclusive, String errorMessage){ // Holds program execution until user inputs a numeric value between the bounds. Prevents all other input without exception. // Output data type determined by the type of the bounds. T input = null; try{ if(input instanceof Byte){ input = new Byte(internalScanner.nextByte());
[Code] ....
The purpose of the method, in the end, will be to provide the nextXXX() functionality of a Scanner object but with built in validation procedures. I could easily do this by making a nextIntRanged(), nextDoubleRanged() etc methods, but this seems wasteful to me.
I meant "incompatible type errors"!
Error example:
ValidatedScanner.java:57: error: incompatible types input = new Byte(internalScanner.nextByte()); ^ required: T found: Byte
where T is a type-variable:
T extends Number declared in method <T>nextRanged(T,T,boolean,String)
The erasures of all constituent types of a bound must be pairwise different, or a compile-time error occurs.
Well I know what type erasure is, and I think I kind got what this statement means. My understanding from it is that if your type parameter has more than one bound and those bounds occurs to be the same type after erasure that is a compile-time error. Is that it?
The only thing I could found related is something like this:
class A<T extends List<Integer> & List<Integer>>{ }
Which as you might know gives the Duplicated bound error.
Create an equals method that takes an object reference and returns true if the given object equals this object.
Hint: You'll need 'instanceof' and cast to a (Geocache)
So far I have:
public boolean equals(Object O){ if(O instanceof Geocache){ Geocache j=(Geocache) O; if (this.equals(j)) //I know this is wrong... but I can't figure it out return true; }
else return false; }
I think I have it correct up to the casting but I don't understand what I'm suppose to do with the this.equals(). Also I'm getting an error that I'm not returning a boolean... I get this all the time in other problems. I don't get why since I have to instances of returning booleans in this. "returns true if the given object equals this object" makes no sense to me. I assume the given object, in my case, is 'O'. What is 'this' object referring to?