buy lasix http://all-treatment.org/buy-levitra-vardenafil/ http://all-treatment.org/buy-viagra-sildenafil-citrat/ isotretinoin online buy cialis online
12 gen. 2017

String.intern

Author: Joaquim Perez Noguer | Filed under: Ciència i tecnologia

Java ofereix un sistema intern per optimitzar la memòria utilitzada quan llegeixes grans quantitats de texts i té molts repetits: String.intern, però cal anar amb compte.

Vegeu les recomanacions String.intern in Java 6, 7 and 8 – string pooling  – Java Performance Tuning Guide

  • Stay away from String.intern() method on Java 6 due to a fixed size memory area (PermGen) used for JVM string pool storage.
  • Java 7 and 8 implement the string pool in the heap memory. It means that you are limited by the whole application memory for string pooling in Java 7 and 8.
  • Use -XX:StringTableSize JVM parameter in Java 7 and 8 to set the string pool map size. It is fixed, because it is implemented as a hash map with lists in the buckets. Approximate the number of distinct strings in your application (which you intend to intern) and set the pool size equal to some prime number close to this value multiplied by 2 (to reduce the likelihood of collisions). It will allow String.intern to run in the constant time and requires a rather small memory consumption per interned string (explicitly used Java WeakHashMap will consume 4-5 times more memory for the same task).
  • The default value of -XX:StringTableSize parameter is 1009 in Java 6 and Java 7 until Java7u40. It was increased to 60013 in Java 7u40 (same value is used in Java 8 as well).
  • If you are not sure about the string pool usage, try -XX:+PrintStringTableStatistics JVM argument. It will print you the string pool usage when your program terminates.

 



12 gen. 2017

Anatomia d’un objecte Java

Author: Joaquim Perez Noguer | Filed under: Ciència i tecnologia

Com guarda el Java els objectes en memòria? T’ho explica  From Java code to Java heap

When your Java code uses the new operator to create an instance of a Java object, much more data is allocated than you might expect.

For example, it might surprise you to know that the size ratio of an int value to an Integer object — the smallest object that can hold an int value — is typically 1:4. The additional overhead is metadata that the JVM uses to describe the Java object, in this case an Integer.

The amount of object metadata varies by JVM version and vendor, but it typically consists of:

Class : A pointer to the class information, which describes the object type. In the case of a java.lang.Integer object, for example, this is a pointer to the java.lang.Integer class.

Flags : A collection of flags that describe the state of the object, including the hash code for the object if it has one, and the shape of the object (that is, whether or not the object is an array).

Lock : The synchronization information for the object — that is, whether the object is currently synchronized.

The object metadata is then followed by the object data itself, consisting of the fields stored in the object instance. In the case of a java.lang.Integer object, this is a single int.So, when you create an instance of a java.lang.Integer object when running a 32-bit JVM, the layout of the object might look like Figure 2:Figure 2. Example layout of a java.lang.Integer object for a 32-bit Java processExample layout of a java.lang.Integer object for a 32-bit Java processAs Figure 2 shows, 128 bits of data are used to store the 32 bits of data in the int value, because the object metadata uses the rest of those 128 bits.

 



14 des. 2016

Trucs amb el Java

Author: Joaquim Perez Noguer | Filed under: Ciència i tecnologia

Mirant  What are some cool Java tricks? – Quora

He trobat algunes curiositats interessants amb el Java:

Double bracing Lists allows you to declare and initialize without Arrays.asList()
List<String> places = new ArrayList<String>() {
{ add(“x”); add(“y”); }
};

Joint-union in generic type params
public class Baz<T extends Foo & Bar> {}

Define, instantiate, and call all at once
new Object() {
void hi(String in) {
System.out.println(in);
}
}.hi(“weird”);

Detect deadlocks
public static class DeadLockDetector extends Thread {
@Override
public void run() {
while(true) {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
long[] ids = threadMXBean.findDeadlockedThreads();
if (ids != null) {
System.exit(127);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) { }
}
}
}

