• Nenhum resultado encontrado

IPM 10/11 – P1 Introduction to Java

N/A
N/A
Protected

Academic year: 2023

Share "IPM 10/11 – P1 Introduction to Java"

Copied!
15
0
0

Texto

(1)

Licenciatura em Ciência de Computadores

IPM 10/11 – P1

Introduction to Java

Miguel Tavares Coimbra

(2)

Summary

• Introduction to Java

– Why Java?

– Characteristics – Syntax

– Eclipse IDE

(3)

Why Java?

• We have been studying Human-Machine Interaction.

• We have talked about the design triangle:

– Objective, Technology, User

• But how do we test our solution?

– We need technology.

– Java is simple. (although we could also have

chosen other languages...)

(4)

Our course and Java

• Tutorials will involve programming in Java.

• More specifically with:

– Java AWT – Java Swing

• Why?

– Easy.

– Close to other languages you have learned (C).

– Simple libraries for graphical user interfaces.

• How?

– We will use the Eclipse IDE.

(5)

Generic characteristics of Java - I

• The nice stuff

– Abstract machine (runs on every OS).

– Memory management.

– Object-oriented.

– Vast API

• Simple Graphic libraries.

– AWT

– Swing

(6)

Generic characteristics of Java - II

• The not so nice stuff

– API instability.

– API complexity (sometimes...).

– Low efficiency – Half as fast as C

• Some references:

– Tutoriais e FAQs da Sun

http://java.sun.com/docs/books/tutorial/

– Java Linux http://www.blackdown.org/java-linux.html

(7)

Basic syntax

• Similarity with C/C++:

– Instructions syntax – Variable declarations – Expressions

– Explicit conversions (type casting)

• Specific characteristics:

– Exclusively object-oriented

• All code is inside a class.

• Everything is an object.

• Exception: Intrinsic data types (real numbers, booleans and characters).

– Memory management

• Garbage collection

(8)

More syntax

• The main „function‟ executes the program.

• Instructions end with “;”

• A class is equivalent to a C module.

• The delimiters for comments are:

– /* and */

– // until the end of the line.

(9)

Hello World in Java

/*

Hello World in Java

*/

class ola {

public static void main(String[] arg) { // let‟s write “hello World"

System.out.println(“hello World");

}

}

(10)

Variables, expressions and control

• Variables are declared and used like in C

• Expressions like in C except:

Operator + is overloaded.

• Execution control resembles C (boolean tests)

• Initial parameters are an Array of Strings

// ECHO in java class echo

{

public static void main(String[] arg) {

int i;

for(i=0; i<arg.length; i++)

System.out.print(arg[i]+“ “ );

System.out.println("");

} }

(11)

Methods

• Sub-routines are used just like in C.

• They are called

Methods, and are inside classes.

• Need to declare types for arguments and

return value.

// Factorial class fact {

public static void main (String args[]) {

int n;

System.out.println("n\tn!");

for(n=0; n<10; n++)

System.out.println(n+"\t"+fact(n));

}

int fact(int n) {

if(n==0) return 1;

else return n*fact(n-1);

} }

(12)

Java IDE

• Now that you are an expert in Java

– How do we program with it?

• We could use command-line compiling

– But we are not going to...

• We will use an Integrated Development Environment (IDE).

– Easier to edit code, easier to execute and debug, easier to get help... Easier!

– This is not a programming course! We are interested in HCI.

(13)

Eclipse IDE

(14)

What are we missing?

• What are Objects?

– Referencing – Visibility

• What are Classes?

– Extensions – Interfaces

• Graphic Toolkits

– AWT

– Swing

(15)

Resources

1. Developer Resources for Java Technology

http://java.sun.com/

2. Essentials of the Java programming language

http://java.sun.com/developer/onlineTraini

ng/Programming/BasicJava1/

Referências

Documentos relacionados

A) para inicia uma oração adverbial condicional, pois restringe o genoma à condição de bactéria. C) como introduz uma oração adverbial conformativa, pois exprime acordo

[r]

Notas explicativas da Administração às Demonstrações Contábeis Individuais e Consolidadas referentes ao exercício encerrado em 31 de dezembro de 2020 (Em milhares de reais,

Faculdade de Engenharia Universidade da Beira Interior Estruturas Aeroespaciais II – 2014.. Departamento de

Paired with a Laerdal manikin, simulator, task trainer, or standardized patient, SimPad PLUS has the flexibility to support your needs and help provide the best possible simulation

Diretor Artístico e Regente Titular da Orquestra Filarmônica de Minas Gerais desde sua criação, em 2008, Fabio Mechetti posicionou a orquestra mineira no cenário mundial da música

Tiveram asseguradas algumas conquistas entre as quais o sufrágio universal masculino e o ensino obrigatório e gratuito durante o período jacobino (Convenção) da Revolução,

decorrência de pedidos de resgates incompatíveis com a liquidez existente ou que possam implicar alteração do tratamento tributário do FUNDO ou do cotista, sem prejuízo