Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Advise: PHP or Java

Tags:
  1. Oct 13, 2015 #1
    Dear Friends,

    I am new here and I would like to ask you for an advise. I have the opportunity to start a scholarship with a good school with Cambridge International Certificate.

    At this school I have opportunity to choose one of two modules: PHP Web Development or Java Development.

    I worked a lot in Content Management System of different web pages, experience in HTML and CSS and some basic skills in DB architecture.

    Please give me an advise. What is most indicated at this moment and has good perspective for the future.

    Many thanks,
    Victor
     
  2. jcsd
  3. Oct 13, 2015 #2
    Do you want to program for the web mainly or have the ability to program for desktop and mobile devices?
     
  4. Oct 13, 2015 #3
    As I understand, PHP is for web programming and Java is for desktop and mobile devices? The second one has more future. No?
     
  5. Oct 13, 2015 #4
    Don't worry about the future of the languages, both languages will evolve, adapt, and be replaced sometime in your future. You are correct about what each is used for, but both are very flexible languages. If you are a first year student, understanding the concepts of the languages is far more important than the language itself. I can read and write maybe a dozen computer languages, but because I know the basics, I can learn a new one in a day or so if I wanted to.
     
  6. Oct 15, 2015 #5
    Well one is compiled and the other is interpreted . so its a little bit hard to compare them (if you were saying PHP vs ASP then we could)
    Depends on which one you like more . take a look at examples .
     
  7. Oct 15, 2015 #6
    Which do you think is compiled? Neither of these are traditionally compiled languages, but both have compilers. Java runs on something called bytecode, which gets compiled just in time. PHP uses something called opcode, which is also compiled just in time. Both also have true compilers also, (GCJ for Java and HipHop for PHP) but the main draw of both languages is that it works on any machine.
     
  8. Oct 15, 2015 #7
    From what i read something like PHP that does its work on other system and shows results to you is interpreted
    And something like java which runs completely on your system is compiled
    Maybe i didn't understand well
     
  9. Oct 16, 2015 #8
    You are not understanding correctly, both are interpreted languages, java just has an extra step.

    When you run PHP, the PHP engine loads in the php script and starts to parse it. Once it's done parsing it, it creates something called "opcode" this is highly condensed code that provides instructions for the PHP engine. This engine then takes that opcode and converts it to machine code as needed in order to actually run it on the machine. That machine code is also stored for later, so if you run the same piece of code twice in PHP, it only has to interpret it once.

    Java is slightly different in the fact that it does the parsing in a separate step. You can't just write java code and say "ok, go run my code" like you can in PHP. It's still parsed and creates something called "bytecode" which is exactly the same as what opcode is. This gets compiled out into a .class file. Then when you run the .class code, the java engine interprets the bytecode and turns it into machine code as needed. Exactly the same as php does.

    The reason they do this is portability: machine code only works on one machine, but this special in between "opcode" or "bytecode" can run on any machine that has the php or java engine.


    All languages get first changed into something more universal: some sort of bytecode. The difference between the interpreted languages and the compiled ones is that the compilers change everything to machine code. There is no on the fly compilation. This has the advantage of not requiring the Java Runtime Engine or the PHP engine. Once you compile a C program in C, you don't need C anymore. But if you write your code in Java or PHP, you can't remove the engines. The disadvantage to compiled code is that it only works on one architecture (64bit intel machine code will only work on that CPU or something compatible.)

    You can download true compilers for both PHP and Java thought to make pure machine code.



    True compilers have bytecode too, they do that so that they only need to write one compiler. Look at the GNU compilers: C, C++, Fortran, Java... lots and lots of languages. So what they write is parsers for each language. They write a converter from C to GNU bytecode, and another for Fortran to GNU bytecode, then another for Java to GNU bytecode. Then a converter from bytecode to AMD, bytecode to Intel 32, bytecode to Intel 64. See how they've dramatically reduced complexity? Could you imagine if they had to maintain a C -> AMD, C -> Intel 32, C -> Intel 64, Fortran -> AMD, Fortran -> Intel 32.... Bytecode is not new, using it for portability and requiring the end machine to have an engine for it is.
     
  10. Oct 16, 2015 #9
    Thanks .. a little confusing , but got what does it mean
    So i meant the application of two languages is different
    I have worked with both PHP and C#(which is simillar to java)
    PHP was much easier to me , but if i needed to write mathematical programs and things like that , i had to switch to C#
     
  11. Oct 16, 2015 #10
    Yeah, PHP is not meant for math or anything computationally expensive. Compiled programming languages have the advantage of deeply analyzing code and optimizing the hell out of it. Just in time compilers don't have time to do that. Sometimes huge C++ projects using all of the optimization options can take hours and hours to compile. I use PHP for quickly writing scripts or interacting with the hard drive, database, networks... things that are slow anyway. For images, sound, mathematically intensive code, C/C++ and ASM is what I mostly use. I suggest watching a TED talk or o presentation by a compiler developer, the types of optimizations that they do are insane.

    That said, Java is a little better at intensive stuff like that. Most programming languages actually link to other code, that can be written in other languages. For example, you can use OpenGL in Java, OpenGL is written in C. That's why it's so fast, all you need to know how to do is to wrap a header around the library. Java and PHP will never be as fast as natively compiled code that's been fully profiled and optimized, but it can use libraries that were written that way to do intensive stuff.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Advise: PHP or Java
  1. PHP Help ? (Replies: 16)

  2. Php or c++ ? (Replies: 40)

Loading...