05 martie 2020

Judecăți de programatori

- Moartea e problemă semi-decidabilă.
Până nu mori nu ai de unde să știi că vei muri, poți avea doar așteptări rezonabile că la un moment dat se va întâmpla.
- I beg to differ. Pastrand analogia, problema este 100% decidabila (stii sigur ca algoritmul se... incheie), doar ca nu poti determina exact timpul de executie.
- Unii din oamenii care sunt acum în viață ar putea tehnic vorbind să fie nemuritori.
Nu cred că se întâmplă, dar nu ai de unde să știi până nu mor. Dacă te bazezi doar pe faptul că niciun om nu a ajuns la 200 de ani, e doar inducție partială pe mulțimea oamenilor care au murit deja, pentru că încă există 7 miliarde de cazuri care încă nu s-au oprit. Din câte știu eu, nu există o vârstă la care organismul să aibă codificat un return forțat, deci asta face problema să nu fie decidabila. Posibil să greșesc în intepretarea mea. Dacă da, unde?

25 februarie 2020

Alte întrebări culese de la interviuri

1. Două dintre următoarele afirmații sunt corecte:
a) hashCode() ajută la localizarea obiectelor în colecții
b) hashCode() trebuie să întoarcă un număr întreg, pozitiv
c) Implementarea lui hashCode() în clasa String este moștenită din Object
d) Două stringuri goale vor produce hashCode() identic

Adevărat: d
Fals: b, c
---

2. Ce afișează următorul program?

public class Main {
    public static void main(String args[]) {       
        int abc [] = {2, 3, 4};
        int def [] = fix(abc);
        System.out.println(abc[0] + abc[1] + abc[2]);
        System.out.println(def[0] + def[1] + def[2] + " ");
    }
   
    private static int [] fix(int [] array) {
        array[1] = 0;
        return array;
    }
}

Răspuns: 6 6
Metoda fix primește ca parametru referința la un obiect int [].

---

3. Care din următoarele situații nu cauzează un thread să se oprească, în mod direct:
a) wait()
b) notify()
c) sleep()
d) încercarea de a citi dintr-un InputStream

---

4. Avem două cuburi prin care vrem să afișăm zilele din calendar. Cum putem dispune cifrele?

Răspuns: Cubul 1 ia cifrele 0, 1, 2, 3, 4, 5 și Cubul 2 ia cifrele 0, 1, 2, 6, 7, 8 (6 se întoarce în 9).

18 februarie 2020

O colecție de întrebări pentru interviuri, ediția București 2020

Java SE
- polimorfism, mostenire
- modificatori de acces în JSE, diferența între protected și default
- cum functioneaza variabilele statice
- despre tipurile de excepții: checked și unchecked
- de ce se folosește finally
- try with resources
- cum se creează un obiect immutable
- diferența intre int si Integer
- despre stringuri, mutabile sau imutabile?
- concatenarea de stringuri din java, de ce e costisitor?
- StringBuilder vs StringBuffer
- care sunt tipurile de colecții: liste, seturi, map etc
- diferența List, Map și Set
- set ordonat--- TreeSet? cum se ordonează?
- diferența între Comparable si Comparator
- parsare XML cu java - cum?

- Struts, Servlet
- filtre din Servlet
- interceptor din Struts2
- JSP e thread safe?
- cum functionau aplicațiile Swing pe mai multe thread-uri - cum stia primul thread ca s-a terminat al doilea?
- JDBC, Hibernate
- de ce să folosesți JDBC comparativ cu un ORM?
- tipuri de statements in JDBC
- cum te protejezi de JDBC injection
- la ce se foloseste Maven, tipuri de scope-uri si la ce sunt folosite

Javascript, HTML
- HTML tags, caracteristici html5
- diferența GET/POST
- cum te protejezi de sniffing pe rețea
- obiecte in javascript, se poate folosi let in Javascript?
- multithreading in Javascript? Dar in html? web workers?
- Ajax - cum funcționeaza
- tipuri de atribute ale unui cookie
- tipuri de atacuri în oasp - top 10 vulnerabilities

