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基本类型:
计算所占字节:
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 退格

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Java Made Simple: A Beginner's Guide to Programming Power Introduction Java is a powerful programming language used in everything from mobile applications to enterprise-level systems. For beginners, Java's syntax is simple and easy to understand, making it an ideal choice for learning programming. Basic Syntax Java uses a class-based object-oriented programming paradigm. Classes are templates that organize related data and behavior together. Here is a simple Java class example: publicclassPerson{privateStringname;privateintage;

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4