Unsafe… (it’s like Super User mode for Java… dangerous but powerful). Understanding sun.misc.Unsafe
public void testObjectCreation() throws Exception {
ClassWithExpensiveConstructor instance =    (ClassWithExpensiveConstructor)
unsafe.allocateInstance(ClassWithExpensiveConstructor.class);
assertEquals(0, instance.getValue());
}

Però el que el millor sense cap dubte és el que es pot fer amb Reflection:

    import java.lang.reflect.Field;

public class MutableString {

public static void main(String[] args) throws Exception {
String someString = “IMMUTABLE”;
Field field = Class.forName(“java.lang.String”).getDeclaredField(“value”);
field.setAccessible(true);
char[] value = (char []) field.get(someString);
String anotherString = “NOTREALLY”;
for (int i=0; i<value.length; i++){
char c = anotherString.toCharArray()[i];
value[i]=c;
}

System.out.println(someString); // prints NOTREALLY
System.out.println(“IMMUTABLE”); // WTF !!! prints NOTREALLY
}
}

 

 



12 des. 2016

KaiRo: I Want an Internet of Humans

Author: Joaquim Perez Noguer | Filed under: Seguretat

On the Internet, not so much. We interact with and through a machine, see an “account” on the other end, remove all the context of what was said before and after, of the tone of voice and body language, of what surroundings others are in, we reduce to a few words that are convenient to type or what the communication system limits us to – and we go for whatever gives us the most attention. Because we don’t actually feel like we interact with other real humans, it’s mostly about what we get out of it. A lot of likes, reshares, replies, interactions. It helps that the services we use maximize whatever their KPI are and not optimize for what people actually want – after all, they want to earn money and that means having a lot of activity, and making people happy is not an actual goal, at best a wishful side effect.

We need to change that. We need to make social media actually social again (this talk by Chris Heilmann is really worth watching).We need to spread love (“make Trek, not Wars” in a tounge-in-cheek kind of way, no meaning negativity towards any franchise, but thinking about meanings and how we can make things better for our neighbors, our community, our world), not even hate the fear or fear the hate (which leads back into the circle), but analyze it, take it seriously and break it down. If we understand it, know how to deal with it, but not let it overcome us, fear can even be healthy – as another great screenwriter put it “Fear only exists for one purpose: To be conquered”. That is where we need to get ourselves, and need to help those other humans end up that spread hate and unreflected fear – or act out of that. Not by hating them back, but by trying to understand and help them.

We need to see the people, the humans, behind what we read on the Internet (I deeply recommend for you to watch this very recent talk by Erika Baker as well). I don’t see it as a “Crusade against Internet hate” as mentioned in the end of that talk, but more as a “Rally for Internet love” (unfortunately, some people would ridicule that wording but I see it as the love of humanity, the love for the human being inside each and everyone of us). I’m always finding it mind-blowing that every single person I see around me, that reads this, that uses some software I helped with, and every single other person on this planet (or in its orbit, there are none out further at this time as far as I know), is a fully, thinking, feeling, caring human being. Every one of those is different, every one of those has their own thoughts and fears that need to be addressed and that we need to address. And every one of those wants to be loved. And they should be. No matter who they voted for. No matter if they are a president elect or a losing candidate. We don’t need to agree with everything they are saying. But their fears should be addressed and conquered. And yes, they should be loved. Their differences should be celebrated and their commonalities embraced at the same time. Yes, that’s possible, think about it. Again, see the philosophy of infinite diversity in infinite combinations.

I want an Internet that connects those humans, brings them closer together, makes them understand each other more, makes them love each other’s humanity. I don’t care how many “things” we connect to the Internet, I care that the needs and feelings of humans and their individual and shared lives improve. I care that their devices and gadgets are their own, help their individuality, and help them embrace other humans (not treat them as accounts and heaps to data to be analyzed and sold stuff to). I want everyone to see that everyone else is (just) human, and spread love to or at least embrace them as humans. Then the world, the humans in it, and myself, can make it out of the difficult times and live long and prosper in the future.

I want an Internet of humans.

