Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
33 views

01 Java Language and OOP Part I LAB

This document outlines an agenda and labs for a Java language and object-oriented programming (OOP) part 1 lab. The agenda covers Java keywords, primitive data types, wrapper classes, variables, expressions, comments, casting, and overflow. It then provides the code for 13 labs covering Hello World, primitive data types like byte, short, int, long, double, char, boolean, expressions, comments, casting between types, wrapper classes, and integer overflow. The labs provide examples of and practice with these Java and OOP concepts.

Uploaded by

HariChristian
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

01 Java Language and OOP Part I LAB

This document outlines an agenda and labs for a Java language and object-oriented programming (OOP) part 1 lab. The agenda covers Java keywords, primitive data types, wrapper classes, variables, expressions, comments, casting, and overflow. It then provides the code for 13 labs covering Hello World, primitive data types like byte, short, int, long, double, char, boolean, expressions, comments, casting between types, wrapper classes, and integer overflow. The labs provide examples of and practice with these Java and OOP concepts.

Uploaded by

HariChristian
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Java Language and OOP

Part I LAB
By Hari Christian
Agenda
01 Java Keyword
02 Primitive Data Type
03 Wrapper Class
04 Variabel or Identifier
05 Expression Statement
06 Comment in Java
07 Comment Single Line
08 Comment Multiple Line
09 Casting
10 Overflow
LAB 1 Hello World
public class Lab1 {
public static void main(String[] args) {
System.out.println(Hello World!!!);
}
}
LAB 2 Primitive Data Type
public class Lab2 {
public static void main(String[] args) {
byte a = 1; // ini adalah literal value
short b = 2; // juga dapat disebut assignment
int c = 3; // juga dapat disebut statement
long d;
d = a + b + c;
System.out.println("hasilnya = " + d);
}
}
LAB 3 Primitive Data Type
public class Lab3 {
public static void main(String[] args) {
double pi = 3.14;
double r = 2.12;
double luas;
luas = pi * r * r;
System.out.println("Luas Lingkaran = " + luas);
}
}
LAB 4 Primitive Data Type
public class Lab4 {
public static void main(String[] args) {
char ch1 = 65;
char ch2 = 'B';
System.out.println("ch1 = " + ch1);
System.out.println("ch2 = " + ch2);
}
}
LAB 4 Primitive Data Type
LAB 5 Primitive Data Type
public class Lab5 {
public static void main(String[] args) {
boolean b = true;
System.out.println ("Nilai b = " +b);
if (b) {
System.out.println("Statemen ke-1 dieksekusi");
}
b = false;
System.out.println("Nilai b = " +b);
if (b) {
System.out.println("Statemen ke-2 tidak dieksekusi");
}
if (!b) {
System.out.println("Statemen ke-3 dieksekusi");
}
System.out.println ("5 <= 10 mengembalikan nilai = " + (5 <= 10));
System.out.println("4 > 6 mengembalikan nilai " + (4 > 6));
}
}
LAB 6 Expression Statement
public class Lab6 {
public static void main(String[] args) {
int i = 4;
int j = 6;
int x = i++ + ++i - --j + ++j + j++;
System.out.println(x = + x);
System.out.println(i = + i);
System.out.println(j = + j);
}
}
LAB 7 Comment
/**
* Ini adalah latihan praktikum PBO
* PBO di ISTB menggunakan Java
* Lab 7 ini menjelaskan tentang comment
*/
public class Lab7 {
public static void main(String[] args) {
// ini comment satu baris

/*
ini comment
dua baris
atau lebih
*/
}
}
LAB 8 Casting Identity
public class Lab8 {
public static void main(String[] args) {
int i = 5;
int j = i;
System.out.println(Isi dari j yaitu = + j);
}
}
LAB 9 Casting Widening
public class Lab9 {
public static void main(String[] args) {
int i = 5;
double d = i;
System.out.println(Isi dari d yaitu = + d);
}
}
LAB 10 Casting Narrowing
public class Lab10 {
public static void main(String[] args) {
double d = 5.6;
int i = (int) d;
System.out.println(Isi dari i yaitu = + i);
}
}
LAB 11 Wrapper Class
public class Lab11 {
public static void main(String[] args) {
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
System.out.println(min = + min);
System.out.println(max = + max);
}
}
LAB 12 Wrapper Class
public class Lab12 {
public static void main(String[] args) {
Integer a = 5;
Integer b = 7;
Integer c = a + b;
System.out.println(c);
}
}
LAB 13 Overflow
public class Lab13 {
public static void main(String[] args) {
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
int over1 = max + 1;
System.out.println(over1);
int over2 = min - 1;
System.out.println(over2);
}
}
Thank You

You might also like