static

Java类和对象课后作业

北战南征 提交于 2020-01-24 23:15:59
1. public class test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Foo obj1=new Foo(); Foo onj2=new Foo(); System.out.println(obj1==obj2); } } class Foo{ int value=100; } 截图: 总结: 当 “ == ”施加于原始数据类型变量时,是比较变量所保存的数据是否相等 当 “ == ”施加于引用类型变量时,是比较这两个变量是否引用同一对象。 引用代表地址,所以 “ == ”实际上相当于比较两个引用类型变量中保存的对象地址是否相同。 2.以下代码为何无法通过编译?哪儿出错了? 推出结论: 如果类提供了一个自定义的构造方法,将导致系统不再提供默认构造方法。 3. class InitializeBlockClass { {field=200;} public int field=100; public InitializeBlockClass(int value){this.field=value;} public InitializeBlockClass(){} } public class test { public

PHP的3种基本设计模式-学习

大憨熊 提交于 2020-01-24 23:02:04
1.工厂模式,使用一个工厂方法或者类来生成对象,而不是在代码中直接new 2.单例模式,使某个类的对象只允许被创建一次 3.注册模式,用来解决全局共享和交换对象 理解: 1.工厂模式应用场景,有A、B、C、D1、D2、Factory 6个类,A、B、C中都实例化了D1,正常写法是在A,B,C中都写一次new D1,现有业务需求用D2代替D1,则需要把A,B,C中的每个D1都修改成D2,维护麻烦且易出错,工厂模式就是为解决这类问题而生,在Factory类中写一个静态方法 class Factory { static function createD() { $d = new D1(); return $d; } } A、B、C在实例化D1时只需要调用 $d = Factory::createD(); 现业务需求用D2代替D1,则只需要把工厂(Factory类)的createD方法中D1改为D2即可 $d = new D2(); 2.单例模式应用场景,数据库连接只需一次。有一个私有的构造方法和属性(如:$db),和一个对外的方法可获取到该类的实例 class DataBase { private static $db; private function __construct() { } /** * 在单例模式的静态方法中判断该类是否实例化 * @return Database */

java错题本

风格不统一 提交于 2020-01-24 23:01:09
1.判断题: Java程序一般应当含有main方法,因为它是所有JaVa程序执行的入口 (错) 解析:applet(java小程序)不用,application(java应用程序)需要。(见 java applet和java application的区别 ) 2.判断题: 当运行Java程序时, 类加载器 将字节码加载到内存中, 字节码检验器 确认所有的字节码是合法的并且不会破坏Java的安全限制,然后 解释器 读取这些字节码并将它们翻译成计算机可以理解的语言。在程序执行的时候还有可能需要在内存中存储一些必要的数据。 (对) 3.易错现象: 4.关于java中的堆区、栈区、方法区 参考: http://ydiandiandian.diandian.com/post/2012-06-18/40027997380 关于JVM,参考书《深入浅出JVM》,后面补张图,虽然对JVM还是不太了解,暂且先放放。 先了解具体的概念: JAVA的JVM的内存可分为3个区:堆(heap)、栈(stack)和方法区(method) (1)堆区: 1.存储的全部是对象,每个对象都包含一个与之对应的class的信息。(class的目的是得到操作指令) 2.jvm只有一个堆区(heap)被所有线程共享,堆中不存放基本类型和对象引用,只存放对象本身 (2)栈区: 1.每个线程包含一个栈区

day08_String类、static关键字、Arrays类、 Math类

北城余情 提交于 2020-01-24 10:24:01
String类 概述 java.lang.String 类代表字符串。Java程序中所有的字符串文字(例如 "abc" )都可以被看作是实现此类的实例。类 String 中包括用于检查各个字符串的方法,比如用于比较字符串,搜索字符串,提取子字符串以及创建具有翻译为大写或小写的所有字符的字符串的副本。 特点 字符串不变:字符串的值在创建后不能被更改。 举例: package demo01; public class Test { public static void main(String[] args) { /* 字符串的内容仍然是没有改变的 下面有两个字符串:"Hello","Java" strA当中保存的是地址值。 本来地址值是Hello的内存地址 后来地址值变成了Java的内存地址 */ String strA = "Hello"; System.out.println(strA); // Hello strA = "Java"; System.out.println(strA); // Java } } 因为String对象是不可变的,所以它们可以被共享。 举例: package demo01; /* 字符串常量池:程序当中直接写上的双引号字符串,就在字符串常量池中。 */ public class Demo02StringPool { public static void

Why not serving static files with Django in a production environment?

左心房为你撑大大i 提交于 2020-01-24 09:46:05
问题 I came across the following example for settings.py : if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) and was told: The static() helper function is suitable for development but not for production use. Never serve your static files with Django in a production environment. Can anyone explain why and how to use it the better way? EDIT: Can I use static() with Apache? 回答1: Django is not very fast or efficient for serving static files. To quote the

wpf static binding question

雨燕双飞 提交于 2020-01-24 07:32:31
问题 Ok guys, I have a serious problem with this. I have a static class with static properties providing some colors as a hex string: namespace com.myCom.Views { public static class MyColorTable { private const string _Hex0 = "#FFFFFFFF"; private const string _Hex1 = "#FFE5E5E5"; public static String Hex0 { get { return _Hex0; } } public static String Hex1 { get { return _Hex1; } } } } Now, I want to bind these colors to a UserControl via XAML, like this: <UserControl x:Class="com.testing

Why isn't SqlConnection disposed/closed?

核能气质少年 提交于 2020-01-24 05:14:34
问题 Given the method: internal static DataSet SelectDataSet(String commandText, DataBaseEnum dataBase) { var dataset = new DataSet(); SqlConnection sqlc = dataBase == DataBaseEnum.ZipCodeDb ? new SqlConnection(ConfigurationManager.AppSettings["ZipcodeDB"]) : new SqlConnection(ConfigurationManager.AppSettings["WeatherDB"]); SqlCommand sqlcmd = sqlc.CreateCommand(); sqlcmd.CommandText = commandText; var adapter = new SqlDataAdapter(sqlcmd.CommandText, sqlc); adapter.Fill(dataset); return dataset; }

第六次实训作业异常处理

微笑、不失礼 提交于 2020-01-24 01:51:12
1.编写一个类ExceptionTest,在main方法中使用try-catch-finally语句结构实现: 在try语句块中,编写两个数相除操作,相除的两个操作数要求程序运行时用户输入; 在catch语句块中,捕获被0除所产生的异常,并输出异常信息; 在finally语句块中,输出一条语句。 package qqq; import java.util.Scanner; / 。 / public class ExpetionText { static Scanner reaper=new Scanner(System.in); public static void main(String[] args) { int a,b,c = 0; System.out.println("请输入a,b:"); a=reaper.nextInt(); b=reaper.nextInt(); try{ c=a/b; }catch(ArithmeticException e) { System.out.println("除数不能为0!"); } finally{ System.out.println("结果:a/b="+c); } } } 请输入a,b: 3 0 除数不能为0! 结果:a/b=0 2.编写一个应用程序,要求从键盘输入一个double型的圆的半径,计算并输出其面积

Can you reset a static variable?

回眸只為那壹抹淺笑 提交于 2020-01-24 01:22:12
问题 I have been trying to reset a static variable that will keep count when certain methods are run. I want to be able to reset the counter after I return the output of one of the methods. The getEfficency will pull the value just fine, but after I run the getEfficency I would like for the static variable to be reset to 0, so that my program can run the other compute method. public class Sequence { private static int efficencyCount; public static int computeIterative(int n) { efficencyCount++; }

Java-嵌套接口

偶尔善良 提交于 2020-01-23 21:22:39
Java-嵌套接口 1. 什么是嵌套接口 嵌套接口可以被称为 inner interface,也可以称为 nested class。 接口可以嵌套在类或者其他接口中。 当在类中嵌套接口时可以是 public、private 以及默认包访问权限。 当在接口中嵌套接口时,其必须为 public(由于接口的性质,其默认也是public)。 为什么使用嵌套接口: 当一个接口只会在另一个接口中使用时,这样设计符合逻辑; 有利于封装(良好的框架不应该暴露给用户过多的实现细节,包括接口); 嵌套接口更具可读性以及可维护性;  在 Java 类库中一个典型的嵌套接口的例子是 java.util.Map 以及 Java.util.Map.Entry 。 java.util.Map 在这里也起到了命名空间的作用。关于命名空间详细点说就是如果这个 Entry 不做为 Map 接口的一个内部接口,那么为了说明这个接口是用于 Map 的实现的一部分,就应该取名为 MapEntry。那么对于企业级别的框架设计而言,这将会有非常多的 MapEntry。一般用户却不需要实现这些接口,但是这些接口却和 Map 这些可能被用户实现的接口在同一级别上,不利于阅读。   Entry 类不属于全局作用域,这也就意味着很多是 Entry 类型的 Entry 对象并不是 java.util.Map 类型。这里的 Java