|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
I believe you mix up pointers and references. In Java there are no pointers or out parameters or whatever you may call them in your language. In Java, you cannot change the "thing behind a variable"* of a variable outside of your method by design. This does not mean, that every object gets copied each time you assign it to a variable or parameter.
Example: In your java example, you declare a new local variable called "t" and assign it the reference of the object behind the parameter b. After that you try to assign to parameter "b" the reference of the object behind the parameter "a".
If you would have run your code through a compiler, you would have noticed your thought process is not quite right, because you cannot assing something to a parameter. In order to declare a local variable you would need to also write the type of your new "a".**
Sorry if I am not communicating this very clearly, at the moment. It's 3am here and I am barely accountable anymore. :D I'm pretty sure about java pass-by-reference and pass-by-value mechanics, though. And they simply have nothing to do with C++.
* I don't want to use the word value here for clarification
** I'm not quite sure about this. Maybe they changed this, even though I cannot imagine that. I stopped at Java6, though. Either you get a compile error or the compiler creates a new local variable named "b", which then shadows the parameter. But never will the reference behind the parameter "b" be changed.
Cheers and good night!
Update: To translate between java and c++: Java has call-by-reference for complexe types. The reference is just not writable, ok? :D (The object behind the reference is writable, of course. Hell were are we? In a bloody functional language, pff! )
|
Nesserev is mostly right, and AKnopf is just confusing things further. While Nesserev's code won't compile + Show Spoiler [adding confusion] +(unless he has a class called X, or his Swapper has generic type X) , the example is clear enough. Substitute for X whatever real type you want (int, Object), and it'll work the way he says.
The main reason AKnopf is confusing stuff further is:
In Java, you cannot change the "thing behind a variable"* of a variable outside of your method by design
Which is true, but you have to unpack the sentence quite carefully to not just miss "outside your method": in Java, the following two pieces of code do not do the same thing:
public static void swap(X a, X b) { X t = a; a = b; b = t; }
public static void main(String[] args) { X a = ...; X b = ...; swap(a,b) // does nothing }
public static void main(String[] args) { X a = ...; X b = ...; X t = a; a = b; b = t; // a and b are swapped }
You see, it's easy to change the value of variables, but you have to understand the scope of those variables. Within the scope of the swap method in the first example, a and b were swapped. It's just that because Java passes by value that that has no effect on the outer scope.
Moreover, the following code does work:
public static void swap(SwapObject so) { X t = so.a; so.a = so.b; so.b = t; }
public static void main(String[] args) { SwapObject so = new SwapObject(); so.a = ...; so.b = ...; swap(so); }
Although it's horrible code with public fields and much confusion. The reason this works is because you can change the values within the object you are pointing to (Java has pointers, not references, to objects), because the scope there is the same: both swap and main methods have different pointers (passed by value), but they point to the same SwapObject object.
And if Travis is now horribly confused, he should forget everything Nesserev, AKnopf and I said, and read this instead:
http://javadude.com/articles/passbyvalue.htm
|
On November 14 2016 17:10 Acrofales wrote:manit0u is mostly right, and AKnopf is just confusing things further. While manitou's code won't compile + Show Spoiler [adding confusion] +(unless he has a class called X, or his Swapper has generic type X) , the example is clear enough. Substitute for X whatever real type you want (int, Object), and it'll work the way he says.
I believe you confused me with Nesserv there for a moment since I haven't posted any code pertaining to the discussion at hand 
|
On November 14 2016 17:36 Manit0u wrote:Show nested quote +On November 14 2016 17:10 Acrofales wrote:manit0u is mostly right, and AKnopf is just confusing things further. While manitou's code won't compile + Show Spoiler [adding confusion] +(unless he has a class called X, or his Swapper has generic type X) , the example is clear enough. Substitute for X whatever real type you want (int, Object), and it'll work the way he says. I believe you confused me with Nesserv there for a moment since I haven't posted any code pertaining to the discussion at hand  Whoops. Fixing that!
|
Could someone help me a bit with running Java on Debian?
I'm constantly getting this error:
java.lang.UnsupportedClassVersionError: org/scalatra/servlet/ScalatraListener : Unsupported major.minor version 52.0
This would indicate that it's trying to run it in JSE8, but I've the default Java to JSE7:
$ java -version java version "1.7.0_111" OpenJDK Runtime Environment (IcedTea 2.6.7) (7u111-2.6.7-2~deb8u1) OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)
$ javac -version javac 1.7.0_111
Any ideas?
Or does it mean that I should run it in JSE8? It's so conusing...
Edit: + Show Spoiler [full error] + $ ./sbt Detected sbt version 0.13.13 Starting sbt: invoke with -help for other options Using /home/kkarski/.sbt/0.13.13 as sbt dir, -sbt-dir to override. [info] Loading project definition from /home/kkarski/workspace/scala/document-management-system/project [info] Set current project to Document Management System (in build file:/home/kkarski/workspace/scala/document-management-system/) > jetty:start [info] Compiling Templates in Template Directory: /home/kkarski/workspace/scala/document-management-system/src/main/webapp/WEB-INF/templates SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See [url=http://www.slf4j.org/codes.html#StaticLoggerBinder]http://www.slf4j.org/codes.html#StaticLoggerBinder[/url] for further details. [info] starting server ... [success] Total time: 1 s, completed Nov 15, 2016 11:33:25 AM > 2016-11-15 11:33:25.600:INFO::main: Logging initialized @67ms 2016-11-15 11:33:25.607:INFO:oejr.Runner:main: Runner 2016-11-15 11:33:25.712:INFO:oejs.Server:main: jetty-9.2.1.v20140609 2016-11-15 11:33:28.733:WARN:oeja.AnnotationConfiguration:main: ServletContainerInitializers: detected. Class hierarchy: empty 2016-11-15 11:33:28.747:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@6baa6838{/,file:/home/kkarski/workspace/scala/document-management-system/target/webapp/,STARTING}{file:/home/kkarski/workspace/scala/document-management-system/target/webapp/} java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.visit(IterativeDescriptorProcessor.java:85) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.process(IterativeDescriptorProcessor.java:72) at org.eclipse.jetty.webapp.MetaData.resolve(MetaData.java:394) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1332) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:744) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:154) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) at org.eclipse.jetty.server.Server.start(Server.java:357) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.server.Server.doStart(Server.java:324) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.runner.Runner.run(Runner.java:509) at org.eclipse.jetty.runner.Runner.main(Runner.java:557) Caused by: java.lang.UnsupportedClassVersionError: org/scalatra/servlet/ScalatraListener : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:803) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at org.eclipse.jetty.webapp.WebAppClassLoader.findClass(WebAppClassLoader.java:482) at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:440) at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:402) at org.eclipse.jetty.server.handler.ContextHandler.loadClass(ContextHandler.java:1568) at org.eclipse.jetty.webapp.StandardDescriptorProcessor.visitListener(StandardDescriptorProcessor.java:1935) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.visit(IterativeDescriptorProcessor.java:85) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.process(IterativeDescriptorProcessor.java:72) at org.eclipse.jetty.webapp.MetaData.resolve(MetaData.java:394) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1332) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:744) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:154) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) at org.eclipse.jetty.server.Server.start(Server.java:357) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.server.Server.doStart(Server.java:324) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.runner.Runner.run(Runner.java:509) at org.eclipse.jetty.runner.Runner.main(Runner.java:557) 2016-11-15 11:33:28.754:WARN:oejsh.RequestLogHandler:main: !RequestLog 2016-11-15 11:33:28.768:INFO:oejs.ServerConnector:main: Started ServerConnector@7171ff47{HTTP/1.1}{0.0.0.0:8080} 2016-11-15 11:33:28.768:INFO:oejs.Server:main: Started @3265ms [info] waiting for server to shut down...
|
I think this error means your java application was compiled with version 8 and you try it in a JRE with a lower version. But I am not 100% certain because I never really tried to do that.
My tip: Just google the error message. You will most likely find an answer on StackOverflow.
|
On November 15 2016 19:36 RoomOfMush wrote: I think this error means your java application was compiled with version 8 and you try it in a JRE with a lower version. But I am not 100% certain because I never really tried to do that.
My tip: Just google the error message. You will most likely find an answer on StackOverflow.
Already tried that. Nothing really helped me
|
Have you tried using Oracle's JRE? Most compatibility issues have been fixed, but there probably are still some floating around.
Also the compiler is not backward compatible. You should use the Java 8 JRE if your bytecode was generated with the java 8 compiler.
|
Scala requires jvm 8 since 2.12
|
On November 15 2016 20:57 Hanh wrote: Scala requires jvm 8 since 2.12
I've had scala 2.9 at the time of posting. Upgraded to 2.11.8 (highest I can go now), but it didn't help.
Edit: Developing web apps in the java environment feels like shooting yourself in the foot before the race even begins
|
It's the other way round. Scala requires jvm 8, so either downgrade scala or upgrade jvm.
|
In the spirit of my previous NetBeans-rants, I will share another gem with you, this time while using it for Java: Despite everything being installed and set up correctly, NetBeans keeps insisting that it can't find the hibernate-jars. I checked the path in the error message where NetBeans claims to be unable to find the jars, only to see all of them being there. So I delete the jar file. Now NetBeans claims it can't find another jar. End of the story, deleting all jars in that folder "fixed" it. "Fixed" because now, NetBeans gives a warning for my project, since all those required jars are missing but compiles and runs fine. At this point, NetBeans becomes more of a religion than an actual IDE since the only way to have a good experience with it is to stop rationalising and to start believing.
Java-parenting: If your kid can’t find a toy in his room that is clearly there, just throw it away and suddenly, your child will magically be able to play with it, without any trouble to find it. Wait, have I just said that NetBeans has hallucinations strong enough to bend reality?
|
Hyrule18968 Posts
On other tech related issues, docker compose randomly decided it didn't want to find my Dockerfile and this it crashed. But only after hanging for 4 minutes. Nothing I found fixed it, I ended up having to trash the entire local repo and reclone it.
|
On November 15 2016 21:45 Hanh wrote: It's the other way round. Scala requires jvm 8, so either downgrade scala or upgrade jvm.
Odd. JVM8 support is marked as experimental in Scala 2.11...
|
Did you compile scalatra yourself?
|
Hyrule18968 Posts
docker is throwing me other curveballs now
php_1 | 172.18.0.3 - 15/Nov/2016:16:26:54 +0000 "GET /app_dev.php" 200 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:54 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:55 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:54 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:55 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:55 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:55 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:55 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:55 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:26:55 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:27:00 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:27:00 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:27:01 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:27:06 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:27:06 +0000 "GET /app_dev.php" 404 php_1 | 172.18.0.3 - 15/Nov/2016:16:27:07 +0000 "GET /app_dev.php" 200
that's ONE REQUEST
what the hell
|
On November 16 2016 00:46 Hanh wrote: Did you compile scalatra yourself?
I'm following the tutorial on their website. Conscript -> g8 -> scalatra/scalatra-sbt
|
anyone do react-native development? i'm not sure about best practices (like always apparently -_-). i wish there didnt seem to be like 50 ways to do everything...
|
Pretty much like reactjs. I like redux.
|
Does anyone have any insight on possible RoR developer interview questions?
I'm applying for a new job, trying to move from PHP to RoR but my RoR knowledge is pretty basic (but I have plenty of general experience in web dev).
|
|
|
|