difirence for java php and js and c and python____js

來源:互聯網
上載者:User

 Python的對象分配和Java的類似. 跟Ruby的完全不一樣(Ruby會預先分配好對象鏈) ,
Python的記憶體回收機制太低端, 還只是90年代的Java,用引用計數法回收, 而Java的G1都完善出來了




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 first 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, will cause error once has error.

  5. if also has next script block, then read that 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 method for new instance(singleton) in php, difirence from 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 not.




 

php:  for array adding list:

difidence of demo[] = ""; and array_push(demo, "");  //seams to the results are identical.. but base code for these 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 for 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 is not 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 可以這樣用,shell不可




反射

java: Class.forName, getConstructors, getMethods, getParameterTypes

php: call_user_func, call_user_func_array   直接用變數作為類名





php add 1 day for time

date('Y-m-d', strtotime('2013-08-29 +1 day'));






Performance PHP :

如果能將類的方法定義成static,就盡量定義成static,它的速度會提升將近4倍

$row[’id’] 的速度是$row[id]的7倍。

echo 比 print 快,並且使用echo的多重參數(譯註:指用逗號而不是句點)代替字串串連,比如echo $str1,$str2。

登出那些不用的變數尤其是大數組,以便釋放記憶體

require_once()代價昂貴

include檔案時盡量使用絕對路徑,因為它避免了PHP去include_path裡尋找檔案的速度,解析作業系統路徑所需的時間會更少

如果你想知道指令碼開始執行(譯註:即伺服器端收到用戶端請求)的時刻,使用$_SERVER[‘REQUEST_TIME’]要好於time()

str_replace函數比preg_replace函數快,但strtr函數的效率是str_replace函數的四倍

用@屏蔽錯誤訊息的做法非常低效,極其低效

開啟apache的mod_deflate模組,可以提高網頁的瀏覽速度

遞增一個全域變數要比遞增一個局部變數慢2倍

遞增一個對象屬性(如:$this->prop++)要比遞增一個局部變數慢3倍

遞增一個未預定義的局部變數要比遞增一個預定義的局部變數慢9至10倍

僅定義一個局部變數而沒在函數中調用它,同樣會減慢速度(其程度相當於遞增一個局部變數)。PHP大概會檢查看是否存在全域變數

方法調用看來與類中定義的方法的數量無關

衍生類別中的方法運行起來要快於在基類中定義的同樣的方法

Apache解析一個PHP指令碼的時間要比解析一個靜態HTML頁面慢2至10倍。盡量多用靜態HTML頁面,少用指令碼

除非指令碼可以緩衝,否則每次調用時都會重新編譯一次。引入一套PHP緩衝機制通常可以提升25%至100%的效能,以免除編譯開銷

當執行變數$i的遞增或遞減時,$i++會比++$i慢一些。這種差異是PHP特有的,並不適用於其他語言,所以請不要修改你的C或Java代碼並指望它們能立即變快,沒用的。++$i更快是因為它只需要3條指令(opcodes),$i++則需要4條指令。後置遞增實際上會產生一個臨時變數,這個臨時變數隨後被遞增。而前置遞增直接在原值上遞增

不要把方法細分得過多,仔細想想你真正打算重用的是哪些代碼。

在可以用file_get_contents替代file、fopen、feof、fgets等系列方法的情況下,盡量用file_get_contents,因為他的效率高得多。但是要注意file_get_contents在開啟一個URL檔案時候的PHP版本問題;

迴圈內部不要聲明變數,尤其是大變數:對象(這好像不只是PHP裡面要注意的問題吧。)

foreach效率更高,盡量用foreach代替while和for迴圈

用單引號替代雙引號引用字串

“用i+=1代替i=i+1。符合c/c++的習慣,效率還高”

對global變數,應該用完就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 



在JDK1.5及以前版本中,RMI每接收一個遠程方法調用就產生一個單獨的線程來處理這個請求,請求處理完成後,這個線程就會釋放

在JDK1.6之後,RMI使用線程池來處理新接收的遠程方法調用請求-ThreadPoolExecutor

在JDK1.6中,RMI提供了可配置的線程池參數屬性:

sun.rmi.transport.tcp.maxConnectionThread - 線程池中的最大線程數量

sun.rmi.transport.tcp.threadKeepAliveTime - 線程池中閒置線程存活時間

1. 啟動時設定sun.rmi.transport.tcp.responseTimeout,單位是毫秒

    java -Dsun.rmi.transport.tcp.responseTimeout=50 

2.在應用程式中設定環境變數sun.rmi.transport.tcp.responseTimeout

 System.setProperty("sun.rmi.transport.tcp.responseTimeout", "5000")  單位也是毫秒






java基本類型:

1.整型
類型              儲存需求     bit數    取值範圍      備忘
int                 4位元組           4*8 
short             2位元組           2*8    -32768~32767
long              8位元組           8*8
byte              1位元組           1*8     -128~127
2.浮點型
類型              儲存需求     bit數    取值範圍      備忘
float              4位元組           4*8                  float類型的數值有一個尾碼F(例如:3.14F)
double          8位元組           8*8                       沒有尾碼F的浮點數值(如3.14)預設為double類型
3.char類型
類型              儲存需求     bit數     取值範圍      備忘
char              2位元組          2*8
4.boolean類型
類型              儲存需求    bit數    取值範圍      備忘
boolean        1位元組          1*8      false、true

c基本類型:




計算所佔位元組:

c  sizeof  strlen

java:  .getBytes().length  size  (基本類型不能查看size)



自訂類載入:

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種基本類型)

主要(基本)資料類型是: 字串 數值 布爾
複合(引用)資料類型是: 對象 數組
特殊資料類型是: Null Undefined 字串資料型別

 

php:(4種基本類型)

四種標量類型: boolean (布爾型) integer (整型) float (浮點型, 也稱作 double) string (字串)

兩種複合類型: array (數組) object (對象)

最後是兩種特殊類型: resource (資源) NULL (NULL)

為了確保代碼的易讀性,本手冊還介紹了一些偽類型: mixed number callback

 

java: 8/9種基本類型

基本類型可以分為三類,字元類型char,布爾類型boolean以及數實值型別byte、short、int、long、float、double。\

數實值型別又可以分為整數類型byte、short、int、long和浮點數類型float、double。JAVA中的數實值型別不存在無符號的,它們的取值範圍是固定的,不會隨著機器硬體環境或者作業系統的改變而改變。

 

 

 

C的資料類型總分為4種:整型、浮點、指標和結構體

細分的話好多,。。

 

 

 

 

 

3.特殊字元:就3個 \":雙引號 \':單引號 \\:反斜線

4.控制字元:5個 \' 單引號字元 \\ 反斜線字元 \r 斷行符號 \n 換行 \f 走紙換頁 \t 橫向跳格 \b 退格





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.