Home >Backend Development >PHP Problem >What is the syntax difference between php and java

What is the syntax difference between php and java

青灯夜游
青灯夜游Original
2021-06-02 18:29:501753browse

Difference: 1. PHP supports "//", "#" and "/**/" comment method, java supports "//", "/**/" and "/***/" comment methods. 2. All function names, keywords, classes, variables, etc. in Java are case-sensitive; PHP is not. 3. PHP is a weak reference type, java is a strong reference type, etc.

What is the syntax difference between php and java

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The basic syntax of Java and PHP is basically the same. In fact, The basic syntax of most languages ​​is the same, but they still have some subtle differences:

1. Comments

PHP comments: PHP supports three types of comments Method:

A. Double slash For example: // This is to declare a variable

B. # symbol For example: # This is to declare a variable

C./* */ For example: /*This is to declare a variable*/

java also supports three comment methods:

A. Double slash For example: //This is to declare a variable

B./* */ For example: /*This is to declare a variable*/

C./***/ For example: /***This is to declare a variable*/

2, case sensitive

Case sensitivity issues in PHP: In PHP, all user-defined functions, classes and keywords (such as if, else, echo, etc.) are not case-sensitive, while variables are case-sensitive.

In java, all function names, keywords, classes, variables, etc. are case-sensitive.

3. Reference type

PHP variable declaration: PHP is similar to Javascript. Both are weak reference types, and there is no need to specify the type when declaring. Java is a strong reference type, and its type must be specified when declaring.

The way to declare variables in PHP is: $X = 7; Note: The naming rules for java and PHP variables are the same.

4. Data declaration

Classes in PHP: The implementation process is the same as that of java, both use the keyword class, but the data declaration is different. same.

<?php
class Car

{  var $color;  function Car($color="green") {    $this->color = $color;
  }  function what_color() {    return $this->color;
  }
}
?>

5. String representation

Strings in PHP can be represented by double quotes or single quotes. But in java only double quotes can be used.

For example: "string" 'string'

6. Java has the concept of internal classes, but PHP does not;

7. If there is method overloading under a class in Java, PHP can only overload the method of the parent class;

8. The operating mechanism is different:

9. Data types

There are 8 basic data types in Java, and corresponding reference types. PHP does not have reference types. To determine whether the values ​​of two variables are equal in Java, you must first convert Basic data type, otherwise the two variable reference values ​​may be compared. PHP does not use

10. Java and PHP construction methods cannot be inherited. Java uses super and PHP uses parent to call the parent class construction method.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the syntax difference between php and java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn