{"action":"created","comment":{"url":"https://api.github.com/repos/elo7/tech-blog/pulls/comments/80471674","id":80471674,"diff_hunk":"@@ -0,0 +1,164 @@\n+---\n+title: 'Introdução ao Java'\n+date: 2016-08-19\n+category: back-end\n+layout: post\n+description: O primeiro post de uma série sobre como começar a codificar algo em Java. Nesse primeiro post você vai entender como que funciona a execução do Java no computador, além de entender sobre tipos primitivos.\n+author: tcelestino\n+tags:\n+  - java\n+---\n+\n+Entrei para o time de front-end do [Elo7](http://elo7.com.br) tem alguns meses e digo que fiquei \"assustado\" quando vi que o time mexia muito com código Java. Meu susto maior é que minha única experiência com a linguagem foi na época da faculdade, chegando apenas a desenvolver o [iSnake](https://github.com/tcelestino/iSnake). Tirando isso, posso dizer que minha experiência é `null`.\n+\n+Mas chega de história e vamos ao que interessa!\n+\n+## Instalando o Java\n+\n+Antes de começar a escrever algum código, vamos precisar verificar se já temos o Java instalado. Para descobrir se já tem o compilador Java instalado em seu computador, execute o seguinte comando no terminal:\n+\n+```bash\n+$ javac -version\n+```\n+\n+Você precisa ver uma mensagem como a que aparece na imagem abaixo:\n+\n+![Verificando se já temos o Java instalado](../images/introducao-ao-java-1.png)\n+\n+Estou usando a versão 8 do Java, provalvemente você estará usando uma outra versão, que não vai impactar por enquanto nossos primeiros passos. Agora, caso a mensagem não seja parecida com a que tem na imagem acima, recomendo esse [artigo](https://goo.gl/XfZCiB) do pessoal da Caelum que explica como fazer a instalação do Java em diversos sistemas operacionais.\n+\n+## Nossa primeira classe\n+\n+Para começarmos a fazer algum código, vamos apenas precisar do terminal e seu editor de texto preferido (Sublime, Atom, Bloco de Notas etc...). Sim, por enquanto não vamos usar nenhuma IDE, assunto que ficará para os futuros posts. Com seu editor de texto aberto, escreva (ou copie) o código abaixo:\n+\n+```Java\n+public class HelloWorld {\n+  public static void main(String[] args) {\n+    System.out.println(\"Hello World!\");\n+  }\n+}\n+```\n+\n+Salve o arquivo como *HelloWorld.java*. No terminal digite o seguinte comando:\n+\n+```bash\n+$ javac HelloWorld.java\n+```\n+\n+**Explicando:** o comando *javac* irá compilar seu *nomeClasse.java* e criar um arquivo chamado *nomeClasse.class*, no nosso caso *HelloWorld.class*.\n+\n+Depois de compilar nosso arquivo, vamos precisar executar o nosso código compilado. Rode o comando:\n+\n+```bash\n+$ java HelloWorld\n+```\n+\n+**Explicando:** o comando *java* irá executar o nosso arquivo compilado.\n+\n+![Nossa primeira classe: Hello World!](../images/introducao-ao-java-2.png)\n+\n+**Nota:** Todos os exemplos de código que serão usados nos posts, estarão disponíveis [nesse repositório](http://github.com/tcelestino/intro-java)\n+\n+## Entendendo tipos primitivos\n+\n+No Java, precisamos sempre definir o tipo das variáveis que não poderá ser modificada em qualquer momento da execução do código. Existem 8 tipos de dados primitivos (char, boolean, byte, int, short, long, float e double). Vou explicar algumas delas.\n+\n+### int\n+\n+Variáveis do tipo *int* armazenam valores inteiros. Além disso, podemos realizar operações matemáticas (somar, subtrair, dividir, multiplicar, etc..) com os valores armazenados. Segue um exemplo:\n+\n+```java\n+public class ExampleInt {\n+  public static void main(String[] args) {\n+    int bornYear = 1987;\n+    int actualYear = 2016;\n+    int myAge = bornYear - actualYear;\n+    int myNewAge = myAge + 1;\n+\n+    System.out.println(myAge);\n+    System.out.println(myNewAge);\n+  }\n+}\n+```\n+\n+### double\n+\n+Em variavéis do tipo *double*, podemos armazenar valores com pontos flutuantes (Ex.: 1.89) e além desses valores fracionados, o *double* também aceita números inteiros. E assim como nas variáveis do tipo *int* é possível fazer operações matemáticas.\n+\n+```java\n+public class ExampleDouble {\n+  public static void main(String[] args) {\n+    double dollar = 3.20;\n+    double weight = 75;\n+    double count = weight / 3;\n+\n+    System.out.println(dollar);\n+    System.out.println(weight);\n+    System.out.println(count);\n+  }\n+}\n+```\n+\n+**Nota:** assim como o *double*, existe o tipo *float* que também aceita valores fracionados, sendo que a diferença entre eles fica pela quantidade de bytes que cada um pode suportar. No **float** são 4 bytes e no *double* 8 bytes.\n+\n+### char\n+\n+Variáveis do tipo *char* apenas podem receber um caractere. Ou seja, você não pode escrever um texto, ou definir um número para ela.\n+\n+```java\n+public class ExampleChar {\n+  public static void main(String[] args) {\n+    char e = 'e';\n+\n+    System.out.println(e);\n+  }\n+}\n+```\n+\n+Vale anotar que variáveis desse tipo não podem receber um valor vazio (Ex.: char d = ''), isso porque um valor vazio não é um caractere.\n+\n+### boolean\n+\n+Variáveis do tipo *boolean* apenas possuem dois valores: *true* ou *false*. As palavras *true* e *false*, no Java são palavras reservadas, ou seja, só podem ser usadas em variáveis que são do tipo *boolean*.\n+\n+```java\n+public class ExampleBoolean {\n+  public static void main(String[] args) {\n+    int myAge = 29;\n+    boolean isBrazilian = true;\n+    boolean isOldMan = myAge > 50; // expressão booleana\n+\n+    System.out.println(isBrazilian);\n+    System.out.println(isOldMan);\n+  }\n+}\n+```\n+\n+Agora, se tentarmos adicionar valores que não seja do tipo definido, o que pode acontecer? Vamos criar um arquivo que vamos chamar de *MyPersonalInfo.java* e vamos escrever (pode copiar) o código abaixo:","path":"src/posts/introducao-ao-java.html.md","position":137,"original_position":137,"commit_id":"7244a79f63fef2cc462c8bfe50f3a50fce79c56a","original_commit_id":"7244a79f63fef2cc462c8bfe50f3a50fce79c56a","user":{"login":"luiz","id":46065,"avatar_url":"https://avatars.githubusercontent.com/u/46065?v=3","gravatar_id":"","url":"https://api.github.com/users/luiz","html_url":"https://github.com/luiz","followers_url":"https://api.github.com/users/luiz/followers","following_url":"https://api.github.com/users/luiz/following{/other_user}","gists_url":"https://api.github.com/users/luiz/gists{/gist_id}","starred_url":"https://api.github.com/users/luiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luiz/subscriptions","organizations_url":"https://api.github.com/users/luiz/orgs","repos_url":"https://api.github.com/users/luiz/repos","events_url":"https://api.github.com/users/luiz/events{/privacy}","received_events_url":"https://api.github.com/users/luiz/received_events","type":"User","site_admin":false},"body":"Aqui não é `sejam` ao invés de `seja`?\r\n\r\n@FernandaBernardo ","created_at":"2016-09-26T13:16:27Z","updated_at":"2016-09-26T13:16:27Z","html_url":"https://github.com/elo7/tech-blog/pull/16#discussion_r80471674","pull_request_url":"https://api.github.com/repos/elo7/tech-blog/pulls/16","_links":{"self":{"href":"https://api.github.com/repos/elo7/tech-blog/pulls/comments/80471674"},"html":{"href":"https://github.com/elo7/tech-blog/pull/16#discussion_r80471674"},"pull_request":{"href":"https://api.github.com/repos/elo7/tech-blog/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/elo7/tech-blog/pulls/16","id":83000412,"html_url":"https://github.com/elo7/tech-blog/pull/16","diff_url":"https://github.com/elo7/tech-blog/pull/16.diff","patch_url":"https://github.com/elo7/tech-blog/pull/16.patch","issue_url":"https://api.github.com/repos/elo7/tech-blog/issues/16","number":16,"state":"open","locked":false,"title":"Introdução ao Java","user":{"login":"tcelestino","id":190265,"avatar_url":"https://avatars.githubusercontent.com/u/190265?v=3","gravatar_id":"","url":"https://api.github.com/users/tcelestino","html_url":"https://github.com/tcelestino","followers_url":"https://api.github.com/users/tcelestino/followers","following_url":"https://api.github.com/users/tcelestino/following{/other_user}","gists_url":"https://api.github.com/users/tcelestino/gists{/gist_id}","starred_url":"https://api.github.com/users/tcelestino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tcelestino/subscriptions","organizations_url":"https://api.github.com/users/tcelestino/orgs","repos_url":"https://api.github.com/users/tcelestino/repos","events_url":"https://api.github.com/users/tcelestino/events{/privacy}","received_events_url":"https://api.github.com/users/tcelestino/received_events","type":"User","site_admin":false},"body":"Primeiro post sobre como iniciar a programar Java.","created_at":"2016-08-27T22:31:35Z","updated_at":"2016-09-26T13:37:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f55eae6cbe3a042efac3020154053e0ea46c2bed","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/elo7/tech-blog/pulls/16/commits","review_comments_url":"https://api.github.com/repos/elo7/tech-blog/pulls/16/comments","review_comment_url":"https://api.github.com/repos/elo7/tech-blog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elo7/tech-blog/issues/16/comments","statuses_url":"https://api.github.com/repos/elo7/tech-blog/statuses/7244a79f63fef2cc462c8bfe50f3a50fce79c56a","head":{"label":"elo7:introducao-ao-java","ref":"introducao-ao-java","sha":"7244a79f63fef2cc462c8bfe50f3a50fce79c56a","user":{"login":"elo7","id":1469534,"avatar_url":"https://avatars.githubusercontent.com/u/1469534?v=3","gravatar_id":"","url":"https://api.github.com/users/elo7","html_url":"https://github.com/elo7","followers_url":"https://api.github.com/users/elo7/followers","following_url":"https://api.github.com/users/elo7/following{/other_user}","gists_url":"https://api.github.com/users/elo7/gists{/gist_id}","starred_url":"https://api.github.com/users/elo7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elo7/subscriptions","organizations_url":"https://api.github.com/users/elo7/orgs","repos_url":"https://api.github.com/users/elo7/repos","events_url":"https://api.github.com/users/elo7/events{/privacy}","received_events_url":"https://api.github.com/users/elo7/received_events","type":"Organization","site_admin":false},"repo":{"id":61552932,"name":"tech-blog","full_name":"elo7/tech-blog","owner":{"login":"elo7","id":1469534,"avatar_url":"https://avatars.githubusercontent.com/u/1469534?v=3","gravatar_id":"","url":"https://api.github.com/users/elo7","html_url":"https://github.com/elo7","followers_url":"https://api.github.com/users/elo7/followers","following_url":"https://api.github.com/users/elo7/following{/other_user}","gists_url":"https://api.github.com/users/elo7/gists{/gist_id}","starred_url":"https://api.github.com/users/elo7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elo7/subscriptions","organizations_url":"https://api.github.com/users/elo7/orgs","repos_url":"https://api.github.com/users/elo7/repos","events_url":"https://api.github.com/users/elo7/events{/privacy}","received_events_url":"https://api.github.com/users/elo7/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elo7/tech-blog","description":"Blog técnico do Elo7","fork":false,"url":"https://api.github.com/repos/elo7/tech-blog","forks_url":"https://api.github.com/repos/elo7/tech-blog/forks","keys_url":"https://api.github.com/repos/elo7/tech-blog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elo7/tech-blog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elo7/tech-blog/teams","hooks_url":"https://api.github.com/repos/elo7/tech-blog/hooks","issue_events_url":"https://api.github.com/repos/elo7/tech-blog/issues/events{/number}","events_url":"https://api.github.com/repos/elo7/tech-blog/events","assignees_url":"https://api.github.com/repos/elo7/tech-blog/assignees{/user}","branches_url":"https://api.github.com/repos/elo7/tech-blog/branches{/branch}","tags_url":"https://api.github.com/repos/elo7/tech-blog/tags","blobs_url":"https://api.github.com/repos/elo7/tech-blog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elo7/tech-blog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elo7/tech-blog/git/refs{/sha}","trees_url":"https://api.github.com/repos/elo7/tech-blog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elo7/tech-blog/statuses/{sha}","languages_url":"https://api.github.com/repos/elo7/tech-blog/languages","stargazers_url":"https://api.github.com/repos/elo7/tech-blog/stargazers","contributors_url":"https://api.github.com/repos/elo7/tech-blog/contributors","subscribers_url":"https://api.github.com/repos/elo7/tech-blog/subscribers","subscription_url":"https://api.github.com/repos/elo7/tech-blog/subscription","commits_url":"https://api.github.com/repos/elo7/tech-blog/commits{/sha}","git_commits_url":"https://api.github.com/repos/elo7/tech-blog/git/commits{/sha}","comments_url":"https://api.github.com/repos/elo7/tech-blog/comments{/number}","issue_comment_url":"https://api.github.com/repos/elo7/tech-blog/issues/comments{/number}","contents_url":"https://api.github.com/repos/elo7/tech-blog/contents/{+path}","compare_url":"https://api.github.com/repos/elo7/tech-blog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elo7/tech-blog/merges","archive_url":"https://api.github.com/repos/elo7/tech-blog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elo7/tech-blog/downloads","issues_url":"https://api.github.com/repos/elo7/tech-blog/issues{/number}","pulls_url":"https://api.github.com/repos/elo7/tech-blog/pulls{/number}","milestones_url":"https://api.github.com/repos/elo7/tech-blog/milestones{/number}","notifications_url":"https://api.github.com/repos/elo7/tech-blog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elo7/tech-blog/labels{/name}","releases_url":"https://api.github.com/repos/elo7/tech-blog/releases{/id}","deployments_url":"https://api.github.com/repos/elo7/tech-blog/deployments","created_at":"2016-06-20T14:14:12Z","updated_at":"2016-08-03T16:47:40Z","pushed_at":"2016-09-12T19:56:17Z","git_url":"git://github.com/elo7/tech-blog.git","ssh_url":"git@github.com:elo7/tech-blog.git","clone_url":"https://github.com/elo7/tech-blog.git","svn_url":"https://github.com/elo7/tech-blog","homepage":null,"size":3294,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":0,"default_branch":"master"}},"base":{"label":"elo7:master","ref":"master","sha":"5767dde5dba4bff64a01f26386987e3728c722f4","user":{"login":"elo7","id":1469534,"avatar_url":"https://avatars.githubusercontent.com/u/1469534?v=3","gravatar_id":"","url":"https://api.github.com/users/elo7","html_url":"https://github.com/elo7","followers_url":"https://api.github.com/users/elo7/followers","following_url":"https://api.github.com/users/elo7/following{/other_user}","gists_url":"https://api.github.com/users/elo7/gists{/gist_id}","starred_url":"https://api.github.com/users/elo7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elo7/subscriptions","organizations_url":"https://api.github.com/users/elo7/orgs","repos_url":"https://api.github.com/users/elo7/repos","events_url":"https://api.github.com/users/elo7/events{/privacy}","received_events_url":"https://api.github.com/users/elo7/received_events","type":"Organization","site_admin":false},"repo":{"id":61552932,"name":"tech-blog","full_name":"elo7/tech-blog","owner":{"login":"elo7","id":1469534,"avatar_url":"https://avatars.githubusercontent.com/u/1469534?v=3","gravatar_id":"","url":"https://api.github.com/users/elo7","html_url":"https://github.com/elo7","followers_url":"https://api.github.com/users/elo7/followers","following_url":"https://api.github.com/users/elo7/following{/other_user}","gists_url":"https://api.github.com/users/elo7/gists{/gist_id}","starred_url":"https://api.github.com/users/elo7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elo7/subscriptions","organizations_url":"https://api.github.com/users/elo7/orgs","repos_url":"https://api.github.com/users/elo7/repos","events_url":"https://api.github.com/users/elo7/events{/privacy}","received_events_url":"https://api.github.com/users/elo7/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elo7/tech-blog","description":"Blog técnico do Elo7","fork":false,"url":"https://api.github.com/repos/elo7/tech-blog","forks_url":"https://api.github.com/repos/elo7/tech-blog/forks","keys_url":"https://api.github.com/repos/elo7/tech-blog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elo7/tech-blog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elo7/tech-blog/teams","hooks_url":"https://api.github.com/repos/elo7/tech-blog/hooks","issue_events_url":"https://api.github.com/repos/elo7/tech-blog/issues/events{/number}","events_url":"https://api.github.com/repos/elo7/tech-blog/events","assignees_url":"https://api.github.com/repos/elo7/tech-blog/assignees{/user}","branches_url":"https://api.github.com/repos/elo7/tech-blog/branches{/branch}","tags_url":"https://api.github.com/repos/elo7/tech-blog/tags","blobs_url":"https://api.github.com/repos/elo7/tech-blog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elo7/tech-blog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elo7/tech-blog/git/refs{/sha}","trees_url":"https://api.github.com/repos/elo7/tech-blog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elo7/tech-blog/statuses/{sha}","languages_url":"https://api.github.com/repos/elo7/tech-blog/languages","stargazers_url":"https://api.github.com/repos/elo7/tech-blog/stargazers","contributors_url":"https://api.github.com/repos/elo7/tech-blog/contributors","subscribers_url":"https://api.github.com/repos/elo7/tech-blog/subscribers","subscription_url":"https://api.github.com/repos/elo7/tech-blog/subscription","commits_url":"https://api.github.com/repos/elo7/tech-blog/commits{/sha}","git_commits_url":"https://api.github.com/repos/elo7/tech-blog/git/commits{/sha}","comments_url":"https://api.github.com/repos/elo7/tech-blog/comments{/number}","issue_comment_url":"https://api.github.com/repos/elo7/tech-blog/issues/comments{/number}","contents_url":"https://api.github.com/repos/elo7/tech-blog/contents/{+path}","compare_url":"https://api.github.com/repos/elo7/tech-blog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elo7/tech-blog/merges","archive_url":"https://api.github.com/repos/elo7/tech-blog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elo7/tech-blog/downloads","issues_url":"https://api.github.com/repos/elo7/tech-blog/issues{/number}","pulls_url":"https://api.github.com/repos/elo7/tech-blog/pulls{/number}","milestones_url":"https://api.github.com/repos/elo7/tech-blog/milestones{/number}","notifications_url":"https://api.github.com/repos/elo7/tech-blog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elo7/tech-blog/labels{/name}","releases_url":"https://api.github.com/repos/elo7/tech-blog/releases{/id}","deployments_url":"https://api.github.com/repos/elo7/tech-blog/deployments","created_at":"2016-06-20T14:14:12Z","updated_at":"2016-08-03T16:47:40Z","pushed_at":"2016-09-12T19:56:17Z","git_url":"git://github.com/elo7/tech-blog.git","ssh_url":"git@github.com:elo7/tech-blog.git","clone_url":"https://github.com/elo7/tech-blog.git","svn_url":"https://github.com/elo7/tech-blog","homepage":null,"size":3294,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elo7/tech-blog/pulls/16"},"html":{"href":"https://github.com/elo7/tech-blog/pull/16"},"issue":{"href":"https://api.github.com/repos/elo7/tech-blog/issues/16"},"comments":{"href":"https://api.github.com/repos/elo7/tech-blog/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/elo7/tech-blog/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/elo7/tech-blog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elo7/tech-blog/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/elo7/tech-blog/statuses/7244a79f63fef2cc462c8bfe50f3a50fce79c56a"}}}}
{"actor":{"display_login":"luiz"}}