Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 96441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:48:55+00:00 2026-05-10T23:48:55+00:00

What are the main differences between PHP and Java that someone proficient in PHP

  • 0

What are the main differences between PHP and Java that someone proficient in PHP but learning Java should know about?

Edit: I mean differences in the syntax of the languages, i.e their data types, how they handle arrays & reference variables, and so forth 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:48:56+00:00Added an answer on May 10, 2026 at 11:48 pm

    Not an exhaustive list, and I’m PHP developer who did a tour of Java a while back so Caveat Emptor.

    Every variable in Java needs to be prepended with a data type. This includes primitive types such as boolean, int, double and char, as well as Object data-types, such as ArrayList, String, and your own objects

    int  foo    = 36; char bar    = 'b'; double baz  = 3.14; String speech = 'We hold these truths ...'; MyWidget widget = new MyWidget(foo,bar,baz,speech); 

    Every variable can only hold a value of its type. Using the above declarations, the following is not valid

    foo = baz 

    Equality on objects (not on primitive types) checks for object identity. So the following un-intuitively prints false. Strings have an equality method to handle this.

    //see comments for more information on what happens  //if you use this syntax to declare your strings //String v1 = 'foo'; //String v2 = 'foo';  String v1 = new String('foo'); String v2 = new String('foo');  if(v1 == v2){     println('True'); } else{     println('False'); } 

    Arrays are your classic C arrays. Can only hold variables of one particular type, need to be created with a fixed length


    To get around this, there’s a series of collection Objects, one of which is named ArrayList that will act more like PHP arrays (although the holds one type business is still true). You don’t get the array like syntax, all manipulation is done through methods

    //creates an array list of strings ArrayList<String> myArr = new ArrayList<String>(); myArr.add('My First Item');  

    ArrayLists still have numeric keys. There’s another collection called HashMap that will give you a dictionary (or associative array, if you went to school in the 90s) like object.


    ArrayLists and other collections are implemented with something called generics (the <String>). I am not a Java programmer, so all I understand about Generics is they describe the type of thing an Object will operate on. There is much more going on there.


    Java has no pointers. However, all Objects are actually references, similar to PHP 5, dissimilar to PHP 4. I don’t think Java has the (depreciated) PHP &reference &syntax.


    All method parameters are passed by value in Java. However, since all Objects are actually references, you’re passing the value of the reference when you pass an object. This means if you manipulate an object passed into a method, the manipulations will stick. However, if you try something like this, you won’t get the result you expect

    public void swapThatWontWork(String v1, String v2) {   String temp = var1;   var1 = var2;   var2 = temp; } 

    It’s as good a time as any to mention that methods need to have their return type specified, and bad things will happen if an method returns something it’s not supposed to. The following method returns an int

    public int fooBarBax(int v1){ } 

    If a method is going to throw an exception, you have to declare it as such, or the compiler won’t have anything to do with it.

    public int fooBarBax(int v1) throws SomeException,AnotherException{    ... } 

    This can get tricky if you’re using objects you haven’t written in your method that might throw an exception.


    You main code entry point in Java will be a method to a class, as opposed to PHPs main global entry point


    Variable names in Java do not start with a sigil ($), although I think they can if you want them to


    Class names in Java are case sensitive.


    Strings are not mutable in Java, so concatenation can be an expensive operation.


    The Java Class library provides a mechanism to implement threads. PHP has no such mechanism.


    PHP methods (and functions) allow you have optional parameters. In java, you need to define a separate method for each possible list of parameters

    public function inPHP($var1, $var2='foo'){}  public void function inJava($var1){     $var2 = 'foo';     inJava($var1,$var2); } public void function inJava($var1,$var2){  } 

    PHP requires an explicit $this be used when an object calls its own methods methods. Java (as seen in the above example) does not.


    Java programs tend to be built from a ‘program runs, stays running, processes requests’ kind of way, where as PHP applications are built from a ‘run, handle the request, stop running’ kind of way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't think you can do it with inotify. Here… May 11, 2026 at 11:46 pm
  • Editorial Team
    Editorial Team added an answer Check to make sure you have a ServiceReferences.ClientConfig file in… May 11, 2026 at 11:46 pm
  • Editorial Team
    Editorial Team added an answer As John Saunders said, you have to recreate all of… May 11, 2026 at 11:46 pm

Related Questions

What are the main differences between a Linked List and a BinarySearchTree? Is BST
What are the main differences between SQLite and HSQLDB ? There are lots of
What are the main differences (if any) between the box models of IE8 and
I mostly use Java and generics are relatively new. I keep reading that Java

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.