Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
During 3 years of my working career, I have been working with databases, data, etc. It was only during the last year that I started working with Python for some data analysis. Now i got interested in all the Big Data ecosystem and Python gets me far enough, yet.
However, recently I chose to learn Scala as my second programming language. It appears that usually my program needs to have a class, a method, and then it needs to be built. It is all very confusing to be honest :)
So I read on and it appears that Scala comes from JVM environment, and I started reading on Java and it turns out that in Java you cannot just create a program consisting of a single command. You need to create a class, a method, etc. I understand that it is probably because it follows one of the principles of OOP, but could anyone please direct me to the source, which would explain why do we need to create classes and methods in java - as opposed to listing commands only?
So I read on and it appears that Scala comes from JVM environment, and I started reading on Java and it turns out that in Java you cannot just create a program consisting of a single command. You need to create a class, a method, etc. I understand that it is probably because it follows one of the principles of OOP
First, let me briefly explain why Python does not requires you to create a class or something similar in order to run it.
Python is designed as an interpreted language (or you can call it script). The instructions you wrote are series of operating system commands handled by the command interpreter. So what is a command interpreter?
Command interpreter is part of the OS which executes commands entered by you. In some OS, it is known as a shell.
Java on the other hand is a designed as a compiled language which needs to be compiled by a language compiler. The language compiler converts your source codes into machine language so that you processor can work on it.
In my opinion, it is not really about OOP in Java. It is what they are which made the difference - to be compiled vs to be interpreted.
If you are just wondering why Java codes need a class, it has been asked before in SO:
Why do C# and Java require everything to be in a class?
Scala is made because of this. It mixes functional and OOP language features, so you can create methods by themselves, without creating a class to contain them.
Java doesn't have this feature, methods can't be created outside a class. Java is very object oriented, everything (except the primitives) extends object.
Some people say, that this is like this, because java is garbage collected. Having functions inside objects makes it easier, to free space up.
It really depends on you, if you find this good or not. In my opinion, it's better to get as far from functional programming, as possible. Let's not get back to the C era.
Java is an object-oriented (OO) language. Classes are objects, one of the basic building blocks of this language. Inside the classes, you have methods, containing the "commands" you are speaking of.
I suggest you refer to literature on that topic - there is a vast amount of books outlining OO principles and the differences between different types of languages (OO, functional, procedural, etc.).
All in all, wikipedia might be a good starting point - see the list of main paradigm approaches here:
https://en.wikipedia.org/wiki/Comparison_of_programming_paradigms#Main_paradigm_approaches
P.S.: As I'm unsure what exactly your question is about, I have to add that of course, Python is an OO language too. That you can run Python code without creating a class first, is a design choice.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I'm fully aware that a similar question was already asked here: Generating LLVM Code from Java
The thing is, that was in 2012...I looked at the solutions and found most of the projects mentioned abandoned or at least very inactive.
So, as someone who is most used to working with Java, what would be my options for working with LLVM (to create a toy language, not using clang or anything)?
Try to use one of those projects, even if the might be outdated? Sounds like a bad idea.
Learn C/C++? Don't get me wrong, I already have a C++-book lying around and I don't say it's a bad language, but I highly doubt I would feel comfortable working with it.
Use bindings for other languages, like Haskell, Python, etc.? I might prefer that over C/C++, but that would mean to learn another complete language before getting started...
Write my own bindings? I never did anything like that,I would not even know the difference between JNI, JNA and whatnot...but might be interesting to learn.
Try to format LLVM IR in text form? Might work, but is probably not the best idea either.
Just to finally answer this, Java C++ Presets are a useful and mostly-upto-date option for this: https://github.com/bytedeco/javacpp-presets/tree/master/llvm
I came across the same problem recently since I'm using ANTLR in Java/Scala to define my lexer and parser and LLVM to generate the actual machine code through its IR.
In trying to bind JVM-based front-end to LLVM IR and back-end I am actually trying to use GraalVM https://www.graalvm.org/ since it offers a seamless way to interact across languages, including the LLVM bitcode, using its Polyglot.
Here some references:
https://www.graalvm.org/docs/reference-manual/languages/llvm/
https://medium.com/graalvm/graalvm-llvm-toolchain-f606f995bf
https://blog.plan99.net/graal-truffle-134d8f28fb69
You should be able to access LLVM IR directly from your Java/Scala code or vice versa, you could access your AST in JVM-based language from LLVM/C++ code using Polyglot calls.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a query in which I cannot give a satisfactory answer. Java is notorious for its independence over machine architectures grace to JVM. I 've understood the following:
Different JVM implementations are sitting on different machines as to produce the appropriate output (different for any different architecture) from the same input(.class files).
Let's now consider C++. Why not to do the same with Java? Namely, implement different C++ compiler versions for different architectures, feed them with the same source and make every compiler produce the appropriate output; just make C++ compiler to mimic JVM!
This is my query since I cannot understand why Java is unique in that...
The C++ compiler already does that. The difference is that whereas class files are interpreted by the JVM, C++ applications aren't (usually) distributed as source files.
This of course also requires that you use standard libraries which are available for all the platforms. There's nothing very magical here. You have compiled languages such as C++, partially compiled like Java and interpreted such as Ruby.
As far as I know this is exactly what happens (as Kayaman said). You write one source, and compile it for different platforms, for example gcc/mingw or visual for Windows, gcc for Linux etc.
The difference between C/C++ and Java is that from C and C++ it is much easier to do direct system calls, to directly work with the filesystem, with sound devices etc. These system calls will differ for each system, which is what makes the code not portable. This means that portability for C++ code is the choice of the programmer.
Because if you do that you have Java. If C++ doesn't have a direct connection with the low level resources than lots of advantages of this language disappear. It's kind of the same thing with C++ and assembling language. Creating a more high-level language will have a negative effect on the control of the machine's resources.
Read this about Java: Java Architecture
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have a Java program which gets data from a database in the form of a list of objects and an object just has some primitive types associated to it like strings and ints.
Now I need to pass the data from Java to a Python program to do some calculations and then return the calculated output to the Java program.
My Python program has the following imports
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
import numpy as np
import scipy.misc as sp
from scipy.optimize import minimize
from scipy.stats import poisson
Does anyone have any ideas for how I could achieve this? I looked at Jython but saw that it isn't compatible with NumPy and others but there is a compatibility layer available called JyNI however I can't find many examples to getting a working solution.
EDIT: From my research, there doesn't seem to be a suitable library which will handle communication between Java and Python but would it be possible to the Java program to start a Python script which looks for say a JSON file containing the data it needs for processing and then prints an output that Java can pick up?
I am of the opinion, that you stand to have several choices; my personal favourites are as follows:
I'm not too sure why you are trying to speak between Python and Java, so I'd like to make the first point of staying away from such things, if at all possible. I understand that there are some things that simply cannot be done in a language, certain libraries that are hard to find/emulate in another language, etc.; but, one will find it often simply to be less of a hassle to work in one language to complete the whole of the task. That being said, if you still feel that you wish you use both languages, I will not stop you, since you probably have a good reason.
If you have chosen to continue, then, let me provide you with a quick few ideas that might help in circumventing this issue. Albeit it's true that Jython is incompatible with NumPy, there are other libraries that may accomplish your task similarly. A few examples: DataMelt (a JVM language family friendly way to do graphing, but also has very strong math capabilities); EJML (a great thing for working with big matrices, and it's open source :D); and ND4J (a Java library very similar to NumPy).
Finally, if you find difficulty in the above, or you simply choose to not use it, there is always the option of abstraction. I say this, in the sense that one can always choose to move around which tasks are done where: this is applicable to you, in that you could move some of the calculations and processes around, so that Java does more of the work, minimizing the things you actually would need to send, to a few simple structures that could be conveyed either by a scripting language in the JVM family, (like Rhino, a JavaScript derivative, etc.), or by using something like Jacl to have LAN connection through TCP, and to broadcast one program's results to another, through I/O methods.
There are probably many other little workarounds and solutions that people have come up with in the past (native embeddings, higher level control, etc.), but these are my best offers to you, as they cause the least trouble (as far as I am aware). I hope this answers your question, and best of luck to you.
A short list of maths libraries useful in Java.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I'm versed in Java, and starting to experiment with Groovy.
Because the two are integrated so well, I find myself writing in Java whatever I can because it's so easy. What specific tips can you offer that would speedup my work with Groovy?
Meaning - in what areas do groovy excel over java, and where should I stick to Java?
Some of the main things I like groovy for:
testing is probably the biggest win. The ability to change behavior at runtime and mock out methods is one of the greatest things about groovy. Convert your test suites to groovy now!
use the builders. Groovy builders have so much more expressiveness than traditional java. In particular, the MarkupBuilder for embedded snippets of XML or HTML is 1000s of times nicer to use than vanilla java
GPars if you're doing any sort of concurrent programming or threading
Also see Hidden features of Groovy and Why would one use Groovy over Java (note: was "removed from Stack Overflow for reasons of moderation").
Where I'd stick with java:
any place where speed really matters, stick with java. You still pay a high cost in performance for groovy's dynamic nature.
The problem with Groovy.
Groovy is a write-easy, but maintenance-nightmare. In my opinion, it should not be used in large projects. Inheriting somebody else's (or your own) code can be problematic, because very often you have no clue of the type of a variable, so you have your due diligence to find out, or use assertions to guarantee the incoming type to a method.
Groovy is a weak-typed language. The type of a variable is frequently ignored, or "conveniently" cast automatically, which leads to many bugs and slower performance.
Even the bests IDE's are lacking, because the practically typeless variables of the language. In many cases the compile just can't know what is the type of a variable. Even if you declare the type of a variable (which helps the editor to make suggestions), many programmers forget to define the variables type.
It has interesting ideas that I would love to see in Java, but stay away from it if your Groovy code will require more than a thousand lines.
* The answers in a nutshell *
Summarizing, here are the answers to both questions:
What specific tips can you offer that
would speedup my work with Groovy?
Use it only for small stuff. Otherwise, you will incur in technical-debt (see the Wikipedia). So far I'm in similar situation. Unit testing, using the console to test pieces of code, etc., are things that will speed up your development, since it's so easy to learn and use. Be sure to master closures, collections, and looping, and to understand what Java features are not available in Groovy.
Don't use pure Groovy for complex or large applications. In the long term the maintenance will slow you down.
Meaning - in what areas do groovy
excel over java, and where should I
stick to Java?
In a large or critical project you need to keep yourself disciplined and use dependable tools. It's like building a house: I are build a doll house, Groovy is fine :-) ... if it's not perfect, it's no biggie. If you build your own house or something bigger with little tolerance for error, you need to use quality tools and materials of better quality that don't let you oversee potential problems (Java, for example).
In any case, Groovy is like duck tape: some here and there may do no harm.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What is the difference between Java and C++? Are both object-oriented?
This is far too general a question to be answered here.
Java is an explicitly object-oriented language, with the harder-to-use bits snipped off.
C++ is a multi-paradigm language with the safety off. You can do object-oriented programming in it, as well as procedural and generic.
If you had a more specific question, we could be of more help. Why did you ask? If you want recommendations for a particular platform, or project, or whatever, we could be more responsive.
A C++ programmer will tell you that Java is rubbish. A Java programmer will tell you that C++ is rubbish. Therefore I conclude that they are indeed the same thing.
Each language designed with different purposes in mind, so IMO it's not fair to compare the two from one perspective, and ignore the other.
Generally speaking, C++ is an open standard, designed for implementing high performance systems where speed and performance and critical, there are lots of impressing projects designed using this language like Phoenix Lander, Adobe Acrobat Reader and others. C++ gives the developer the ability to program using a very high level abstraction -using generics for example, and, when needed, go down deep to the bare metal of the machine -to handle an interrupt for instance.
Java was designed with other purposes in mind, when Sun was planning Oak (later called Java), it focused on web applications so it supported the language with a bunch of heavy libraries of easy-to-use interfaces considering that. and portability (Compile once, run anywhere) using JVM, which prevents the programmer from coding to specific machine, but instead coding to a sandbox which in turn runs the code on the hosting machine, and this has obviously negative reflections on performance/speed.
Comparison of those two language is a popular cause of debate between programmers, and this is due to their different working demands and nature, IMO every language has made mistakes in order to mature, for example, C++'s exported templates, and Java's lack of procedural programming (Big Mistake). plus, each one has its pros and cons regarding different aspects, hence the one that balance productivity/performance issue IS the right language.
For more information Wikipedia's comprehensive article on Comparison of Java and C++
It might be interesting to take a look at what languages are used (and being used) to create major systems (like Google) from here.
One of the most important differences hasn't been mentioned yet - one is compiled to machine code, the other is compiled to bytecode which is interpreted by a virtual machine.
Everything is Object in Java as everything is derived from java.lang.Object But this is not the case in C++
No pointers in Java whereas C++ has provide support for pointers
No destructors in java (Java has automatic garbage collection) but C++ has destructors to do that
Thread support is built in Java but not in C++
No scope resolution operator in Java
No Goto statement in Java
No Multiple Inheritance allowed in Java but C++ allows that
No operator overloading is allowed in Java but C++ allows that
Java is interpreted for most part and hence Platform independent
Both are object oriented but they are very different languages. This probably isn't the best forum to ask for the differences... I would suggest you look both up on Wikipedia and review the descriptions there. You will be able to see the differences very quickly for yourself.
I love c++ but unless you absolutely need to use c++ then use something else. When you need to use c++ then you will know the difference, Grasshopper.
(hint do not write device drivers, video decoders, encryption libraries, 3-d graphics engines or language run-time engines in java).
Yes, both are object oriented programming languages.
C++ is an evolution to C. Which was a system programming language. C++ Added many features to the language to make it object oriented. It became the mainstream programming language for that reason.
Java is an evolution of C++, with different goals ( cross platform for instance ). It remove some of the features that make C++ so hard to learn. Simplify others and remove others.
The main difference is C++ programs are compiled directly to machine code ( understood by the CPU ) while Java programs are compiled to be run in a "Virtual Machine" the JVM most of the cases. For these reasons java programs were interpreted by another program and at the beginning were veeeery slow programs. Nowadays the VM may optimize this code and make it run very very fast.
See this link.http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html
Gross but accurate oversimplification: Java is easier. C++ is faster.
Just a quick addition to what David Thornley posted. C++ is a procedural language that supports Objects and OO design. Java is pure OO. Java does less but on more.