Azathoth42

my java test

Apr 27th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. Skip to main content
  2. Vstupní test - JAVA programátor
  3. You are logged in as Matej Racinsky (Logout)
  4. Page path
  5. Home / ► My courses / ► JAVA / ► Topic 1 / ► Vstupní test - JAVA programátor
  6. Started on Monday, 27 April 2015, 10:31 PM
  7. State Finished
  8. Completed on Tuesday, 28 April 2015, 12:00 AM
  9. Time taken 1 hour 29 mins
  10. Grade Not yet graded
  11. Question 1
  12. Complete
  13. Marked out of 1.00
  14. Not flaggedFlag question
  15. Question text
  16. Jak provedete konvert hodnoty String reprezentující datum na Date
  17.  
  18. String dateString = "2010-01-11";
  19. answer:
  20. DateFormat format = new SimpleDateFormat("yyyy-mm-dd");
  21. Date date = format.parse(dateString);
  22. Question 2
  23. Complete
  24. Marked out of 1.00
  25. Not flaggedFlag question
  26. Question text
  27. Napište, jak provedete konvert hodnoty String reprezentující číslo na int
  28.  
  29. String numString = "1000";
  30. answer:
  31. int number = Integer.parseInt(numString);
  32. Question 3
  33. Complete
  34. Marked out of 1.00
  35. Not flaggedFlag question
  36. Question text
  37. Napište metodu, která vrátí datum Date posunutý odedneška o zadaný počet dní
  38.  
  39. - příklad použití metody:
  40.  
  41. Date date = getDateShift(100); // vrátí datum odedneška za 100 dní
  42. answer:
  43. public Date getDateShift(int shift) {
  44. Calendar calendar = Calendar.getInstance();
  45. calendar.add(Calendar.DATE, shift);
  46. return calendar.getTime();
  47. }
  48. Question 4
  49. Complete
  50. Marked out of 1.00
  51. Not flaggedFlag question
  52. Question text
  53. Napište metodu, která vrátí int hodnotu na základě vstupního řetězce String dle tabulky:
  54.  
  55. item_A 1
  56. item_B 3
  57. item_c 5
  58. item_D 7
  59. item_E 12
  60. item_F 4
  61.  
  62. příklad použití metody:
  63.  
  64. int itemId = itemNameToItemId("item_c");
  65. answer:
  66. public int itemNameToItemId(String item) {
  67. Map<String, Integer> map = new HashMap<>();
  68. map.put("item_A", 1);
  69. map.put("item_B", 3);
  70. map.put("item_c", 5);
  71. map.put("item_D", 7);
  72. map.put("item_E", 12);
  73. map.put("item_F", 4);
  74. return map.get(item);
  75. }
  76. Question 5
  77. Complete
  78. Marked out of 1.00
  79. Not flaggedFlag question
  80. Question text
  81. Napište metodu, která převede čárkama oddělené hodnoty vstupního řetězce String na seznam hodnot
  82.  
  83. příklad použití metody:
  84.  
  85. List<String> itemList = convertStringSetToList("item_A, item_B, item_c, item_D, item_E, item_F");
  86.  
  87. answer:
  88. public List<String> convertStringSetToList(String values){
  89. String[] valuesArray = values.split(", ");
  90. return Arrays.asList(valuesArray);
  91. }
  92. Question 6
  93. Complete
  94. Marked out of 1.00
  95. Not flaggedFlag question
  96. Question text
  97. Jaký je rozdíl v použití operátoru & a && ?
  98. answer:
  99. operátor && provádí zkrácené vyhodnocování, tedy pokud ve výrazu A && B je A == false, B se nevyhodnocuje, zatímco u A & B se vyhodností A i B.
  100. Question 7
  101. Complete
  102. Marked out of 1.00
  103. Not flaggedFlag question
  104. Question text
  105. Máme problém s JAVA HEAP (memory leak). Při analýze heap bylo zjištěno, že problém je někde v následujícím kódu. Identifikujte problém.
  106.  
  107.  
  108. Connection conn = null;
  109. PreparedStatement ps = null;
  110. ResultSet rs = null;
  111. try {
  112. conn = getConnection();
  113. ps = conn.prepareStatement(statement);
  114. rs = ps.executeQuery();
  115. if (rs.next()) {
  116. // code
  117. }
  118. } catch (Exception e) {
  119. // handle exception
  120. } finally {
  121. ps.close();
  122. conn.close();
  123. }
  124. answer:
  125. catch i finally jsou uvnitř bloku try. Takže když nastane výjimka, proměnné ps a re se nezavřou.
  126. Question 8
  127. Complete
  128. Marked out of 1.00
  129. Not flaggedFlag question
  130. Question text
  131. Do kterého adresáře v ejb.jar archívu vložíte soubor ejb-jar.xml ?
  132. answer:
  133. do adresáře META-INF
  134. Question 9
  135. Complete
  136. Marked out of 1.00
  137. Not flaggedFlag question
  138. Question text
  139. Vytvořte XSD schéma definující následující XML :
  140.  
  141. <price_list>
  142. <price>
  143. <name>rohlík</name>
  144. <id>1</id>
  145. <currency>CZK</currency>
  146. <amount>3</amount>
  147. </price>
  148. <price>
  149. <name>mléko</name>
  150. <id>2</id>
  151. <currency>CZK</currency>
  152. <amount>12</amount>
  153. </price>
  154. <price>
  155. <name>máslo</name>
  156. <id>3</id>
  157. <currency>CZK</currency>
  158. <amount>25</amount>
  159. </price>
  160. <price>
  161. <name>chleba</name>
  162. <id>4</id>
  163. <currency>CZK</currency>
  164. <amount>21</amount>
  165. </price>
  166. </price_list>
  167.  
  168. answer:
  169. <?xml version="1.0" encoding="UTF-8" ?>
  170. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  171. <xs:element name="price_list">
  172. <xs:complexType>
  173. <xs:sequence>
  174. <xs:element name="price" maxOccurs="unbounded">
  175. <xs:complexType>
  176. <xs:sequence>
  177. <xs:element name="name" type="xs:string"/>
  178. <xs:element name="id" type="xs:integer"/>
  179. <xs:element name="currency" type="xs:string"/>
  180. <xs:element name="amount" type="xs:integer"/>
  181. </xs:sequence>
  182. </xs:complexType>
  183. </xs:element>
  184. </xs:sequence>
  185. </xs:complexType>
  186. </xs:element>
  187. </xs:schema>
  188. Question 10
  189. Complete
  190. Marked out of 1.00
  191. Not flaggedFlag question
  192. Question text
  193. Vytvořte XSD schéma definující následující XML :
  194.  
  195. <price_list>
  196. <price name="rohlík" id="1" currency="CZK">3</price>
  197. <price name="mléko" id="2" currency="CZK">12</price>
  198. <price name="máslo" id="3" currency="CZK">25</price>
  199. <price name="chleba" id="4" currency="CZK">21</price>
  200. </price_list>
  201.  
  202. answer:
  203. <?xml version="1.0" encoding="UTF-8" ?>
  204. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  205. <xs:element name="price_list">
  206. <xs:complexType>
  207. <xs:sequence>
  208. <xs:element name="price" maxOccurs="unbounded">
  209. <xs:complexType>
  210. <xs:simpleContent>
  211. <xs:extension base="xs:integer">
  212. <xs:attribute name="name" type="xs:string"/>
  213. <xs:attribute name="id" type="xs:integer"/>
  214. <xs:attribute name="currency" type="xs:string"/>
  215. </xs:extension>
  216. </xs:simpleContent>
  217. </xs:complexType>
  218. </xs:element>
  219. </xs:sequence>
  220. </xs:complexType>
  221. </xs:element>
  222. </xs:schema>
  223. Finish review
  224. Skip Quiz navigation
  225. Quiz navigation
  226. Question 1 This page Question 2 This page Question 3 This page Question 4 This page Question 5 This page Question 6 This page Question 7 This page Question 8 This page Question 9 This page Question 10 This page
  227. Finish review
  228. You are logged in as Matej Racinsky (Logout)
  229. JAVA
Advertisement
Add Comment
Please, Sign In to add comment