This document provides an introduction to the Java programming language. It discusses that Java code is compiled to bytecode that runs on the Java Virtual Machine (JVM), allowing Java programs to run on any system with a JVM. The document then covers how to set up a Java development environment, write a simple "Hello World" program, use classes and objects in Java, and some basic Java concepts like primitives, arrays, and exceptions. It also compares Java to C/C++ and highlights some key differences.
This document provides an introduction to the Java programming language. It discusses that Java code is written in the Java programming language and compiled to Java Virtual Machine (JVM) byte code. The JVM then interprets the byte code on different platforms. Java code is portable across operating systems since it runs on the JVM. The document also covers Java classes, objects, primitive data types, arrays, scoping, and importing libraries. It provides an example of a simple "Hello World" Java program.
This document provides information about the CS3101-3 Programming Language - JAVA course for Fall 2004. It introduces the instructor, Ke Wang, and his contact information. It states the class will meet on Wednesdays from 11am-1pm for 6 weeks ending on October 20th. There will be 5-6 homework assignments due on Tuesdays at 11:59:59pm. Late submissions are allowed once with a 24-hour extension. The document outlines topics that will be covered in the course like Java basics, objects, classes, inheritance, and GUI programming. It provides references to online textbooks and tutorials that can be used. Finally, it encourages students to practice programming to learn the language.
This document provides information about the CS3101-3 Programming Language - JAVA course for Fall 2004. It introduces the instructor, Ke Wang, and his contact information. It states the class will meet on Wednesdays from 11am-1pm for 6 weeks ending on October 20th. There will be 5-6 homework assignments due on Tuesdays at 11:59:59pm. Late submissions are allowed once with a 24-hour extension. The document outlines topics that will be covered in the course like Java basics, objects, classes, inheritance, and GUI programming. It provides references to online textbooks and tutorials that can be used. Finally, it encourages students to practice programming to learn the language.
This document provides information about the CS3101-3 Programming Language - JAVA course for Fall 2004. It introduces the instructor, Ke Wang, and his contact information. It states the class will meet on Wednesdays from 11am-1pm for 6 weeks ending on October 20th. There will be 5-6 homework assignments due on Tuesdays at 11:59:59pm. Late submissions are allowed once with a 24-hour extension. The document outlines topics that will be covered in the course like Java basics, objects, classes, inheritance, GUI programming and threads. It provides references to textbooks and online resources.
OCA Java SE 8 Exam Chapter 1 Java Building Blocksİbrahim Kürce
The document discusses key concepts in Java including classes, objects, fields, methods, variables, primitive types, reference types, and memory management. It explains that classes are the basic building blocks in Java programs and contain fields and methods. Objects are instances of classes that exist in memory. The document also covers variable scope, default initialization, and garbage collection in Java.
The document provides information on Java OOP concepts including objects, classes, inheritance, polymorphism, abstraction, and encapsulation. It defines objects as entities with state and behavior, and classes as collections of objects. Inheritance allows objects to acquire properties of parent objects. Polymorphism allows one task to be performed in different ways. Abstraction hides internal details and shows functionality, while encapsulation binds code and data together into a single unit.
This ppt tells about what is Java? What are the requirements of Java? And how it works? For more info about Java and free Java Projects Visit : http://s4al.com/category/study-java/
This document provides an introduction to the Java programming language. It discusses that Java code is written in the Java programming language and compiled to Java Virtual Machine (JVM) byte code. The JVM then interprets the byte code on different platforms. Java code is portable across operating systems since it runs on the JVM. The document also covers Java classes, objects, primitive data types, arrays, scoping, and importing libraries. It provides an example of a simple "Hello World" Java program.
This document provides information about the CS3101-3 Programming Language - JAVA course for Fall 2004. It introduces the instructor, Ke Wang, and his contact information. It states the class will meet on Wednesdays from 11am-1pm for 6 weeks ending on October 20th. There will be 5-6 homework assignments due on Tuesdays at 11:59:59pm. Late submissions are allowed once with a 24-hour extension. The document outlines topics that will be covered in the course like Java basics, objects, classes, inheritance, and GUI programming. It provides references to online textbooks and tutorials that can be used. Finally, it encourages students to practice programming to learn the language.
This document provides information about the CS3101-3 Programming Language - JAVA course for Fall 2004. It introduces the instructor, Ke Wang, and his contact information. It states the class will meet on Wednesdays from 11am-1pm for 6 weeks ending on October 20th. There will be 5-6 homework assignments due on Tuesdays at 11:59:59pm. Late submissions are allowed once with a 24-hour extension. The document outlines topics that will be covered in the course like Java basics, objects, classes, inheritance, and GUI programming. It provides references to online textbooks and tutorials that can be used. Finally, it encourages students to practice programming to learn the language.
This document provides information about the CS3101-3 Programming Language - JAVA course for Fall 2004. It introduces the instructor, Ke Wang, and his contact information. It states the class will meet on Wednesdays from 11am-1pm for 6 weeks ending on October 20th. There will be 5-6 homework assignments due on Tuesdays at 11:59:59pm. Late submissions are allowed once with a 24-hour extension. The document outlines topics that will be covered in the course like Java basics, objects, classes, inheritance, GUI programming and threads. It provides references to textbooks and online resources.
OCA Java SE 8 Exam Chapter 1 Java Building Blocksİbrahim Kürce
The document discusses key concepts in Java including classes, objects, fields, methods, variables, primitive types, reference types, and memory management. It explains that classes are the basic building blocks in Java programs and contain fields and methods. Objects are instances of classes that exist in memory. The document also covers variable scope, default initialization, and garbage collection in Java.
The document provides information on Java OOP concepts including objects, classes, inheritance, polymorphism, abstraction, and encapsulation. It defines objects as entities with state and behavior, and classes as collections of objects. Inheritance allows objects to acquire properties of parent objects. Polymorphism allows one task to be performed in different ways. Abstraction hides internal details and shows functionality, while encapsulation binds code and data together into a single unit.
This ppt tells about what is Java? What are the requirements of Java? And how it works? For more info about Java and free Java Projects Visit : http://s4al.com/category/study-java/
CETPA Infotech provides Core and Advanced Java Training in Noida. We have a team of experienced Java professionals who help our students learn Java with the help of Live Base Projects. The object-oriented, class-based build of Java has made it one of most popular programming languages and the demand of professionals with certification in Advanced Java training is at an all-time high not just in India but foreign countries too
The document provides an overview of key Java concepts including:
1) Classes and methods define the structure and behaviors of objects in Java. Data types include primitives and object references.
2) Control statements like if/else and loops operate similarly to other languages like C++. Object-oriented concepts include inheritance, polymorphism, and encapsulation.
3) Interfaces define common behaviors without implementation, while abstract classes can contain abstract and implemented methods. The Java Virtual Machine executes Java bytecode making programs platform independent.
The document discusses Java strings and string comparison. It provides details on Java string class methods like charAt(), length(), substring(), contains(), equals(), etc. It also discusses the three ways to compare strings in Java: 1) Using the equals() method which compares string content, 2) Using the == operator which compares references, and 3) Using the compareTo() method which compares strings lexicographically. Examples of comparing strings using the equals() method are also provided.
This document provides an introduction to the Java programming language. It discusses Java's object-oriented nature, how to build standalone Java programs and applets, the Java Virtual Machine, basic Java syntax including classes, objects, and arrays, and contrasts Java with C/C++. Example "Hello World" programs in Java are provided to demonstrate basic syntax.
Java is a high level, an object oriented and mostly used programming language. It has several applications as in web development, app development, android development etc. This is a ppt that will give a basic idea about java its uses and its applications.
This document provides an overview of Java programming concepts covered in a course. It discusses:
- Sections of the course covering topics like Applets, Multithreading, AWT, Swing, Networking and JDBC.
- A brief history of Java and its versions.
- Core Java concepts like objects, classes, inheritance, interfaces, strings and exceptions.
- Other features like being platform independent, secure, robust and portable.
- Data types, operators, methods, constructors, access modifiers and this keyword in Java.
Java , basics of java programming, JVM, JRE, JDK detailed explanation. primitive datatype. this ppt explains the basic concepts of java clearly starting from variables to complex programmes. It has 55 slides which gives you better understanding
oops concept in java | object oriented programming in javaCPD INDIA
The document discusses key concepts in object-oriented programming in Java including classes, objects, inheritance, packages, interfaces, encapsulation, abstraction, and polymorphism. It provides examples to illustrate each concept. Classes define the structure and behavior of objects. Objects are instances of classes. Inheritance allows classes to extend existing classes. Packages organize related classes. Interfaces define behaviors without implementation. Encapsulation hides implementation details. Abstraction models essential features without specifics. Polymorphism allows the same method name with different signatures or overriding.
Here I discuss about Java programming language and easiest way to solve programming problem. Java basic syntax and their uses are described briefly so that anyone can easily understand within very short time. If anyone follow the slide with proper way,I assure that he or she will find java programming interesting.
The document discusses object oriented programming concepts in Java including classes, objects, constructors, and accessing class members. It provides code examples for creating a class with methods and variables, instantiating an object of the class, and calling methods on the object using the dot operator. It also shows examples of default and parameterized constructors.
- Java is an object-oriented programming language originally developed by Sun Microsystems that is both compiled and interpreted. Source code is compiled into bytecode, which is then run by the Java Virtual Machine (JVM) on any platform.
- Key features of Java include platform independence, security through sandboxing of applications, dynamic class loading, and versions for different uses including Java Micro Edition for small devices and Java Enterprise Edition for business applications.
- A Java program consists of classes that describe objects. Classes contain data fields and methods, and can extend existing classes. Commonly used classes are organized into packages.
Java is an object-oriented programming language. Key aspects of Java include:
- It is platform independent and runs on a virtual machine.
- Programs are written in classes with methods. The main method is where execution begins.
- Common operations include accepting user input, printing output, and performing math functions.
- Java supports concepts like inheritance, polymorphism, abstraction and encapsulation.
- The language does not support pointers, structures or multiple inheritance.
Java was created in 1991 by James Gosling, Mike Sheridan, and Patrick Naughton at Sun Microsystems. It has three editions: Java ME for limited devices, Java SE as the core platform for desktops and servers, and Java EE for large enterprise applications. Java code is compiled into bytecode that runs on a Java Virtual Machine (JVM) making Java portable across platforms. Key principles of Java include being object-oriented, secure, and platform independent.
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEVinishA23
The document discusses various object-oriented programming concepts in Java:
1. Objects are instances of classes that contain both data and functions. Classes act as blueprints for creating objects.
2. Inheritance allows subclasses to inherit attributes and behaviors from parent classes. Subclasses can override methods from parent classes.
3. Polymorphism allows functions to take different forms - either by function overloading or overriding. Overloading relies on static binding at compile time, while overriding uses dynamic binding at runtime.
The document provides information about object-oriented programming concepts in Java including objects, classes, constructors, and access modifiers. It defines an object as having state, behavior, and identity. A class is described as a template or blueprint for creating objects that share common properties. The document discusses default and parameterized constructors. It also covers the static keyword in relation to variables, methods, blocks, and nested classes. Other topics include finalizer methods, import statements, and the four levels of access control in Java.
A web browser takes you anywhere on the internet, letting you see text, images and video from anywhere in the world. ... The web is a vast and powerful tool. Over .
This document provides an introduction to the Java programming language. It discusses installing the JDK and Eclipse development environment. It then covers JVM, JRE, and JDK concepts. The document demonstrates a simple "Hello World" Java program. It discusses Java naming conventions and basic data types. It also outlines common loops and control structures in Java. The remainder of the document provides examples of Java programs and discusses arrays, lists, modifiers, methods, OOP concepts by relating real-world objects to objects in software, and how to define classes and create objects in Java.
This document provides an introduction to the Java programming language. It discusses the history and components of Java, including the Java language, platform, and tools. It then explains some key Java concepts like object-oriented programming, classes, objects, inheritance, and interfaces. It provides examples of how to write a simple Java program and declare methods. It also compares static and instance members and discusses abstract classes and when to use interfaces versus abstract classes.
CETPA Infotech provides Core and Advanced Java Training in Noida. We have a team of experienced Java professionals who help our students learn Java with the help of Live Base Projects. The object-oriented, class-based build of Java has made it one of most popular programming languages and the demand of professionals with certification in Advanced Java training is at an all-time high not just in India but foreign countries too
The document provides an overview of key Java concepts including:
1) Classes and methods define the structure and behaviors of objects in Java. Data types include primitives and object references.
2) Control statements like if/else and loops operate similarly to other languages like C++. Object-oriented concepts include inheritance, polymorphism, and encapsulation.
3) Interfaces define common behaviors without implementation, while abstract classes can contain abstract and implemented methods. The Java Virtual Machine executes Java bytecode making programs platform independent.
The document discusses Java strings and string comparison. It provides details on Java string class methods like charAt(), length(), substring(), contains(), equals(), etc. It also discusses the three ways to compare strings in Java: 1) Using the equals() method which compares string content, 2) Using the == operator which compares references, and 3) Using the compareTo() method which compares strings lexicographically. Examples of comparing strings using the equals() method are also provided.
This document provides an introduction to the Java programming language. It discusses Java's object-oriented nature, how to build standalone Java programs and applets, the Java Virtual Machine, basic Java syntax including classes, objects, and arrays, and contrasts Java with C/C++. Example "Hello World" programs in Java are provided to demonstrate basic syntax.
Java is a high level, an object oriented and mostly used programming language. It has several applications as in web development, app development, android development etc. This is a ppt that will give a basic idea about java its uses and its applications.
This document provides an overview of Java programming concepts covered in a course. It discusses:
- Sections of the course covering topics like Applets, Multithreading, AWT, Swing, Networking and JDBC.
- A brief history of Java and its versions.
- Core Java concepts like objects, classes, inheritance, interfaces, strings and exceptions.
- Other features like being platform independent, secure, robust and portable.
- Data types, operators, methods, constructors, access modifiers and this keyword in Java.
Java , basics of java programming, JVM, JRE, JDK detailed explanation. primitive datatype. this ppt explains the basic concepts of java clearly starting from variables to complex programmes. It has 55 slides which gives you better understanding
oops concept in java | object oriented programming in javaCPD INDIA
The document discusses key concepts in object-oriented programming in Java including classes, objects, inheritance, packages, interfaces, encapsulation, abstraction, and polymorphism. It provides examples to illustrate each concept. Classes define the structure and behavior of objects. Objects are instances of classes. Inheritance allows classes to extend existing classes. Packages organize related classes. Interfaces define behaviors without implementation. Encapsulation hides implementation details. Abstraction models essential features without specifics. Polymorphism allows the same method name with different signatures or overriding.
Here I discuss about Java programming language and easiest way to solve programming problem. Java basic syntax and their uses are described briefly so that anyone can easily understand within very short time. If anyone follow the slide with proper way,I assure that he or she will find java programming interesting.
The document discusses object oriented programming concepts in Java including classes, objects, constructors, and accessing class members. It provides code examples for creating a class with methods and variables, instantiating an object of the class, and calling methods on the object using the dot operator. It also shows examples of default and parameterized constructors.
- Java is an object-oriented programming language originally developed by Sun Microsystems that is both compiled and interpreted. Source code is compiled into bytecode, which is then run by the Java Virtual Machine (JVM) on any platform.
- Key features of Java include platform independence, security through sandboxing of applications, dynamic class loading, and versions for different uses including Java Micro Edition for small devices and Java Enterprise Edition for business applications.
- A Java program consists of classes that describe objects. Classes contain data fields and methods, and can extend existing classes. Commonly used classes are organized into packages.
Java is an object-oriented programming language. Key aspects of Java include:
- It is platform independent and runs on a virtual machine.
- Programs are written in classes with methods. The main method is where execution begins.
- Common operations include accepting user input, printing output, and performing math functions.
- Java supports concepts like inheritance, polymorphism, abstraction and encapsulation.
- The language does not support pointers, structures or multiple inheritance.
Java was created in 1991 by James Gosling, Mike Sheridan, and Patrick Naughton at Sun Microsystems. It has three editions: Java ME for limited devices, Java SE as the core platform for desktops and servers, and Java EE for large enterprise applications. Java code is compiled into bytecode that runs on a Java Virtual Machine (JVM) making Java portable across platforms. Key principles of Java include being object-oriented, secure, and platform independent.
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEVinishA23
The document discusses various object-oriented programming concepts in Java:
1. Objects are instances of classes that contain both data and functions. Classes act as blueprints for creating objects.
2. Inheritance allows subclasses to inherit attributes and behaviors from parent classes. Subclasses can override methods from parent classes.
3. Polymorphism allows functions to take different forms - either by function overloading or overriding. Overloading relies on static binding at compile time, while overriding uses dynamic binding at runtime.
The document provides information about object-oriented programming concepts in Java including objects, classes, constructors, and access modifiers. It defines an object as having state, behavior, and identity. A class is described as a template or blueprint for creating objects that share common properties. The document discusses default and parameterized constructors. It also covers the static keyword in relation to variables, methods, blocks, and nested classes. Other topics include finalizer methods, import statements, and the four levels of access control in Java.
A web browser takes you anywhere on the internet, letting you see text, images and video from anywhere in the world. ... The web is a vast and powerful tool. Over .
This document provides an introduction to the Java programming language. It discusses installing the JDK and Eclipse development environment. It then covers JVM, JRE, and JDK concepts. The document demonstrates a simple "Hello World" Java program. It discusses Java naming conventions and basic data types. It also outlines common loops and control structures in Java. The remainder of the document provides examples of Java programs and discusses arrays, lists, modifiers, methods, OOP concepts by relating real-world objects to objects in software, and how to define classes and create objects in Java.
This document provides an introduction to the Java programming language. It discusses the history and components of Java, including the Java language, platform, and tools. It then explains some key Java concepts like object-oriented programming, classes, objects, inheritance, and interfaces. It provides examples of how to write a simple Java program and declare methods. It also compares static and instance members and discusses abstract classes and when to use interfaces versus abstract classes.
International Conference on NLP, Artificial Intelligence, Machine Learning an...gerogepatton
International Conference on NLP, Artificial Intelligence, Machine Learning and Applications (NLAIM 2024) offers a premier global platform for exchanging insights and findings in the theory, methodology, and applications of NLP, Artificial Intelligence, Machine Learning, and their applications. The conference seeks substantial contributions across all key domains of NLP, Artificial Intelligence, Machine Learning, and their practical applications, aiming to foster both theoretical advancements and real-world implementations. With a focus on facilitating collaboration between researchers and practitioners from academia and industry, the conference serves as a nexus for sharing the latest developments in the field.
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesChristina Lin
Traditionally, dealing with real-time data pipelines has involved significant overhead, even for straightforward tasks like data transformation or masking. However, in this talk, we’ll venture into the dynamic realm of WebAssembly (WASM) and discover how it can revolutionize the creation of stateless streaming pipelines within a Kafka (Redpanda) broker. These pipelines are adept at managing low-latency, high-data-volume scenarios.
ACEP Magazine edition 4th launched on 05.06.2024Rahul
This document provides information about the third edition of the magazine "Sthapatya" published by the Association of Civil Engineers (Practicing) Aurangabad. It includes messages from current and past presidents of ACEP, memories and photos from past ACEP events, information on life time achievement awards given by ACEP, and a technical article on concrete maintenance, repairs and strengthening. The document highlights activities of ACEP and provides a technical educational article for members.
A review on techniques and modelling methodologies used for checking electrom...nooriasukmaningtyas
The proper function of the integrated circuit (IC) in an inhibiting electromagnetic environment has always been a serious concern throughout the decades of revolution in the world of electronics, from disjunct devices to today’s integrated circuit technology, where billions of transistors are combined on a single chip. The automotive industry and smart vehicles in particular, are confronting design issues such as being prone to electromagnetic interference (EMI). Electronic control devices calculate incorrect outputs because of EMI and sensors give misleading values which can prove fatal in case of automotives. In this paper, the authors have non exhaustively tried to review research work concerned with the investigation of EMI in ICs and prediction of this EMI using various modelling methodologies and measurement setups.
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
2. road map today
Brief intro to Java
Develop and compile environment
A simple example
Intro to object/class
Java basics
Differences from C
3. Intro to Java
Java programming language
The one we use to write our program
Compiled to byte code of JVM
Java virtual machine (JVM)
Java interpreter – interpret the compiled byte code
Software simulated CPU architecture
Cross-platform: support Linux, Windows, PalmOS…etc.
Java runtime environment (JRE)
Predefined set of java classes available to use
Core Java APIs – basic utilities, I/O, graphics, network…
4. Java is portable,
As long as there is a JVM compiled for
that particular processor and OS
Typical program, like C or C++, is
compiled for a particular processor
architecture and OS.
“Write once, run everywhere!”
Sun’s motto for Java
5. Java
Java is an object-oriented language, with a
syntax similar to C
Structured around objects and methods
A method is an action or something you do with
the object
Avoid those overly complicated features of
C++:
Operator overloading, pointer, templates, friend
class, etc.
6. Getting and using java
J2SDK freely download from http://java.sun.com
“Your first cup of Java”:
detailed instructions to help you run your first program
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/in
dex.html
All text editors support java
Vi/vim, emacs, notepad, wordpad
Just save to .java file
Have IDEs that comparable to Visual Studio
JCreator (simple)
Eclipse (more complicated)
7. Compile and run an application
Write java class Foo containing a main()
method and save in file “Foo.java”
The file name MUST be the same as class
name
Compile with: javac Foo.java
Creates compiled .class file: Foo.class
Run the program: java Foo
Notice: use the class name directly, no .class!
8. Hello World!
/* Our first Java program – Hello.java */
public class Hello {
//main()
public static void main ( String[] args ) {
System.out.println( "hello world!" );
}
}
File name: Hello.java
Command line
arguments
Standard output, print with new line
9. About class
Fundamental unit of Java program
All java programs are classes
Each class define a unique kind of object
( a new data type)
Each class defines a set of fields, methods
or other classes
public: modifier. This class is publicly
available and anyone can use it.
10. Things to notice
Java is case sensitive
whitespace doesn’t matter for compilation
File name must be the same as one of the
class names, including capitalization!
At most one public class per file
If there is one public class in the file, the
filename must be the same as it
Generally one class per file
11. What is an object?
Object is a thing
An object has state, behavior and identity
Internal variable: store state
Method: produce behavior
Unique address in memory: identity
An object is a manifestation of a class
12. What is class?
Class introduces a new data type
A class describes a set of objects that
have identical characteristics (data
elements) and behaviors (methods).
Existing classes provided by JRE
User defined classes
Once a class is established, you can make
as many objects of it as you like, or none.
13. Simple example: class Person
A Person has some attributes
The class defines these properties for all
people
Each person gets his own copy of the
fields
Attributes = properties = fields
14. Class Person: definition
class Person {
String name;
int height; //in inches
int weight; //in pounds
public void printInfo(){
System.out.println(name+" with height="+height+", weight="+weight);
}
}
class ClassName{ /* class body goes here */ }
class: keyword
15. Class Person: usage
Person ke; //declaration
ke = new Person(); //create an object of Person
ke.name= “Ke Wang”; //access its field
Person sal = new Person();
sal.name=“Salvatore J. Stolfo”;
ke.printInfo();
Sal.printInfo(); // error here??
16. Reference
Person ke; //only created the reference, not an object.
It points to nothing now (null).
ke = new Person(); //create the object (allocate storage
in memory), and ke is initialized.
ke.name=“Ke Wang”; //access the object through
the reference
17. Java Basics: primitive types
One group of types get special treatment
in Java
Variable is not created by “new”, not a
reference
Variable holds the value directly
18. Primitive types
Primitive type Size Minimum Maximum Wrapper type
boolean 1-bit — — Boolean
char 16-bit Unicode 0 Unicode 216- 1 Character
byte 8-bit -128 +127 Byte
short 16-bit -215 +215-1 Short
int 32-bit -231 +231-1 Integer
long 64-bit -263 +263-1 Long
float 32-bit IEEE754 IEEE754 Float
double 64-bit IEEE754 IEEE754 Double
19. Primitive types
All numerical types are signed!
No unsigned keyword in Java
The “wrapper” class allow you to make a
non-primitive object to represent the
primitive one
char c =‘a’;
Character C = new Character(c);
Character C = new Character(‘a’);
20. Primitive types - boolean
boolean can never convert to or from other
data type, not like C or C++
boolean is not a integer
if(0) doesn’t work in java
Have to explicitly state the comparison
if( x ==0) {
21. Arrays in Java
An ordered collection of something, addressed
by integer index
Something can be primitive values, objects, or even
other arrays. But all the values in an array must be of
the same type.
Only int or char as index
long values not allowed as array index
0 based
Value indexes for array “a” with length 10
a[0] – a[9];
a.length==10
Note: length is an attribute, not method
22. Arrays in Java: declaration
Declaration
int[] arr;
Person[] persons;
Also support: int arr[]; Person persons[];
(confusing, should be avoided)
Creation
int[] arr = new int[1024];
int [][] arr = { {1,2,3}, {4,5,6} };
Person[] persons = new Person[50];
23. Arrays in Java: safety
Cannot be accessed outside of its range
ArrayIndexOutOfBoundsException
Guaranteed to be initialized
Array of primitive type will be initialized to their
default value
Zeroes the memory for the array
Array of objects: actually it’s creating an array
of references, and each of them is initialized to
null.
24. Arrays in Java:
second kind of reference types in Java
int[] arr = new int [5];
arr
int[][] arr = new int [2][5];
arr[0]
arr[1]
arr
25. Reference vs. primitive
Java handle objects and arrays always by
reference.
classes and arrays are known as reference types.
Class and array are composite type, don’t have
standard size
Java always handle values of the primitive types
directly
Primitive types have standard size, can be stored in a
fixed amount of memory
Because of how the primitive types and objects
are handles, they behave different in two areas:
copy value and compare for equality
26. Scope of objects
When you create an object using new, the
object hangs around past the end of the
scope, although the reference vanishes.
{
String s = new String("abc");
}
Reference s vanishes, but the String
object still in memory
Solution: Garbage Collector!
27. Garbage collector
In C++, you have to make sure that you
destroy the objects when you are done
with them.
Otherwise, memory leak.
In Java, garbage collector do it for you.
It looks at all the objects created by new and
figure out which ones are no longer being
referenced. Then it release the memory for
those objects.
28. Importing library
If you need any routines that defined by
java package
import java.util.*;
import java.io.*;
Put at the very beginning of the java file
java.lang.* already been imported.
Check javadoc for the classes
29. Static keyword
Want to have only one piece of storage for a
data, regardless how many objects are created,
or even no objects created
Need a method that isn’t associated with any
particular object of this class
static keyword apply to both fields and methods
Can be called directly by class name
Example: java.lang.Math
Non-static fields/methods must be called through
an instance
30. main()
class Hello{
int num;
public static void main(String[] args) {
num = 10;
}
}
>javac Hello.java
Hello.java:4: non-static variable num cannot be referenced
from a static context
num = 10;
^
1 error
31. Main() doesn’t belong in a class
Always static
Because program need a place to start, before any
object been created.
Poor design decision
If you need access non-static variable of class
Hello, you need to create object Hello, even if
main() is in class Hello!
class Hello{
int num;
public static void main(String[] args){
Hello h = new Hello();
h.num = 10;
}
}
32. Difference between C and Java
No pointers
No global variable across classes
Variable declaration anywhere
Forward reference
Method can be invoked before defined
Method overloading
As long as the methods have different parameter lists
No struct, union, enum type
No variable-length argument list