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 8 years ago.
Improve this question
I have noticed people speak about AI. My perception of A.I is code written such that a program can learn and simulate human behavior or even write its own code. I want to know if this can be done with java language on an IDE and if so an example code would be nice( code that can write its own code).
This can be done in any general-purpose language; there is nothing inherent to a computer language which would make the resulting program either able or unable to "learn" because learining is a much higher-level concept.
Also note that learning is not exactly a clear-cut concept: any program whose behavior changes based on previous input could be argued to have "learnt" something.
Historically, LISP has been perceived as a language particularly well-suited for AI work, and indeed was the primary language of the AI movement of the '80s. An important reason for this is that it is particularly easy to make a program which writes LISP programs. This not to say that a Java program couldn't be made to do the same; it would just be far less convenient and require much more library support.
What you refer to is called http://en.wikipedia.org/wiki/Self-modifying_code and is not the same as AI. It was often used in the assembler days for performance optimization (for example removing a conditional statement after it is sure it will never be executed again) but I have never seen it used in Java, even thought it surely is possible. See also Self modifying code in Java.
You might want to take a look at machine learning. This branch of AI revolves around systems which learn from data given to them. If you really want to learn, there is a course available on machine learning on coursera.org.
Related
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 6 years ago.
Improve this question
For the past few weeks now I've been studying Concurrency(Multithreading) in Java. I find it difficult and rather different than anything I've encountered in the Java language so far(or in programming in general). Often I have to reread and reread over and over again until I start to understand a small concept fully.
It's frustrating and I've wondered why this part of the Java programming language has given me so much trouble.
Usually when I look at the code of a single-threaded program I look at the main method and start going step by step in my mind through the whole execution(like a debugger). Throughout this process I try to keep in mind EVERYTHING like variables and their states(values) at every point in the execution. Often times when doing that I even stop at certain points and think how the program execution would alter in different scenarios. If I can go through a program from start to finish like that, I feel like I've fully understood the code and the material.
The problem that I have, I suppose, is that when I try to apply this method for a concurrent application, there are so much things happening at once(sleep(), synchronized methods, acquiring intrinsic locks, guarded blocks using wait(), etc.) and there's so much uncertainty of when something will execute, that it becomes nearly impossible for me to keep up with everything. That's what frustrates me, because I want to have a feeling of "I have control over what's happening", but with concurrency that's impossible.
Any help would be appreciated!!!
Concurrency is a simple concept, really - you have several separate paths of execution, which can interact with each other. The stuff you mentioned, like syncing, blocks, waits and so on are technical details, tools.
I would suggest trying to do some coding :-) Come up with a multi-thread program idea and code it. At some point you will need to use one of the tools you listed and it will all begin to fall into place. This is NOT a concept you should to understand only in theory ^^
More over a Science, Concurrent Programming is an art.
Before going into Java concurrency, PLEASE DO go through the conceptual things first.. i.e. what are the major problems in concurrency? what is a lock? what is a semaphore? what is a barrier? why we are using those? how can we use them for different purpose like variable protection, synchronization etc.? Likewise there are some.
Then you would probably get some very important knowledge before getting into language specific usage.
For a person who have followed sequential programming all the time and first looking at concurrency, definitely it would be harder to understand those things at once. But I am sure you can go to the level that you are in sequential programming for concurrent programming also after some time. :))
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
First of all, I love Python, and I currently use it for most stuff. However, as a PhD student, I mostly implement prototypes for testing and evaluating ideas. This also includes that I'm usually the only one coding, and that -- while I certainly try to write half-way efficient code -- performance is not a primary issue. And for quick prototyping, Python is for me just neat.
Now I consider to go with some of my stuff more "serious", i.e., to bring it into a productive environment, make it better maintainable, and maybe more efficient. So I wonder if it's worthy to rewrite my code to, say, Java (with which I'm also reasonably familiar). I know that Python is not slow, but things like Java's static typing including seems to make it less prone to errors on a larger scale, particularly when different people work on the same project.
It's only worth it if it solves a real problem, note, that problem could be
I want to learn something better
I need it to go faster to reduce power requirements in my colo.
I need to hire more people and the talent pool for [insert language here]
is too small.
Insert innumerable real problems here.
Python and Java are both suitable for production. Write it in whatever makes it easiest to solve the problems you and or your team are facing and if you want to preempt some problems make sure you've done your homework. Plenty of projects have died because they chose C/C++ believing performance was going to be a major factor without thinking about the extra effort involved in using these language well.
You mentioned maintainability. You're likely to require more code to rewrite it in Java and there's a direct correlation between Bugs and LOC. It's up for debate which one is easier to maintain. I'm sure both camps believe theirs is.
Of the two which one do you enjoy coding with the most?
The crucial question is this one: "Java's static typing including seems to make it less prone to errors on a larger scale". The crucial word here is "seems." Sure, Java will help you catch this one particular type of error. But how important is that, and what do you have to pay for it? The overhead imposed by Java's type system means that you have to write more lines of code, which means reduced productivity. I've used both and I have no doubt that I'm more productive in Python. I have found that type-related bugs in Python are generally easy to find and fix. Keep in mind that in a professional environment you're not going to ship code without testing it pretty carefully. The bottom line for a programming environment is productivity - usable functionality per unit of effort, not the number of bugs you found and fixed during development.
My advice: if you have a working project written in Python, don't rewrite it unless you're certain there's a benefit.
Java is inherently object oriented. Alternatively python is procedural.
As far as the ability of the language to handle large projects you can make do with either.
As far as producing more usable products I would recommend java script as opposed to java because of its viability in the browser. By embedding your js in a publicly hosted website you allow people with no coding knowledge to run your project seamlessly in the browser.
Further more all the GUI design features of HTML are available at your disposal.
That said any language has it's ups and downs and anything I've said here is simply my perception.
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 8 years ago.
Improve this question
I am tasked with coding up an enterprise level eCommerce setup. I know PHP, C#, VB.NET, C++.
I have reviewed a variety of benchmarks in respect to speed performance online and obviously the results are as expected, C++ hands down, C# and Java close enough its immaterial and PHP a strong last place.
I have been learning Java, not too different from C/C++ after all.
I have viewed some memory usage benchmarks related to both C# (ASP.NET) and Java (operating system stuff aside).
However, everything I have located trends towards the more simple scaler variables and normal "any language" constructs. What I am interested in are memory and even speed performance benchmarks comparing complex objects. Cant seem find a thing that is not biased.
I am not interested in the "I like this better or that better", thats simple preference.
I am interested in more concrete data as throughput and memory usage equate to server load and sessions serviced.
Thanks in advance.
If you want to write fast and memory efficient code, then you should just write your code in this way. Software platform overhead is pretty low in Java and in .NET.
.NET JIT compiles code to native instructions, and most JAVA JIT's do the same thing.
I'm sure that benchmarks you reviewed is very synthetic - they just compare time of application cold-start(which is useless metric). Yes, software platforms that use JIT-compilation will lose there - because they need time to analyse and compile bytecode to native. In most situations, you can write applications with same or even better overall performance and memory usage than when using similar C++ code.
Just use language that you(and also your team!) like more.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I've done a lot with IO in Java and after looking for code to convert primitives to byte arrays and back I found source for java.io.Bits on one of the Java source code hosting websites. After a quick glance I realized it's exactly what I need, except it's package-private. So I made a copy which I made public, stored in my project's package and used (only in personal projects, I assure you). I find it very useful.
My question is, why is this package-private? I can see it being really useful for people who work with IO and I see no disadvantage from changing it's visibility to public (in rt.jar). Or is there perhaps an equivalent (and please don't mention other libraries)?
Here's a link to a randomly chosen website that has Java source for java.io.Bits: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/Bits.java
You'd have to ask one of the Java devs for sure, but by making it package private, the API can be treated as "internal" - i.e. it might change or disappear at any time. This means the API can be developed relatively quickly, and doesn't need to go through the same relatively thorough testing process that public APIs need to go through (since once they're released, they're stuck there for good.)
In short, making an API public has long term implications, and it requires much, much more work than just hitting a switch.
I would hazard a guess it started life as a "hacked together" group of functions useful for a few other classes in the IO package, and has just stayed there ever since.
It's package-private, sure, but there are public APIs that expose the same behavior, e.g. ByteBuffer.wrap(array).getInt(index) and the other methods on ByteBuffer. You're almost certainly better off using that properly designed, well-documented public API than trying to wrap or copy internal implementation details from Java.
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 9 years ago.
Improve this question
For example, say I had the string
hunger > 80 then findFood();
or
distanceTo sun < 30 then moveAwayFrom(sun);
That's not the exact syntax of what I want, but does anyone know a simple way I could make it so that I can pass that onto an entity in a game and they will basically follow that? The only thing that spring to mind at the moment is making a huge block of if statements that parse the given string, but that feels really really ineffecient.
I'd like a second opinion, just to see if I'm overlooking something really simple here :/
Not an easy task! What you are basically saying is that you need to create a language.
This language will describe all possible commands which you will then parse and generate commands from.
Now you might be thinking to yourself "gee, I've never written a language before!". That's where ANTLR comes in. It allows you to write the grammar for your language, and then generate the parser/lexer that you will need to decode the commands. You can get an IDE for working with ANTLER called ANTLRWorks, and you should check out the getting started tutorial. You really will have to get over your "curse" of trouble with wiki pages and dive in here.
Along the way you will probably realize easier or more efficient ways to encode your commands so that you can later decode them. Some possible alternatives are embedding a scripting language which you will use to encode/decode the commands, such as Python, JavaScript, or Lua. I have seen Lua used in games before, you can read their statement on why they are popular in games here. Good luck!