Which Programming Language is Better for Web Development: PHP or Java?

In summary: Java Runtime Engine or the PHP engine. 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.)
  • #1
vprohnitchi
2
0
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
 
Technology news on Phys.org
  • #2
Do you want to program for the web mainly or have the ability to program for desktop and mobile devices?
 
  • #3
As I understand, PHP is for web programming and Java is for desktop and mobile devices? The second one has more future. No?
 
  • #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.
 
  • #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 .
 
  • #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.
 
  • #7
newjerseyrunner said:
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.
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
 
  • #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.
 
  • Like
Likes AliGh
  • #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#
 
  • #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.
 
  • Like
Likes AliGh

1. Which language is more popular for web development, PHP or Java?

Currently, PHP is more widely used for web development compared to Java. However, both languages have a large community of developers and are continuously evolving.

2. Which language is more suitable for building complex and scalable web applications?

Java is generally considered more suitable for building complex and scalable web applications due to its strong object-oriented programming capabilities and robustness.

3. Is PHP or Java more beginner-friendly for learning web development?

PHP is often considered more beginner-friendly for learning web development due to its simpler syntax and easier setup. However, with the right resources and determination, either language can be learned by beginners.

4. Which language is better for integrating with other technologies and databases?

Java is known for its compatibility and ability to integrate with various technologies and databases. However, PHP also has a wide range of libraries and frameworks available for integration.

5. Are there any significant performance differences between PHP and Java?

Java is typically faster and more efficient than PHP due to its compiled nature. However, with advancements in modern PHP frameworks and optimizations, the performance gap is narrowing.

Similar threads

  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
11
Views
2K
  • STEM Career Guidance
Replies
15
Views
2K
Replies
2
Views
882
  • Programming and Computer Science
Replies
18
Views
4K
Replies
27
Views
13K
Back
Top