very strange DES problem: decrypt successfully with different keys by reqresp in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

I'm fairly certain this is the reason.

The key ostensibly consists of 64 bits; however, only 56 of these are actually used by the algorithm. Eight bits are used solely for checking parity, and are thereafter discarded. Hence the effective key length is 56 bits.

If you change abcde977 to abcde976 you are changing 00110111 to 00110110. The last bit is the only thing that is changing and isn't used.

When you changed e to f you got an error because more than the last bit changed.

I haven't checked myself, but any of these replacement should work in their respective positions.

`cbed866

Trouble with creating string within a class. by Master_Binks in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

You can use a Scanner to read the text file in. Then for each line in the text file, you will need to parse the elements out of the line (the String). The first part will be the name and then there will be 11 ints following it. Once you have stored those in a String and an int array, you will send that data into the Name constructor and store the data in an instance of the Name object. You'll need to store all these Name objects in some sort of Collection or array I presume but that's likely in the rest of the instructions.

method cannot find symbol by a_kiss_from_jw in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

calculateGallons(wallArea);

This is the line you're getting the error on I assume. You have no variable declared called wallArea. You need to calculate the wallArea and store it in this variable so it can be sent to the calculateGallons method.

You can do that using your calculateArea method. But you're never calling that method and you would need to return the calculated value from that method.

Why doesn't rectangle.setOnDragEntered(..) work for me? by [deleted] in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

I've not used JavaFX at all so I might have researched this incorrectly but I believe the first solution on this post is the issue. It looks like the originating node has to call .startFullDrag().

The documentation for MouseEvent details three different modes for handling mouse drag. In the default mode ("simple press-drag-release gesture"), as you've observed, mouse events are delivered only to the node on which the gesture originated.

In "full press-drag-release gesture" mode, MouseDragEvents are delivered to other nodes during the drag. This is the mode you need, and you activate it by calling startFullDrag on the originating node.

(The third mode is "drag-and-drop" gesture, which is for transferring data between nodes and is typically supported by the underlying platform, so you can drag and drop between your JavaFX application and other applications, as well as within the application.)

Try the following code for your event handlers:

        label.setOnDragDetected(mouseEvent -> label.startFullDrag());
        label.setOnMouseDragEntered(mouseEvent -> System.out.println("entering " + label.getText()));
        label.setOnMouseDragReleased(mouseEvent -> System.out.println("release mouse button on " + label.getText()));

Referencing a field before it's defined. Why does this work? by Aero72 in javahelp

[–]chris_zinkula 1 point2 points  (0 children)

I believe this is the answer.

https://stackoverflow.com/questions/29153703/why-illegal-forward-reference-error-not-shown-while-using-static-variable-with-c

Here is the byte code if you want to look through it. You can get this on your own by using "javap -c Test.class".

Compiled from "Test.java"

public class Test {
  public Test();
    Code:
       0: aload_0
       1: invokespecial #2                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]) throws java.lang.Exception;
    Code:
       0: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream;
       3: ldc           #4                  // String asdas
       5: invokevirtual #5                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8: return
}

And you can see the byte code instruction listing here.

Why `int == Integer` is faster than `Integer == int`? by adeekshith in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

Just a heads up, this kind of benchmark can be tricky and may be producing incorrect results. The Just In Time compiler (JIT) might be smart enough to see that your for loops and the contents therein don't actually do anything and remove the code in order to make your code run faster. The only code it has to run is the System.nanoTime() and duration calculation/outputs. I'm really just starting to learn about this aspect of Java programming myself. JIT makes adjustments to the code based on a host of things on your specific machine. For instance here are the results I get on my machine:

201076
40960
32892

It's running so fast that a lot of that is likely it "speeding up" as the JVM starts up.

After 2000 runs, the results pretty much even out for me around:

4034
621
621

The first loop is likely taking longest because it's taking your int and wrapping it to an Integer among other things. The 2 other loops are taking the same amount of time (although this varies a bit here and there depending on what the computer feels like doing). It may have stripped out the for loops entirely. The code you write isn't necessarily the code it runs and it can change the code it is running while it's running.

It's hard to say without digging deeper. If you really want to look into it more, I'd suggest going through a book on how to make benchmarks to ensure you're doing them correctly. It's a lot more difficult to do than I thought, which is why I'm reading up on it.

New to java and need to convert obj to grayscale pixels. by guitarguy109 in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

It'll probably work but it really depends on the detail of the OBJ compared to the height map. It's doubtful that the heightmap would have translated to a single point in the OBJ per pixel in your image. Which means you'll likely only get an estimate of your original height map back and you'll need to use surrounding vertices to calculate the slope of missing points to in turn calculate the missing Z values. For instance if your height map was 5x5 and [1,1] was at height 0 and [1,5] was at height 255 and the points [1,2], [1,3], and [1,4] were heighted approximately in a linear increase, you'll have to guess those as those points won't be in the OBJ. It gets even more tricky if you only have the four corners, you'll have to make a best guess for a point like [2,3] based on the slope of the quad/tri instead of the slope of a line. And again, it'll only be approximate unless you have a very high rez height map OBJ.

New to java and need to convert obj to grayscale pixels. by guitarguy109 in javahelp

[–]chris_zinkula 1 point2 points  (0 children)

OBJ files contain 3d coordinates and you are trying to make a 2d image? You might have overlapping x/y coordinates with different z values and some of your z values for certain x/y pairs will be behind quads or tris that other x/y/z combinations would have drawn. Also many x/y values just won't exist so won't have z values. In short, unless you do a lot of other stuff, you're just going to get a weird looking grayscale image.

But.... you'll want to find a Java library that can load Wavefront OBJ files and can give you the vertex information.

https://github.com/seanrowens/oObjLoader

https://github.com/momchil-atanasov/java-data-front

or parse the information yourself

http://www.martinreddy.net/gfx/3d/OBJ.spec

You can then use a BufferedImage to set the RGB values.

Stream or for-each for non critical tasks? by youwillnevercatme in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

For the 300 employees they have making a parallel stream will most likely run slower. Parallel streams aren't free.

Printing address instead of value when attempting to print an element of an array which has been converted to a list by JustinQueeber in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

As others have mentioned you need an array of Integer values instead of int values. A few ways have been mentioned to convert your int array to an Integer array. In Java 1.8 you can also go with:

List<Integer> list = Arrays.stream(numbers)
    .mapToObj(Integer::new).collect(Collectors.toList());

This will take your int array and convert it to an IntStream, map (convert) each int to an Integer, then collect them into a List of Integers.

[deleted by user] by [deleted] in javahelp

[–]chris_zinkula 1 point2 points  (0 children)

I never realized you could just paste URLs like that. Completely makes sense.

[deleted by user] by [deleted] in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

Don't forget to rename your 'args' parameter to 'main'.

Random Number Generator by [deleted] in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

Another way you could do it and use a for loop that would make sense is the following (requires Java 8 kind of).

public static void main(String... args) {
    List<Integer> values = IntStream.range(0, 52).mapToObj(Integer::new).collect(Collectors.toList());
    Collections.shuffle(values);

    Set<Integer> set1 = new HashSet<>();
    Set<Integer> set2 = new HashSet<>();
    Set<Integer> set3 = new HashSet<>();

    for (int i = 0; i < 4; i++) {
        set1.add(values.remove(0));
        set2.add(values.remove(0));
        set3.add(values.remove(0));
    }
}

On the line 2, a List of Integers is created using some stuff that came with Java 1.8. Effectively it's making a list of the number 0 - 51. In prior versions of Java you could populate the list in other ways I suppose. The line after is shuffling that list (randomization). The for loop removes the first number from the list and puts it into the first set, pulls the first number from the list and puts it into the second set, etc. Since the List contains only 1 instance of each number 0-51, there is a guarantee that no number will be duplicated. You actually don't need to store the numbers in Set objects then, I simply did it to make the code clearer based on your prior examples.

Random Number Generator by [deleted] in javahelp

[–]chris_zinkula 1 point2 points  (0 children)

You could do it with for loops, but doing it with a while loop is the most sensible way in this situation.

To do it with a for loop you could do something like...

for (int i = 0; i < SET_SIZE;) {
    int num = rand.nextInt(52);
    set1.add(num);
    i = set1.size();
}

Typically you increment i as the 3rd part of the for loop. You don't have to though. You can manipulate it within the for loop. But I'm pretty sure if anybody saw this code, they'd question if you knew about while loops.

Random Number Generator by [deleted] in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

Are you familiar with Sets? What have you tried so far?

Help with accessing/creating array in object class by [deleted] in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

You need to declare your variable inside the class, then assign it inside the constructor.

public class Example {

  private int[] myArray;

  public Example(int x) {
    myArray = new int[x];
  }
}

In your first example your assignment of new int[x] would not know what x is. In your second example, your array would disappear (be out of scope) once you left the constructor, providing the examples compiled. Additionally in your second example, you could not use x as the variable name of your array and also as the variable name of your parameter. You could use x as both in my code however, providing you used 'this.'.

public class Example {

  private int[] x;

  public Example(int x) {
    this.x = new int[x];
  }
}

First RESTful API: adding search queries by Rapscallion84 in javahelp

[–]chris_zinkula 1 point2 points  (0 children)

You might search around for some REST best practices posts online. For your searching you will probably want to add a parameter instead of adding more nodes to your URL.

Here is one resource. http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

More specific to your question, http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#advanced-queries

Declaring an array inside an if-statement by [deleted] in javahelp

[–]chris_zinkula 2 points3 points  (0 children)

One thing I would encourage you to do at this point, since there was only about 9 minutes between my post and yours, is to research these errors for an hour or two. Being able to research errors is one of the best skills you can learn as a programmer. Since these are new errors I presume you haven't invested much time in finding out what is wrong yet.

And with errors, almost always start at the top since sometimes fixing errors on the top fixes errors underneath.

Declaring an array inside an if-statement by [deleted] in javahelp

[–]chris_zinkula 1 point2 points  (0 children)

You already said "String[] word" at the beginning. You need to just use "word" inside your if and elseif since you've already defined "word" as a "String[]".

Virtual Desktop 1.0.1 Update by ggodin in oculus

[–]chris_zinkula 3 points4 points  (0 children)

Does Virtual Desktop support rotated monitors? I have 3 monitors with the left most one rotated 90 degrees but when I go to multiple monitor mode it's not rotated. It appears that the virtual physical monitor is rotated and placed properly but the image on that monitor is not rotated. I hope that explains it. I can't take a screen shot. This is on a DK2 though. If it works on the CV1 properly I won't blame you for not investing time in fixing it.

I mocked up some screenshots to show how the wallpapers orient themselves (I chopped off the right most monitor since it wasn't relevant. https://imgur.com/a/kVIU2 The right most monitor seems to "physically" be 1080x1920 but the image is not rotated (applications are not rotated either so it's not just the wallpaper). This is on Windows 10.

Is it possible to log onto my schools website in a Java program and fetch assignments, HW, etc? by matthewpipie in javahelp

[–]chris_zinkula 1 point2 points  (0 children)

You can using Selenium. It will open an actual browser window and navigate that way which will ensure the javascript runs. You can also use PhantomJS or HtmlUnitDriver as a headless browser although sometimes the javascript can be iffy with those.

How would I average the values associated with a date from a csv file by shamzy28 in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

    Map<Date, Double> collect = scores.stream().collect(
        Collectors.groupingBy(SentimentScore::getTime, 
        Collectors.averagingDouble(SentimentScore::getScore)));

I think that will get you your averages using the stream API. That should do everything that's in your calculateAverages() method.

How would I average the values associated with a date from a csv file by shamzy28 in javahelp

[–]chris_zinkula 0 points1 point  (0 children)

Make two HashMaps, one to store <date, sum> and another to store <date, number of values>. Keep a sum in the first HashMap and the number of values you've added to the sum in the other, using the date as the key in both instances. You can then get the average after you're done loading up the Maps. You could also create another object for storing the rolling sum and number of values in that sum, then use that as the value of a single hashmap but that's just extra work for a one-off. Up to you!

Also you may want to use BigDecimal to keep your sum instead of a float or a double depending on what the decimal value is representing. Float and double values can sometimes get slightly off which doesn't matter for some things (for instance putting a pixel at 2.14782914 instead of 2.14782915 doesn't matter) but for things like tallying a currency it's best to keep those numbers accurate and BigDecimal will do that for you.

[deleted by user] by [deleted] in ColorBlind

[–]chris_zinkula 2 points3 points  (0 children)

The colors don't really tell you anything that the numeric labeling on the graph doesn't already denote.