search
Homephp教程php手册difirence for java php and js and c and python

Python的对象分配和Java的类. 跟Ruby的完全不一样(Ruby会预先分配好对象链) , Python的垃圾回收机制太低端, 还只是90年代的Java,用引用计数法回收, 而Java的G1都完善出来了 Operation Principle: JAVA: base java code, binary code, class loader{oad link(

 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   echo key($servers[$i]);//get thekey
  echo '|';
  echo  current($servers[$i]);//get the value
  echo '
'; 
}

 

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());



$v) :?>

reportid?>


 



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基本类型:

difirence for java php and js and c and python

difirence for java php and js and c and python


计算所占字节:

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 退格






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
解决kernel_security_check_failure蓝屏的17种方法解决kernel_security_check_failure蓝屏的17种方法Feb 12, 2024 pm 08:51 PM

Kernelsecuritycheckfailure(内核检查失败)就是一个比较常见的停止代码类型,可蓝屏错误出现不管是什么原因都让很多的有用户们十分的苦恼,下面就让本站来为用户们来仔细的介绍一下17种解决方法吧。kernel_security_check_failure蓝屏的17种解决方法方法1:移除全部外部设备当您使用的任何外部设备与您的Windows版本不兼容时,则可能会发生Kernelsecuritycheckfailure蓝屏错误。为此,您需要在尝试重新启动计算机之前拔下全部外部设备。

Win10如何卸载Skype for Business?电脑上的skype怎么彻底卸载方法Win10如何卸载Skype for Business?电脑上的skype怎么彻底卸载方法Feb 13, 2024 pm 12:30 PM

Win10skype可以卸载吗是很多用户们都想知道的一个问题,因为很多的用户们发现自己电脑上的默认程序上有这个应用,担心删除后会影响到系统的运行,下面就让本站来为用户们来仔细的介绍一下Win10如何卸载SkypeforBusiness吧。Win10如何卸载SkypeforBusiness1、在电脑桌面点击Windows图标,再点击设置图标进入。2、点击“应用”。3、在搜索框中输入“Skype”,点击选中找到的结果。4、点击“卸载”。5

带你搞懂Java结构化数据处理开源库SPL带你搞懂Java结构化数据处理开源库SPLMay 24, 2022 pm 01:34 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

一起聊聊Java多线程之线程安全问题一起聊聊Java多线程之线程安全问题Apr 21, 2022 pm 06:17 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

JavaScript怎么用for求n的阶乘JavaScript怎么用for求n的阶乘Dec 08, 2021 pm 06:04 PM

用for求n阶乘的方法:1、使用“for (var i=1;i<=n;i++){}”语句控制循环遍历范围为“1~n”;2、循环体中,使用“cj*=i”将1到n的数相乘,乘积赋值给变量cj;3、循环结束后,变量cj的值就n的阶乘,输出即可。

详细解析Java的this和super关键字详细解析Java的this和super关键字Apr 30, 2022 am 09:00 AM

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

Java基础归纳之枚举Java基础归纳之枚举May 26, 2022 am 11:50 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

归纳整理JAVA装饰器模式(实例详解)归纳整理JAVA装饰器模式(实例详解)May 05, 2022 pm 06:48 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于设计模式的相关问题,主要将装饰器模式的相关内容,指在不改变现有对象结构的情况下,动态地给该对象增加一些职责的模式,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),