Difirence for Java PHP and JS and C and Python____js

Source: Internet
Author: User
Tags garbage collection goto php script scalar zend

Python's object allocation is similar to Java's. It's completely different from Ruby's (Ruby will allocate the object chain in advance),
Python's garbage collection mechanism is too low-end, but only in the 90 's Java, with reference counting method of recycling, and the Java G1 are perfect out of the




Operation principle:

Java:

Base Java code, binary code, Class Loader{oad link (validate, prepare, resolve) init}, JVM, C

Php:

4 Layers System (Zend Engine, Zend Extension, PHP, SAPI)

Js:

1.read the ' the ' I script block;

2.grammar parsing, if error then goto flow 5,else goon Flow 3;

3. Pre resolve for Var varibles and functions (never cause error, just pre resolve the right declare)

4.run segments, would cause error once has error.

5. If also has next script block, then read this goto Flow 2.


Abstract Class All can have Constrctor method, just can ' t be new instance (Java, PHP)

Inteface

Php:

Java:must defined to public static final


Special to new instance (singleton) in PHP, difirence to Java//good use for PHP array

static function getinstance ($className)
{
Static $_instances = Array ();
if (!isset ($_instances[$className])) {
$_instances[$className] = new $className;
}
return $_instances[$className];
}




Abstract Class


Final/const


Namespace (Java:import/php:use)

new instance (java:reflect/php:dynamic scalar)

PHP can extends the private method from super class, but Java can.




Php:for Array Adding list:

Difidence of demo[] = "";  and Array_push (demo, ""); Seams to the results are identical. But base code for this two is the same????

Some array functions:

For ($i =0, $n =count ($servers); $i < $n; $i + +) {
Echo Key ($servers [$i]);//get Thekey
echo ' | ';
Echo Current ($servers [$i]);//get the value
echo ' <br/> ';
}

Bath JS and PHP has string array index,

But Java only has number arrayindex (The reason why Java has so many data struct seems as hashmap ...)

Ex

var aa = [];/var AA = new Array (); JS,, (in JS, var bb={} means JSON

int[] aa = {}; Java

$AA = Array (); Php

Word=[' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G ']//python//c=word[:2]

Good use as Array operating (seems to HashMap Constains Funciton in Java):

Js:if (Aa[bb]) {}//Compared to Java HashMap, good

Php:if (Isset ($aa [BB])) {}//Compared to Java HashMap, good

JS Array Push:

Sourcearray.push (""); Return the length

PHP Array Push:

Array_push ($array, value1, vlaue2,); Return the length

$array [] = array (123=>342);

$array [233] = 23432; This isn't a push,

Java has no array push method

Python array Puth:
Word.append ("DD");


PHP Call System:

Exec,system,shell_exec,passthru ()

PHP Call Java:

EXEC (' Java-jar ... ')/or install Php_java extention

Java Call System:

Process proc = Runtime.getruntime (). EXEC ("###");

Java Call SSH:

Should use some Lettle framework as dev fast as possible




Php:

Var_dump (Memory_get_usage ());



<?php if ($report _list): foreach ($report _list as $k => $v):?>

<?php Echo $v->reportid?>

<?php endforeach;endif;? >



TimeStamp:

Php Date (' D.m.y h:i:s ',-3600);
Mysql Select From_unixtime (-3600);
Java New SimpleDateFormat ("Mm/dd/yyyy HH:mm:ss"). Format (new Date ( -3600 * 1000L))
C++ time_t epch =-3600;
printf ("%i->%s", epch, Asctime (Gmtime (&EPCH))); (time.h)
C# String.Format ("{0:d/m/yyyy HH:mm:ss}", New System.DateTime (1970, 1, 1, 0, 0, 0, 0)
. AddSeconds (1293840000));
Javascript New Date ( -3600*1000). ToString ()

Echo ${a$b} #php can be used so that the shell cannot be




Reflection

Java:Class.forName, GetConstructors, GetMethods, getparametertypes

Php:call_user_func, Call_user_func_array directly with variables as class names





PHP add 1 day for time

Date (' y-m-d ', Strtotime (' 2013-08-29 +1 Day '));






Performance PHP:

If you can define the method of a class as static, try to define it as static, and it will rise nearly 4 times times faster.

$row [' ID '] is 7 times times the speed of $row[id].

echo is faster than print, and uses Echo's multiple arguments (to refer to a comma rather than a period) instead of a string connection, such as Echo $str 1, $str 2.

Unregister those unused variables, especially large arrays, to free up memory

Require_once () costly

Include files as much as possible because it avoids the speed with which PHP looks for files in Include_path, and it takes less time to parse the operating system path.

It's better to use $_server[' request_time ' than time if you want to know when the script starts executing (that is, the server receives the client request)

The Str_replace function is faster than the Preg_replace function, but the STRTR function is four times times more efficient than the Str_replace function.

Using the @ block error message is very inefficient and extremely inefficient

Open the Apache mod_deflate module, you can improve the browsing speed of the Web page

Incrementing a global variable is twice times slower than incrementing a local variable

Incrementing an object property (such as: $this->prop++) is 3 times times slower than incrementing a local variable

