« first day (2458 days earlier)      last day (2707 days later) » 

02:45
is there anything that is similar as to using string buffer in java?
I can do this
StringBuffer theText = new StringBuffer();
but i cant do StringReader theText = new StringReader();
03:12
can someone also look over my code
im having trouble formatting the file
nvm
im don
04:00
"Let our advance worrying become advance thinking and planning." -Winston Churchill (source)
04:59
@Brogrammer or you instantiate a private scanner in you class
right
but no worries
i finished
congrats! :D
though i used a string buffer
we didnt learn it tho
but idc
need atleast a 50
on this assignment for an A
got your code up for taking a look at it?
sure i can share but its not neat
i was too tired to fix it up
05:02
when is due time?
Sunday at midnight
i already submitted tho
because the output was correct
now im just doing c# hw
which i have alot of due sunday night
but ill get done
for ur own amusement
@Brogrammer I would have read in the file content like this in your case
rawinput = new String(Files.readAllBytes(Paths.get(inputFile.getAbsolutePath())),Charset.defaultCharset());
replace all linebreaks and whitespaces:
rawinput = rawinput.replaceAll("\\s","");
i cant do that tho
why is that?
havent learned
lol
i def need to brush up
on my java tho
with making these objects
since when is string an object
lol
05:13
well tbh there is nothing special to learn :D
you create a new String (that you learnered)
and you are using the Files api that is native aswell as Paths, which is also native
lol true
thats y ur gold 4
the result you are getting with the above is a single line string with all you characters lined up
@Brogrammer haha :D
actually I got G3 yesterday :D
oh whoa
must be naut jg
absolutely
and kog adc
05:15
and as autofill lux supp
kog adc i havent heard in forever
@Brogrammer String has always been an Object
like Integer and Double not to confuse with double and int which are primitive types
like im used to doing this in c#
Circle c = new Circle(10);
I think its the same with strings in java?
i honestly get the syntax's mixed up
well you can write String s = new String(anyprimitivearray[])
but y would u want to
05:21
What's up Java room, what's up!! Wooo
@McDonald's Welcome to the Java Chat, the room for Java enthusiasts! Please use a code snippet tool when posting code snippets. If you have an Android question, you're in the wrong place! And remember: this is not tech support! Thanks for visiting and have fun! :D
Well I'm outta here, going to check out Python rooms now, don't get jealous!! ha ha
to write a oneliner that will create a String based on a text file. That String can take an array of primitives. Since "byte" is a primitive I chose the method (https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#readAllBytes(java.nio.file.Path)) which returns a byte-array
and that's how it looks:
rawinput = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())),Charset.defaultCharset());
any golang guy here ?
@AtharvaPandey sundays it's usually dead in here :) Unfortunately I'm not into golang
05:30
i thought so @motaa actually i am getting an unusual answer with my algo i dont know what i did wrong
i guess you can still look should i paste code here
sure
package main

import (
	"fmt"
	"math"
)

//IsPrimeSqrt checks if the value is prime or not
func IsPrimeSqrt(value int) bool {
	for i := 2; i <= int(math.Floor(math.Sqrt(float64(value)))); i++ {
		if value%i == 0 {
			return false
		}
	}
	return value > 1
}

//LargestPrime Prints the largest Prime factor
func LargestPrime(value int) int {
	a := 1
	var i int
	for i < value/2 {
		if value%a == 0 {
			if IsPrimeSqrt(a) {
				fmt.Println(a)
			}
		}
		i++
		a++
	}
	fmt.Println("The Largest Prime Number is", a)
paste it at one of the paste sites pls if it exceed a few lines :D
i guess its all pasted now :P
what error are you getting
05:32
i dont get error but i am getting weired out put
this reminds me off an Euler problem
it is
fmt.Println("The Largest Prime Number is", a) this line gives me weired output
which it shouldn't
for 13195 that line gives output 6598
and for some reason it doesnt even work when trying to process that large number
if value%a == 0 {
if IsPrimeSqrt(a) {
fmt.Println(a)
}
}
that part does look wrong
okay but that is working correctly
first you can pimp your outter loop by using:
for(int i:=2; i<(value/i);i++){} // no factors would exist beyond value/i for a particular i
then you need a second loop
because how should the prime factors look for a value 12?
var i int is not initiallized but the smallest primenumber is 2 so no need to check for 0 and 1
if value%a == 0 {
if IsPrimeSqrt(a) {
fmt.Println(a)
}
}
walk through this with the number 12
12 = 2x2x3
so the output should be 3
as you can see the number 2 occurs twice in this case but in your case you don't treat that
05:46
ok the above solution also worked and this works as well i see that this is more efficient
i got the solution to euler
but the problem being here is something else
see when i pass like 13195 my output is 5 7 13 29
which is correct but when i try to place another print in main trying to print the largest number by calling the largestPrime function itself
then my output becomes 5 7 13 29 114 now though it should be 5 7 13 29 29
@motaa
ye thats what I get :D
ahh now I get it why this is happening XD
input 12
its because i is iterating 114 times
even though we get the solution at 29
so i need to update the value of a inside if isprime block
thanks @motaa
pastebin.com/2yJiLZdq that is my solution
05:54
wow thats more shorter and cleaner man I seriously need to improve my algorithm stuff i guess euler will help me
@AtharvaPandey the idea is that when you remove all factors of 2 by just dividing the number you also remove any consequtive factors of dividable by 2 like 4,6,8 and so on
*consecutive :D
okay how come fmt.Println(a, " x ", i) prints 5 7
shouldnt it print something like 4 x 3 when doing things for 12
because I want to print out all primefactors finishing with the largest one
no
12 = 2x2x3
12 = 2 x 6 with 6 = 2 x 3 so
12= 2 x 2 x 3
i get it this comes very clean in java
in go it kinda gives me weird things
the idea is that we know the smallest prime number but we don't know the largest one
paste your code
06:08
nvm I got it :P i forgot that go doesnt have while lol
XD
^^
thats y u need to play league
i do play league
kayn
op that new champ :D
ill start playing again tomorrow night
or monday
06:09
i just play it for stress busting
I think i wont play league for a month or two now atleast after 300 euler questions
oh ye lol is never about chilling out :D
haha :D ^ so true
06:34
@motaa how does a/i gives us prime number i dont get the idea
it won't
i is the current primenumber
so we know it is a potential factor
that being the case, we divide our remaining value by the primefactor
so we look for larger factors in the remaining value
by consecutively dividing by a prime factor you remove all following non primefactors that this primefactor is a factor of
like 12
hmm take 18
u divide twice by 2 and therefore remove 4 and 6
18 = 2 x 3 x 3
you divide it by 2 since 18%2 = 0
then you try 9%2 == 0 -> false
so you increment i to 3
9%3 = 0 so we divide
3%3 = 0 so we divide again
06:44
ok for 18 then the output is comming out to be 9 shouldnt it be 3 only
thus the solution you gave stands false for this use case
change this for(int i=2; i<=(a/i); i++){
from a < to a <=
from i < to i <=
cool try 11 :D
it gives 0
it gives me 11
yes nit does if you print a but when you use a <=
then you wont be able to print
System.out.println("largest prime factor: " + a);
you need to change the line with for
to i<=(a/i)
not the if statement
06:53
i didnt
public class test {

    public static void main(String[] args) {
        long a = 18L;
        int b=0;

        for(int i=2;i<=(a/i); i++){                         // no factors would exist beyond a/i for a particular i

            while( a%i == 0){                               // if i is a factor
                a = a/i;                                    // divide a by i else we wont get a prime number
                System.out.print(a + " x " + i + "\n");
                b=i;
            }
the above works good
07:04
@AtharvaPandey I updated my code. This works fine now:
https://paste.ofcode.org/tJYRtM83PirmtpAFPkf3ik
@Dr.Sam Type /help to see all my commands.
@motaa yo seems to be working well and fine
@AtharvaPandey you can even simplify it and remove all the potentialfactor stuff and change the loop to:
while( a%i == 0 && a/i != 1){
so it looks like this:
https://paste.ofcode.org/WGfX87L5gGYv46GazmdnwF
 
3 hours later…
10:08
guys how to execute a program if integer has comma in numbers
eg: maxOccurDigit(3232, 6) returns -1
which value is passed to a function maxOccurDigit(int n)
function has only one int
10:42
I have a Java question, please see this snippet of code: paste.ofcode.org/awQekS6c4EUSLVrGHhDKE6
The question is inside the snippet ^
@simeg What is the type of response?
@MadaraUchiha why does that matter? It's of this class jsoup.org/apidocs/org/jsoup/Connection.Response.html
@simeg That class doesn't have isPresent on it
Did you mean that it's Optional<ThatClass>?
Yes, exactly. You're correct.
Well then, Optional has a method .map() on it
That will apply a function you pass into it onto the object in the optional only if it's present
When in doubt, see the javadoc
I'm actually surprised that Intellij is that intelligent in its refactoring suggestions
That's pretty damn impressive.
I wish the tooling for TypeScript was this hashed out.
10:48
Great. Otherwise return an empty Optional. Straight from the manual, I usually go there but was not sure for this case (RTFM right?). My trust for IntelliJ just keeps increasing. Thanks!
me too indeed :D
My eclipse is not doing that for me :D
@motaa Yes, well, that's because Eclipse is garbage.
That is true ^
My first programming experience was with Eclipse, it left a giant mental scar
@motaa I can really recommend IntelliJ for Java. There's a free version (Community Edition). If you're a student (or an ex-student with access to your student e-mail, like me) you can get the Ultimate Edition for free.
@simeg that is really good to know!
I'll be getting it right away :D
@MadaraUchiha What do you use for writing code?
@motaa Go for it :D
10:54
@simeg Visual Studio Code
he uses sublime text :P
But I write JavaScript/TypeScript mainly
I've heard good things about it, how do you like it?
I liked JS since before TS was good enough to use
And TS takes it to a whole new level for me
It's JS without all the insanity, with added intellisense and magic types I don't need to write
I mean the IDEA
10:55
It's really nice.
@simeg There's nothing better out there for writing Java.
@MadaraUchiha visual studio?
I used to work with TS, it's nice.
@motaa IntelliJ
ah ok
TypeScript with the --strict flag enabled has better type safety than Java does
10:57
jetbrains blocked by my browser... reason: halliburton company haha
(That's not very hard, admittedly, but still)
@MadaraUchiha What does "better safety" mean, in this context?
@simeg You have a stronger guarantee that if things compile they will have the types you thing that they do
(And in general, the typesystem is stronger than Java's, for instance, type inference in generics, you can input any type into generics, including what Java calls "primitives")
And this is not the case with Java, it's not type secure? (I'm fairly new to Java)
I agree @MadaraUchiha I had funny things going on in my LineCharts<Number,Number>
11:11
For example, Java's arrays are covariant, but generics are invariant, meaning that
String[] is subtype of Object[]
Which is rather stupid
String[] arr = new String[2];
arr[0] = "Hello";
doSomethingWith(arr);
System.out.println(arr[1].concat(arr[0]));

// snip

private static void doSomethingWith(Object[] arr) {
  arr[1] = 42; // It's an Object[], anything goes
}
Now I don't remember the syntax 100%, so there might be an error, but the concept is the same
This code compiles, even though arr is of type String[], I've managed to enter an int in there, and the compiler didn't catch it.
I see your point. But what will happen to this code when run? Will it throw an exception putting the integer in the String array?
I'm gonna see if IntelliJ says this is ok.
@simeg It will throw a runtime exception when it finds that concat isn't a method on whatever's found in arr[1].
Yup, IntelliJ is cool with this.
Ok, I see. And TS handles this properly? There's no super duper class that everything inherits from?
TS doesn't have this specific problem, no
It has a similar one though, but if it gets to that, it's on your head
TS has an any type, which is essentually the way out of typechecking
If you give doSomethingWith()'s parameter a type of any[], all bets are off.
But it doesn't have a single type that everyone else are inheriting from.
Right, yeah I remember the any type. You can also expect multiple types with TS right, something like String | Integer | Float?
11:28
Correct
Although TS has only a number type
(Because JS has only one number type, which is equivalent to Java's double)
But yes, the following is possible
const foo: (number | string)[] = [1, 2, "a", "b"];
That looks weird. Are we saying that foo can contain elements with types string AND number or types string OR number?
@simeg It's neither, strictly speaking.
This is a union type
Aha.
It can be said that it's similar to "or" more than it is "and"
But when working with TS, is there a way to enforce that TS is actually used? Because if I remember you can just skip declaring types and you're back in JS world.
11:34
number | string is "a type that implements the interface for either number, or string"
Whereas number & string is "a type that implements both interfaces for number and string"
@simeg Yes
The --noImplicitAny flag (which is part of the --strict flag)
Nice. I see the latest version is 2.4, when I left that company working with that we just bumped our environments to using 1.5.
Good to see Microsoft stepping up for the OS community
@simeg Sure, now that they aren't top of the food chain, all the bad PR is coming back to haunt them
They're trying, I'll give them that.
 
2 hours later…
13:13
isn't there a list will all kinds of events?
13:47
@motaa mdn
@MadaraUchiha mdn?
Google it
@MadaraUchiha the mozilla development network? :D
@motaa That's right
Oh wait
This is the Java room
lol
My bad
:D
finally my linechart axes show time on axis imgur.com/a/fhEy7 :D
14:02
@motaa Minute is an incorrect label for the x-axis.
"Time" would be a better one
true
now 2 things are left
stripping the long term chart of some data
update its upperbound if a value would not fit anymore
and some interactive lines showing stdv, meridian and mean
and a Tooltip :D
how the 2 things have become 4-5 :D
lol did I really write meridian hahaha :D
14:18
@MadaraUchiha Are you sure string[] is a subtype of any[]?
@fredoverflow Yes, arrays in TypeScript are bivariant
The check goes both up and down the type hierarchy
I just tested, TS will have the same problem
class Parent { }
class Child extends Parent {
    foo() {
        console.log(42);
    }
}
class OtherChild extends Parent {
    bar() {
        console.log(43);
    }
 }

const arr: Array<Child> = [];

function doSomethingWith(pArr: Array<Parent>) {
    pArr.push(new OtherChild());
}

doSomethingWith(arr);
arr[0].foo();
No compile errors, but will fail in production.
@MadaraUchiha Are they always bivariant, or is any[] the only case?
Anyway, bivariant arrays sounds like a super-retarded idea...
@fredoverflow Always, see the code I posted above
@fredoverflow I wholeheartedly agree/
But given the nature of JavaScript idioms, I can understand why they took that decision
Although things seem to be shifting towards a saner approach with 2.4
Morning, Java!
Morning, TypeScript!
14:33
Isn't that made by Microsoft? Eww.
@Michael One of the few good things that came out of there, yes.
Truly few.
Omg
Why is Eclipse always changing its name.
Stop trying to be trendy, Eclipse.
Why can't you just use version numbers like a real software product.
4 hours ago, by Madara Uchiha
@motaa Yes, well, that's because Eclipse is garbage.
@MadaraUchiha What about C# and F#?
@fredoverflow I haven't tried F#, but I heard good things about it.
14:41
@Michael IntelliJ IDEA has version numbers...
I'm currently in the process of learning C#, waiting for a chance to use it at work
But I hear C# is almost strictly superior to Java, if you're willing to put up with Windows.
And yes, I know of .NET core, and I also know it's not yet mature enough.
I need a curvesmoothener :D
14:57
@fredoverflow Named after years? I like my versions to be loosely coupled with their release date, thank you.
 
1 hour later…
16:08
2 hours ago, by Madara Uchiha
@Michael One of the few good things that came out of there, yes.
implying typescript is good...
I tried completing a CompletableFuture with an empty optional as a value and it did not complete, but when using null the value gets through. Can't find any documentation about this. Can anyone explain how that works?
Why is not an empty optional a valid value for completing a CompletableFuture? To me it sounds reasonable
what is a CompletableFuture?
16:41
I read up on CompletableFutures some more and I decided to instead use .completeExceptionally() and throw an exception to indicate failure. Seems more reasonable!
@Michael Closer to version numbers than Space-Names though :D
 
5 hours later…
21:40
o/
22:31
Heya
@BrankoIlic Welcome to the Java Chat, the room for Java enthusiasts! Please use a code snippet tool when posting code snippets. If you have an Android question, you're in the wrong place! And remember: this is not tech support! Thanks for visiting and have fun! :D
22:52
Does ANT have its own method of taking care of classpath as opposed to using javac (or Eclipse's JDT) in the command line?
morn
I have a project which is dependent on multiple versions of one library, so 2 versions of the same JARs are in there. The second JAR has additional methods that the older one doesn't. When ANT script runs, it has no problem using the second JAR (even though it comes "after" the old JAR). However, when I use the javac on the command line and reference the two JARs in the class path, it ignores the updated JAR and throws "method is undefined" error.
I assumed ANT would be doing the same thing as just running javac in the command line...
Anyone know how/why Eclipse doesn't have this issue? It seems to automatically pick the "right" JAR when using a method that's available in one JAR but not the other.
23:45
0
Q: ANT classpath order vs Eclipse JDT

DemCodeLinesI am using Eclipse's JDT Core compiler JAR to compile a Java project. However, I am running into JAR issues. The project has two versions of the same jar (A_1.jar and A_2.jar). A_2.jar is a newer version and has additional methods required by the project. I don't have control over the JARs, so I ...


« first day (2458 days earlier)      last day (2707 days later) »