Baze de date
- ce este un index într-o BD, ce este un trigger
- SQL: diferenta între delete și truncate (truncate nu activează trigger)
- tipuri de join, diferența între left și right join

Altele
- exemple de ședințe Agile
- design patterns exemple
- singleton si multithreading, cum se poate face thread safe
- REST api (x2)
- Linux exemple de comenzi, comanda pt schimbarea parolei, logare ca admin
- un excel care comunică lent cu o BD, cum se poate depana, primii pași?

28 noiembrie 2019

QF teste: exemple de procedura



import java.nio.file.Path

import java.util.concurrent.TimeUnit
import java.util.regex.Pattern

def referenceFile = rc.lookup("referenceFile")
def actualFile = rc.lookup("generatedFile")

def reference = new File(referenceFile).text
def actual = new File(actualFile).text

def isADELrapFormat = reference.contains("<ADELrap")

if(isADELrapFormat) {
    reference = fixFieldsToBeIgnoredInComparison(reference)
    actual = fixFieldsToBeIgnoredInComparison(actual)
}

rc.setLocal("areIdentical", rc.checkEqual(reference, actual, "Mesaj", level:2, report:true, nowrap:false))

private static String fixFieldsToBeIgnoredInComparison(final String xml) {
    final Pattern last_modified_time = Pattern.compile("<LAST_MODIFIED_TIME>.*</LAST_MODIFIED_TIME>");
    return last_modified_time.matcher(xml).replaceFirst("<LAST_MODIFIED_TIME>XXXX</LAST_MODIFIED_TIME>")
}

27 noiembrie 2019

QF teste


Basic setup

Get the ApplicationsSetup_branch.qft (the list of test suites) from STI.
Open it with QF, modify its variable definitions:
  • mainAppRootDir should point to the distribution which will be tested (which has the folders: bin, license, matlab, etc)
  • setup_version should be R9999.9999
  • create two local folders and make testDataFolder and TestResultsFolder point to them
Make sure "Name override mode" is set to "Override everything": go to Edit -> Options, check in Record -> Components and Replay -> Recognition.


Start the application

The application is run from QF itself: go to the left panel -> Procedures -> Dependency: Dependency -> Setup: Start SUT and hit the play button


Create a test

An easy way to record a run is to create a new sequence. If you go to the left panel -> Extras you will see a list of sequences and play one of them to see what it is doing.


Basic steps to create a new sequence
  1. Hit the record button
  2. Do something in your application
  3. Hit the square button to stop recording
  4. When you play the recording, a normal exit disables the Play button and nothing happens, whereas for test failure you will see an error window.

Tips

Depending on the tool you are testing, it is nice to start by deleting the current project and make a new one. Before you stop recording, it is nice to bring the screen to the same place you started from (without deleting the current project though).

Copy your input files into testDataFolder.
When you load your input files, make sure you start from a common parent of testDataFolder and testResultsFolder and then navigate to the file you need. This will make it clear for the QF tool on how to get there.

If you have to export files, export them to your testResultsFolder and navigate to it like described at (2).
Once you first exported a file, rename it using the keyword "reference" to save it as a reference.
To compare the reference file with the newly generated file, use the method shellutils.compareFiles:
  • right click on the sequence -> insert node -> procedure nodes -> procedure call
  • procedure name is "shellutils.compareFiles", variable return type is "areIdentical"
  • you need to fill out 2 variable definitions, one for referenceFile and the other for generatedFile (enter your paths)
  • you need to move the procedure call inside the body of the sequence, as its last step
  • the body of the compareFiles is located in Procedures -> Package: shellutils -> Procedure: compareFiles
  • you can use a different procedure call or make your own, if the above doesn't fit you.
Your sequence doesn't have to cover the whole flow. You can stop the sequence at any time and with the next sequence resume from where you left off.

Steps inside a sequence (such as mouse events, inputs, etc) can be moved freely to another sequence in case the use case is split. Also, if QF doesn't capture certain components, feel free to stop the sequence before QF will throw the error, and start a new sequence after you have manually fixed it or just waited for it to disappear.