Incrementing an undefined local variable is 9 to 10 times times slower than incrementing a predefined local variable

Defining only one local variable, not calling it in a function, also slows down the speed (which is equivalent to incrementing a local variable). PHP will probably check to see if there are global variables

The method call appears to be independent of the number of methods defined in the class

Methods in a derived class run faster than the same method defined in the base class

Apache parses a PHP script 2 to 10 times times slower than parsing a static HTML page. Use static HTML pages as much as possible and use less scripting

Unless the script can be cached, it will be recompiled every time it is invoked. Introducing a set of PHP caching mechanisms typically improves performance by 25% to 100% to exempt compilation overhead

$i + + $i slower than + + when the execution variable $i is incremented or decremented. This difference is specific to PHP and does not apply to other languages, so please do not modify your C or Java code and expect them to quickly become useless. + + $i faster because it requires only 3 instructions (opcodes), $i + + requires 4 instructions. A post increment actually produces a temporary variable, which is then incremented. and the predecessor increments directly on the original value increment

Don't subdivide the method too much and think carefully about what code you really want to reuse.

In the case of using file_get_contents instead of file, fopen, feof, fgets and so on, use file_get_contents as much as possible, because he is more efficient. But pay attention to file_get_contents in opening a URL file when the PHP version problem;

Do not declare variables inside the loop, especially large variables: objects (this seems to be not just a matter of note in PHP). )

foreach is more efficient, use foreach instead of while and for loops as much as possible

Replace double quotation mark reference string with single quotation mark

"Replace i=i+1 with I+=1." In line with C + + habits, efficiency is also high "

For global variables, you should run out of unset ()




Java Get the jar path

public static String Baseurl_sysuser_all = IConfig.class.getProtectionDomain (). Getcodesource (). GetLocation (). GetPath ();
public static String Baseurl_sysuser = baseurl_sysuser_all.substring (0, Baseurl_sysuser_all.lastindexof ("/"));


Volatile PK Synchronized



In JDK1.5 and previous versions, RMI generated a separate thread to handle the request every time a remote method call was received, and the thread was freed when processing of the request was completed.

After JDK1.6, RMI uses a thread pool to handle newly received remote method call requests-threadpoolexecutor

In JDK1.6, RMI provides configurable thread pool parameter properties:

Sun.rmi.transport.tcp.maxConnectionThread-Maximum number of threads in the thread pool

Sun.rmi.transport.tcp.threadKeepAliveTime-Idle thread survival time in the thread pool

1. Set the sun.rmi.transport.tcp.responseTimeout at startup, the unit is milliseconds

Java-dsun.rmi.transport.tcp.responsetimeout=50

2. Setting environment variables in the application sun.rmi.transport.tcp.responseTimeout

System.setproperty ("Sun.rmi.transport.tcp.responseTimeout", "5000") units are also milliseconds






Java Basic type:

1. Integral type
Type storage requirement bit number value range remark
int 4 bytes 4*8
Short 2 bytes 2*8-32768~32767
Long 8 bytes 8*8
BYTE 1 byte 1*8-128~127
2. Floating point type
Type storage requirement bit number value range remark
Float 4 bytes 4*8 float type has a suffix f (for example: 3.14F)
Double 8 byte 8*8 floating-point value without suffix f (for example, 3.14) The default is double type
3.char type
Type storage requirement bit number value range remark
Char 2 bytes 2*8
4.boolean type
Type storage requirement bit number value range remark
Boolean 1 byte 1*8 false, True

C Basic Type:




Calculate the Bytes:

C sizeof strlen

Java:. GetBytes (). Length size (base type cannot view size)



Custom class Loading:

URL url = new URL ("File:/e:\\projects\\testscanner\\out\\production\\testscanner");
ClassLoader Myloader = new URLClassLoader (new Url[]{url});
Class C = myloader.loadclass ("Test.") Test3 ");
Test3 t3 = (Test3) c.newinstance ();














javascript: (3 basic types)

The primary (Basic) data type is: String Value Boolean
The composite (reference) data type is: An array of objects
Special data types are: Null Undefined string data types

php: (4 basic types)

Four scalar types: Boolean (Boolean) integer (integer) float (floating-point type, also called Double) string (string)

Two types of composite: Array (Array) object (objects)

Finally, there are two special types: resource (Resource) null (NULL)

To ensure the readability of the Code, this manual also describes some pseudo types: mixed number callback

basic types of JAVA:8/9

Basic types can be grouped into three categories, character type char, Boolean-type Boolean, and numeric type Byte, short, int, long, float, double. \

Numeric types can also be divided into integer type Byte, short, int, long, and floating-point type float, double. Numeric types in Java do not have unsigned, and their range of values is fixed and will not change as the machine hardware environment or operating system changes.

The data type of C is divided into 4 types: integral type, floating point, pointer and structure body

A lot of broken words, ...

3. Special characters: 3 ": double quotes \": single quotes \: backslash

4. Control character: 5 \ ' single quote character \ Slash backslash character \ r \ n linefeed \f Walk paper change page \ t horizontal jump grid \b Backspace





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.