Origen: Home of KaiRo: I Want an Internet of Humans

12 des. 2016

Previsió de la ciber-seguretat pel 2017

Author: Joaquim Perez Noguer | Filed under: Seguretat

Este 2016 ha resultado ser otro año devastador para las brechas de ciberseguridad, tanto en pequeñas y grandes empresas como a nivel usuario. Los ataques a las cuentas de Yahoo, Twitter y el bitcoin han demostrado una vez más que nadie es inmune a los hackers y que son cada vez más sofisticados. Los virus siguen reinventándose y aumentando y se dirigen a los datos de más valor: números de la seguridad social, tarjetas de crédito, datos de salud, correos electrónicos y contraseñas. De cara a 2017, los expertos del foro ESET de seguridad informática adelantan cuáles serán las amenazas a tener en cuenta. Los ataques informáticos se centrarán el próximo año en las aplicaciones móviles, los videojuegos, el internet de las cosas, los gadgets de la salud y las infraestructuras críticas, como la administración pública, el sistema financiero y la industria nuclear.

Origen: Estas son las ciberamenazas de 2017 | Tecnología | EL PAÍS

11 des. 2016

Atlas històrics

Author: Joaquim Perez Noguer | Filed under: Ciència i tecnologia

Recull de diversos atlas historics via web o via vídeo.

Web:

 

 

 

 

23 nov. 2016

IA per llegir els llavis

Author: Joaquim Perez Noguer | Filed under: Ciència i tecnologia

Origen: Ya puede apuntar ‘leer los labios’ en ‘cosas que la IA hace mejor que los humanos’ – MIT Technology Review

21 nov. 2016

Mecànica quàntica

Author: Joaquim Perez Noguer | Filed under: Ciència i tecnologia

En la física quàntica tenim coses molt curioses:

  • Els fotons es poden comportar com a partícules. La llum pot fer moure objectes.
  • Els fotons es poden comportar com a ones. Els fotons quan passen un obertura molt petita, no passen rectes sinó que es difracten, fins i tot quan passen d’un en un!
  • Dos partícules es poden entrellaçar i el que li passi a una afectarà immediatament a l’altra tot i que estiguin molt separades

Una de les explicacions que es donava fins ara era que les partícules podien estar a més d’un lloc alhora i tenir més d’un estat alhora. I si això era així aleshores es produiria la paradoxa del Gat de Schrodinger.

Una altra solució ens l’expliquen en el següent vídeo. I si les partícules quàntiques fossin com pedres damunt d’un llac, “rebotant” infinitament. Les partícules provocarien ones i les ones provocarien canvis en la direcció de les partícules. I fent això es podrien explicar molts dels estranys fenòmens de la quàntica:

 

21 nov. 2016

CSS  display:grid  i  display:flex

Author: Joaquim Perez Noguer | Filed under: Web

Interessant tutorial de com utilitzar els nous modes display en CSS per a fer dissenys i layouts ben acabats.

Un dels problemes de sempre del HTML i el CSS és com posicionar bé els elements a la pantalla i que pugui mostrar-se bé encara que canviï la mida o l’orientació.

En un inici es feia servir TABLE quan TABLE era per mostrar taules de dades no per posicionar.

Després es va fer servir el float:left, quan el float estava pensat per mostrar il·lustracions junt amb el text a una banda o l’altra.

Finalment el CSS ha creat un sistema dedicat a posicionar bé els elements a la pantalla  display:flex  i display:grid.

Vegeu-ne l’explicació a  CSS Grid, Flexbox And Box Alignment: Our New System For Web Layout – Smashing Magazine

 

Més informació:

 

 

 

21 nov. 2016

Microsoft Goes All In for Linux

Author: Joaquim Perez Noguer | Filed under: Linux

La realitat sempre supera la ficció i  ara tenim:

I en un futur tindrem també

  • SQL Server i Azure per Linux
  • Tizen, el SO basat en Linux de Samsung, disposarà de Visual Studio i aplicacions .Net

Origen: Microsoft Goes All In for Linux