Advertisement
DmPurtov

JavaTestCommon

Mar 27th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. 01 ====================================================================================================
  2.  
  3. BigDecimal a = new BigDecimal("500.000");
  4. BigDecimal b = new BigDecimal("300000");
  5. System.out.println(a+b);
  6.  
  7. 02 ====================================================================================================
  8.  
  9. String s1 = "String";
  10. String s2 = new String("String");
  11. String s3 = "String";
  12. System.out.println(s1 == s2);
  13. System.out.println(s1 == "String");
  14. System.out.println(s1 == s3);
  15. System.out.println(s1.equals(s2));
  16.  
  17. 03 ====================================================================================================
  18.  
  19. private class myString extends String {
  20.     public void sayHello () {
  21.         System.out.println("Hello");
  22.     }
  23. }
  24.  
  25. 04 ====================================================================================================
  26.  
  27. public class Item {
  28.     int id;
  29.     String name;
  30. }
  31.  
  32. List<Item> list = new ArrayList();
  33. // заполняем лист...
  34. // как найти элемент с определенным name?
  35.  
  36. 05 ====================================================================================================
  37.  
  38. long[] array = {1, 2, 3};
  39. for (int x : array) {
  40.     System.out.print(x);
  41. }
  42.  
  43. 06 ====================================================================================================
  44.  
  45. try {
  46.     // do something
  47.     return;
  48. } catch (Exception e) {
  49.     // do something
  50. } finally {
  51.     System.out.println("Finally block");
  52. }
  53.  
  54. 07 ====================================================================================================
  55.  
  56. try {
  57.     // do something
  58.     System.exit();
  59. } catch (Exception e) {
  60.     // do something
  61. } finally {
  62.     System.out.println("Finally block");
  63. }
  64.  
  65. 08 ====================================================================================================
  66.  
  67. public class Test {
  68.     static {
  69.         i = 5;
  70.     }
  71.     static int i = 6;
  72.    
  73.     public static void main(String[] args) {
  74.         System.out.print(i);
  75.     }
  76. }
  77.  
  78. 09 ====================================================================================================
  79.  
  80. private static class A {
  81.     static int i = 1;
  82. }
  83.  
  84. private static class B extends A {
  85.    
  86. }
  87.  
  88. A a = new A();
  89. a.i = 2;
  90. B b = new B();
  91. System.out.println(b.i);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement