the world is a pixel
Integer.MAX_VALUE and Integer.MIN_VALUE
You should know that variable values are cyclic in Java.
public class Test{ public static void main(String args[]){ System.out.println(Integer.MAX_VALUE); System.out.println(Integer.MIN_VALUE); int x = Integer.MAX_VALUE + 1; System.out.println(x); } }
This produces:
2147483647
-2147483648
-2147483648
You must be logged in to post a comment.
No trackbacks yet.
Android screen height and width
12 March, 2011 - 9:30 pm
Tags: Android, Java, mobile, programming, screensize
Posted in english | 1 comment
Context ctx = getContext(); Display display = ((WindowManager)ctx.getSystemService(ctx.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); Yes, there are easier ways to retrieve the screen width on Android but there are cases that this long code is the only solution. You may already have the Context. WindowManager or the Display and so it would be [...]
Java: invoking a method by name
29 April, 2010 - 10:29 am
Tags: Class, Java, method, programming, Reflection
Posted in english | 2 comments
import java.lang.reflect.*; public class Foo { public void bar(int param){ System.out.println(param); } public static void main(String args[]){ Object f = new Foo(); try { Method m = f.getClass().getMethod("bar", int.class); m.invoke(f, 42); } catch (Exception e){ System.err.println(e); } } } $ java Foo 42
calling commands in Java
8 April, 2010 - 1:09 pm
Tags: getruntime, Java, programming, runtime
Posted in english | No comments
I don’t like the approach of calling native shell commands in any language instead of using multi platform libraries, but here is a little prof of concept Java program to call native commands. import java.io.*; import java.util.*; public class Exec { public static void main(String args[]) throws IOException { Process proc = Runtime.getRuntime().e xec(args); BufferedReader [...]
Iterating over a HashMap
8 April, 2010 - 11:22 am
Tags: collections, enhanced loop, foreach, hashmap, iterating, Java, programming
Posted in english | No comments
Iterating over a HashMap using the enhanced loop (foreach) in Java is a good way to keep your code smaller, more legible and usually more semantically coherent. import java.util.HashMap; import java.util.Map; class Foo {} public class Main { public static void main(String args[]){ Map<Byte, Foo> mHash; mHash = new HashMap<Byte, Foo>(); [...]
Getting enviroment information on Android
16 March, 2010 - 10:18 am
Tags: Android, Eclipse, Java, programming, who am i, whoami
Posted in english | 8 comments
This is a simple program I wrote called Who Am I that shows informations about the device which it is running. Which can be useful for developers and maybe advanced users. Download: WhoAmI.tar.bz2 – Eclipse project. It’s configured for Android platform 4 (1.6) but should work without problems in newer Android platform versions. WhoAmI.apk – [...]
The Caps Lock Java Socket Server
27 February, 2010 - 9:39 pm
Tags: caps lock, Java, programming, socket, upcase
Posted in english | 3 comments
Here is a simple server for those who are starting studying sockets or just needs a simple socket server example for reuse while writing your own behavior. Features: A client should enter a string and the server would answer the same string, with each symbol in up case, when possible. Default port at 8080. One [...]
Beware the locale
22 February, 2010 - 5:16 pm
Tags: development, i18n, Java, JUnit, locale, programming, String, teste unitário, toString, unit testing
Posted in english | No comments
Today I was programming a toString method for a class widely used in a application, using the very useful String.format that provides a C’s like printf formatter. @Override public String toString() { return String.format("VO[a: %.1f, b: %.1f, c: %.1f]", a, b, a+b); } %.1f means a float with one digit precision after the dot separator. [...]
Java Font List
5 January, 2010 - 6:10 pm
Tags: AWT, fonts, Java, JVM, Larabie, Larabie Fonts, programming
Posted in english | Comments Off
Here’s a program that lists fonts available in your JVM. You can also set the environment variable JAVA_FONTS to specify the font directory. import java.awt.GraphicsEnvironment; public class ListFonts { public static void main(String args[]){ GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); for(String font:e.getAvailableFontFamilyNames()){ System.out.println(font); } } } By using pipes you can count how many fonts you [...]
Tiled TMX Map Loader for Pygame
I’m using the Tiled Map Editor for a while, I even wrote that tutorial about it. It’s a general purpose tile map editor, written in Java but now migrating to C++ with Qt, that can be easily used with my set of free pixelart tiles. A map done with Tiled is stored in a file [...]
OpenCV: adding two images
8 December, 2009 - 1:55 am
Tags: C, code, Computer Vision, cvadd, opencv, programming, surfer, universe, wikimedia
Posted in english | 8 comments
This is a very simple example of how to open two images and display them added. I got two pictures at project Commons from Wikimedia that were highlighted on Featured Pictures. I did a crop on both to have the same size, as I’m trying to make this example as simple as possible. The first [...]













12 April, 2008 - 10:11 am
Na verdade, não é que os valores de variáveis de java são cíclicos, é uma coisa de arquitetura, de máquina mesmo os 31bits foram usados por completos, mas o assembler incrementa de qualquer jeito, então o valor vai para o bit 32, mas sabe-se que isso torna um número negativo, segundo a codificação complemento de 2. Em C/C++ acontece a mesma coisa. “Programando” em assembler, é possível ver isso, facilmente. Não sei se existe alguma linguagem que faz esse tipo de tratamento, mas as que eu vi até hoje, esse “erro” acontece simplesmente porque não tem a ver com elas, mas sim com a capacidade da máquina e a arquitetura.
12 April, 2008 - 3:05 pm
@Onilton Maciel,
mais ou menos, eu encaro esse comportamento cíclico como uma convenção.
Por exemplo em Ruby se eu pegar uma variável to typo Fixint e ir incrementando incrementando, ela vai chegar um momento que ela se tornará um Bignum. A conversão é feita automaticamente. Acho que Python também se comportaria assim. Legal, né?
15 April, 2008 - 7:16 am
http://en.wikipedia.org/wiki/Computer_numbering_formats#Numbers_in_programming_languages
Concordo com você, mas eu vejo assim, a diferença é que C/C++, Java e algumas outras linguagens não dão tratamento nenhum, por isso o comportamento cíclico acontece, por causa da forma que o número é pensado, complemento de 2. Eles (Java/C) não convencionaram nada, apenas por preguiça (hehe ou tradição, característica do nível da linguagem mesmo, ou sei lá), não aplicaram tratamento nenhum.
http://en.wikipedia.org/wiki/Computer_numbering_formats#Two.27s_complement
Em linguagens com um nível mais alto, como python, ruby, como você falou, esse tratamento é feito, e nesse caso há convenções! ;)
Mas, mudando de assunto, você tem o solaris na sua máquina?
Eu não consegui baixar uma iso, elas têm 1.2GB!!!! Eu só queria fazer um teste….
Sabe se o comando od funciona em um diretório vazio? E o que ele retorna?
16 April, 2008 - 4:42 pm
@Onilton, tenho um Solaris Express Developer Edition (que é uma distribuição do OpenSolaris) instalada em minha máquina.
Em que estado você mora? Você pode pedir um Starter Kit que é enviado para sua casa.
17 April, 2008 - 11:08 am
Amazonas :P…. Vai demorar muito para chegar… Eu acho que vou tentar baixar mesmo… Era só uma pergunta, para ver se eu evitava o trabalho de baixar o SO… que é muito grande.
29 April, 2008 - 2:53 pm
gostaria de saber pq vc usou Integer.MAX_VALUE..pra que serve isso??
29 April, 2008 - 3:48 pm
@deborah,
Integer.MAX_VALUE retorna o maior valor do tipo inteiro. No exemplo, 2147483647.