class BaseInit
{
int x = this.foo();
int foo()
{
return 0;
}
}
class SubInit extends BaseInit
{
@Override
int foo()
{
return 1;
}
}
public class InheritanceAttributeInit
{
public static void main(String[] args)
{
BaseInit b = new SubInit();
System.out.println(b.x); // 1
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTester {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String regex = "/ajax/\\w+/(.*)";
String[] strings = { "/ajax/hello/KID/de-mt.vc.ca02.06.04/1559286",
"/ajax/hell_o/KID/de-mt.vc.ca02.06.04/1559286",
"/ajax/h0e-l8l_o/KID/de-mt.vc.ca02.06.04/1559286", };
for (String s : strings) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(s);
String kid = "";
if (matcher.find()) {
// group(0) returns the entire match, not a captured group
kid = matcher.group(1);
}
System.out.println(kid);
}
}
}
java
1
Java regex tester
importjava.util.regex.Matcher;importjava.util.regex.Pattern;publicclassRegexTester{/** * @param args */publicstaticvoidmain(String[]args){// TODO Auto-generated method stubStringregex="/ajax/\\w+/(.*)";String[]strings={"/ajax/hello/KID/de-mt.vc.ca02.06.04/1559286","/ajax/hell_o/KID/de-mt.vc.ca02.06.04/1559286","/ajax/h0e-l8l_o/KID/de-mt.vc.ca02.06.04/1559286",};for(Strings:strings){Patternpattern=Pattern.compile(regex);Matchermatcher=pattern.matcher(s);Stringkid="";if(matcher.find()){// group(0) returns the entire match, not a captured groupkid=matcher.group(1);}System.out.println(kid);}}}
public void generate(Integer leng) {
Integer[] variation = new Integer[leng];
this.putElement(leng, variation, 0);
}
//Ad. public void generate(Integer)
//variation to poczatkowa pusta tablica, ktora jest jakby modelem
//wariacji (model okresla tylko dlugosc)
private boolean repetition(Integer[] var, Integer element, Integer position)
{
for(int j=0;j<position;j++)
if(var[j]==element)
return true;
return false; //sprawdza czy na dotychczasowych pozycjach nie ma
// takiego samego elementu
}
private void putElement(Integer leng,Integer[] var,Integer position)
{
if(position >= leng)
{
//tutaj nalezy odwolac sie do kontekstu calej klasy
//sprawdzenie warunku wymaganego w zadaniu - NVM
Integer[] clone_var = (Integer[])var.clone();
this.wartosci.clear();
if(clone_var.length == this.zmienne.size() && this.wartosci.isEmpty() == true) {
for(int i = 0; i < clone_var.length; i++) this.wartosci.add(clone_var[i]);
this.solveIt();
}
return;
}
else
{
for (int i=0;i<values.length;i++)
{
if(!this.repetition(var,values[i],position))
{ //jezeli dany element sie nie powtorzyl, to wywolujemy
//kolejne funkcje i chuj - to jest w chuj nieoptymalne
var[position] = values[i];
this.putElement(leng, var, position+1);
}
}
}
}
java
1
variations (without repetitions) generator
publicvoidgenerate(Integerleng){Integer[]variation=newInteger[leng];this.putElement(leng,variation,0);}//Ad. public void generate(Integer)//variation to poczatkowa pusta tablica, ktora jest jakby modelem//wariacji (model okresla tylko dlugosc)privatebooleanrepetition(Integer[]var,Integerelement,Integerposition){for(intj=0;j<position;j++)if(var[j]==element)returntrue;returnfalse;//sprawdza czy na dotychczasowych pozycjach nie ma// takiego samego elementu}privatevoidputElement(Integerleng,Integer[]var,Integerposition){if(position>=leng){//tutaj nalezy odwolac sie do kontekstu calej klasy//sprawdzenie warunku wymaganego w zadaniu - NVMInteger[]clone_var=(Integer[])var.clone();this.wartosci.clear();if(clone_var.length==this.zmienne.size()&&this.wartosci.isEmpty()==true){for(inti=0;i<clone_var.length;i++)this.wartosci.add(clone_var[i]);this.solveIt();}return;}else{for(inti=0;i<values.length;i++){if(!this.repetition(var,values[i],position)){//jezeli dany element sie nie powtorzyl, to wywolujemy //kolejne funkcje i chuj - to jest w chuj nieoptymalnevar[position]=values[i];this.putElement(leng,var,position+1);}}}}
import java.io.*;
public class Read
{
public static void main(String args[]) throws IOException
{
String s;
int i=0,res=0;
int tmpValue[]=new int[2];
DataInputStream din = new DataInputStream(System.in);
while((s = din.readLine()) != null)
{
try
{
tmpValue[i++] = Integer.parseInt(s);
}
catch(NumberFormatException ne)
{
System.out.println("give integers only");
}
catch(ArrayIndexOutOfBoundsException ee)
{
System.out.println("give only 2 nos with a control z");
}
}
try
{
res=tmpValue[0]/tmpValue[1];
System.out.println("Quotient="+res);
}
catch(ArithmeticException ae)
{
System.out.println("not possible to divide by zero");
}
}
}
java
1
read 2 nos from keyboard and find quotient
importjava.io.*;publicclassRead{publicstaticvoidmain(Stringargs[])throwsIOException{Strings;inti=0,res=0;inttmpValue[]=newint[2];DataInputStreamdin=newDataInputStream(System.in);while((s=din.readLine())!=null){try{tmpValue[i++]=Integer.parseInt(s);}catch(NumberFormatExceptionne){System.out.println("give integers only");}catch(ArrayIndexOutOfBoundsExceptionee){System.out.println("give only 2 nos with a control z");}}try{res=tmpValue[0]/tmpValue[1];System.out.println("Quotient="+res);}catch(ArithmeticExceptionae){System.out.println("not possible to divide by zero");}}}
//AgeException.java
public class AgeException extends Exception
{
private String message;
public AgeException(String message)
{
super(message);
}
}
//Admission.java
public class Admission
{
public int age;
public String name;
public Admission(int age,String name)
{
this.age=age;
this.name=name;
}
public void checkAge() throws AgeException
{
if(age<19 || age>24)
{
AgeException ae=new AgeException("Age entered should be between 19 and 24\n Student name="+name +" Student age="+age);
throw ae;
}
}
//GetAdmission.java
public class GetAdmission
{
public static void main(String args[])
{
Admission A=new Admission(Integer.parseInt(args[0]),args[1]);
try
{
A.checkAge();
}
catch(AgeException ae)
{
System.out.println(ae);
}
}
}
java
1
Exception handling
//AgeException.javapublicclassAgeExceptionextendsException{privateStringmessage;publicAgeException(Stringmessage){super(message);}}//Admission.javapublicclassAdmission{publicintage;publicStringname;publicAdmission(intage,Stringname){this.age=age;this.name=name;}publicvoidcheckAge()throwsAgeException{if(age<19||age>24){AgeExceptionae=newAgeException("Age entered should be between 19 and 24\n Student name="+name+" Student age="+age);throwae;}}//GetAdmission.javapublicclassGetAdmission{publicstaticvoidmain(Stringargs[]){AdmissionA=newAdmission(Integer.parseInt(args[0]),args[1]);try{A.checkAge();}catch(AgeExceptionae){System.out.println(ae);}}}
new Thread() {
private String someVar;
private int someOtherVar;
public void run() {
// threadcode
}
public void init(String someVar, int someOtherVar) {
this.someVar = someVar;
this.someOtherVar = someOtherVar;
// other initcode
start();
}
}.init("", 0);
java
1
Anonymous thread with init
newThread(){privateStringsomeVar;privateintsomeOtherVar;publicvoidrun(){// threadcode}publicvoidinit(StringsomeVar,intsomeOtherVar){this.someVar=someVar;this.someOtherVar=someOtherVar;// other initcodestart();}}.init("",0);
ajust memory use in jira
modfiy %JIRA_HOME%/bin/setenv.sh, modify varaible JAVA_OPTS:
set JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx768m -Datlassian.standalone=JIRA -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true
// -Xms256m: indicate mininum memory, -Xmx512m: indicate the maximum memory
and set:
JIRA_MAX_PERM_SIZE=196m
java
1
ajust memory use in jira
ajustmemoryuseinjiramodfiy%JIRA_HOME%/bin/setenv.sh,modifyvaraibleJAVA_OPTS:setJAVA_OPTS=%JAVA_OPTS%-Xms512m-Xmx768m-Datlassian.standalone=JIRA-Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true// -Xms256m: indicate mininum memory, -Xmx512m: indicate the maximum memoryandset:JIRA_MAX_PERM_SIZE=196m
Java compile
vi Test.java
import java.util.*;
public class Test {
public static void main(String[] args) {
Map map = System.getProperties();
System.out.println(map);
}
}
# javac Test.java
# java Test
mysql
1
Java comile process
JavacompileviTest.javaimportjava.util.*;publicclassTest{publicstaticvoidmain(String[]args){Mapmap=System.getProperties();System.out.println(map);}}# javac Test.java# java Test
Hey there! I see you're running Internet Explorer 6.
That's neat. This reminds me of my grandpa. He had this old car that he kept having to fix. He spent so much money on it that he didn't want to get rid of it (even when it stopped running).