我想知道一些非常有用且特定于java的功能.因为我是java开发人员,当人们问我一些很好的编程功能,这些功能在java中没有,而不是任何其他语言,那么你认为我可以告诉他们.
也就是说,如果我告诉他们这些功能,那么他们应该发现我是一名java开发人员.
public abstract class Master
{
public void printForAllMethodsInSubClass()
{
System.out.println ("Printing before subclass method executes");
System.out.println ("Parameters for subclass method were: ....");
}
}
public class Owner extends Master {
public void printSomething () {
System.out.println ("This printed from Owner");
}
public int returnSomeCals ()
{
return 5+5;
}
}
Run Code Online (Sandbox Code Playgroud)
不搞乱子类的方法......是否可以printForAllMethodsInSubClass()在子类的方法执行之前执行?
更新:
使用AspectJ/Ruby/Python ......等是否也可以打印参数?以上代码格式如下:
public abstract class Master
{
public void printForAllMethodsInSubClass()
{
System.out.println ("Printing before subclass method executes");
}
}
public class Owner extends Master {
public …Run Code Online (Sandbox Code Playgroud) 有人说,在对这个答案的评论中
我一般都要推荐Apache Commons,因为如果你发现有用的东西,它实际上是50:50.那里肯定有很多宝石,但也有很多不好的和过时的东西,例如此时令人担忧的缺乏Generics是不可原谅的 - 即使引入它们的Java 5已经达到了EOL!
在这种情况下,"缺乏泛型"是什么意思?你能用外行的话解释一下吗?
我像这样一个像这样的2D数组,就像一个矩阵:
{{1, 2, 4, 5, 3, 6},
{8, 3, 4, 4, 5, 2},
{8, 3, 4, 2, 6, 2},
//code skips... ...
}
Run Code Online (Sandbox Code Playgroud)
(数组没有排序)我想获得所有的"4"位置,而不是逐个搜索数组,并返回位置,我怎样才能更快/更有效地搜索它?提前.
Python需要一个框架,Java(用于Web)也是如此.我对Ruby或Coldfusion了解不多.但是,除了PHP之外,是否有另一种语言可以独立存在,因为它不需要框架或者没有严格遵守设计模式(MVC和喜欢)?顺便说一下,Python和Java需要一个框架来处理网络的声明纯粹来自我对文章和书籍的阅读; 我可能弄错了.
编辑:框架我指的是像Django,Pylon,Spring,JSF,RoR等
我有一个字符串,例如":)text:)text :) :-) word :-("我需要将它附加到文本框(或其他地方),条件:
而不是':)',':-('等需要调用输入特定符号的函数
我用有限状态机来解决存在的解决方案,但是如何实现它不知道.等待建议.
更新: ":)文字:)文字:) :-)字:-(" => 当我们见面':)'wec所有功能微笑(":)")它在文本框上显示图像
更新:我喜欢与代表和Regex.Replace的想法.我可以当遇到':)'发送到委托参数':)'和遇见':('其他参数.
更新:找到解决方案转换为char并将每个符号比较为':)'如果相等则调用smile(':)')
这个问题促使我问 - 为什么大学仍然使用Modula2这样的语言进行教学,何时可以免费获得改进的现代语言?
例如,是否还有教授帕斯卡的单身人士?我的意思是,30年前它很好,但是......现在呢?为什么?
为什么不Java,C#,Haskell?
相关:还是教导LISP倒退吗?
这是一个重复的问题吗?如果没有,我认为它应该是社区维基话题.
<?php
echo (2884284 >> 16), '<br>'; // = 44
echo ((2884284 >> 16) & 0xFFFF), '<br>'; // 44
Run Code Online (Sandbox Code Playgroud)
从上面我得到44
那怎么能从44回到2884284 ???
对于我来说,使用动态类型语言(对象或查找该对象的键)的参数似乎很常见.例如,当我使用数据库时,我可能有一个方法getMyRelatedStuff(person)
所有我真的需要查找相关的东西是该人的id所以我的方法在python中看起来像这样:
def getMyRelatedStuff(person_or_id):
id = person_or_id.id if isinstance(person,User) else person_or_id
#do some lookup
Run Code Online (Sandbox Code Playgroud)
或者走另一个方向:
def someFileStuff(file_or_name):
file = file_or_name if hasattr(file,'write') else open(file_or_name)
Run Code Online (Sandbox Code Playgroud)
编辑:我正在寻找一个内置的语法,我能想到的最接近的是C#中的隐式和显式关键字,允许您定义类型之间的强制转换.
我发现自己遇到了一个面试问题,其目标是编写一个排序算法,对一系列未排序的int值进行排序:
int[] unsortedArray = { 9, 6, 3, 1, 5, 8, 4, 2, 7, 0 };
Run Code Online (Sandbox Code Playgroud)
现在我用Google搜索并发现那里有很多排序算法!最后,我可以激励自己深入研究Bubble Sort,因为它看起来很简单.
我阅读了示例代码并找到了一个如下所示的解决方案:
static int[] BubbleSort(ref int[] array)
{
long lastItemLocation = array.Length - 1;
int temp;
bool swapped;
do
{
swapped = false;
for (int itemLocationCounter = 0; itemLocationCounter < lastItemLocation; itemLocationCounter++)
{
if (array[itemLocationCounter] > array[itemLocationCounter + 1])
{
temp = array[itemLocationCounter];
array[itemLocationCounter] = array[itemLocationCounter + 1];
array[itemLocationCounter + 1] = temp;
swapped = true;
} …Run Code Online (Sandbox Code Playgroud) programming-languages while-loop conditional-statements c#-4.0