SlideShare a Scribd company logo
Learning Java 1: Introduction Christopher Swenson Center for Information Security University of Tulsa 600 S. College Ave Tulsa, OK 74104
Learning Java Based on  Learning Java , by  Niemeyer and Knudsen Quick and Dirty overview of Java fundamentals and advanced  programming Introduction Objects and Classes Generics, Core Utilities Threads, Synchronization I/O, Network Programming Swing
Overview (Ch. 1–5) Java Hello World! Using Java Java Language Objects
Java Modern, Object-Oriented (OO) Language with C-like syntax Developed at Sun Microsystems (James Gosling, Bill Joy) in the early 1990s Virtual Machine Intermediate bytecode Extremely portable Surprisingly fast (comparable to C++) Features HotSpot on-the-fly native compiling Safe and Clean Dynamic Memory Management Robust Error Handling http://java.sun.com http://java.sun.com/j2se/1.5.0/docs/api/

Recommended for you

Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM

While Java’s strict type system is a great help for avoiding programming errors, it also takes away some of the flexibility that developers appreciate when using dynamic languages. By using runtime code generation, it is possible to bring some of this flexibility back to the Java virtual machine. For this reason, runtime code generation is widely used by many state-of-the-art Java frameworks for implementing POJO-centric APIs but it also opens the door to assembling more modular applications. This presentation offers an introduction to the complex of runtime code generation and its use on the Java platform. Furthermore, it discusses the up- and downsides of several code generation libraries such as ASM, Javassist, cglib and Byte Buddy.

byte codeproxyasm
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials

Java is an object-oriented programming language created by James Gosling. It was originally called Oak but was later renamed to Java. The document discusses the different editions of Java including J2SE, J2EE, and J2ME. It also covers key Java technologies like applets, servlets, JSP, and Swing. The document provides an overview of Java features such as being platform independent, portable, multi-threaded, and having a Java Virtual Machine. It also discusses concepts like inheritance, interfaces, packages, exceptions, and input/output in Java.

javacore javajava programming tips
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performance

Writing software for a virtual machine enables developers to forget about machine code assembly, interrupts, and processor caches. This makes Java a convenient language, but all too many developers see the JVM as a black box and are often unsure of how to optimize their code for performance. This unfortunately adds credence to the myth that Java is always outperformed by native languages. This session takes a peek at the inner workings of Oracle’s HotSpot virtual machine, its just-in-time compiler, and the interplay with a computer’s hardware. From this, you will understand the more common optimizations a virtual machine applies, to be better equipped to improve and reason about a Java program’s performance and how to correctly measure runtime!

performancejvmjava virtual machine
Let’s Go! Standard CLI utilities, although IDEs and GUIs exist (Eclipse, Netbeans) Windows: Start    Run    “ cmd ” UNIX / OS X: Open up a command terminal “ javac HelloJava.java ” Compiles the file  HelloJava.java Outputs executable  .class  files
HelloJava.java public class HelloJava { public static void main(String[] args) { System.out.println(“Hello World!”); } } Run with: java -cp . HelloJava Outputs: Hello World!
Some Notes public class HelloJava  { … Everything in Java must be in a class (container for code and data). public static void main(String[] args){ … This is a method (which contains executable code). The function called from the command-line is required to be  main . Takes a  String  array (the arguments), and returns nothing ( void ). System.out.println(“Hello World!”); System  is a class that contains a lot of useful system-wide tools, like standard I/O, and its  out  class represents standard out. The  println  method of out (and all  PrintStream  objects) prints the  String  containted within, followed by a newline. java -cp . HelloJava Invokes the Java Virtual Machine (JVM) to execute the  main  of the named class ( HelloJava ). Searches the current directory for the class file ( -cp . ).
Comments /* */  C-style comments are also supported /** */  are special JavaDoc comments Allow automatic documentation to be built from source code, using the  javadoc  utility. //  C++-style comments are preferred Less ambiguity Simpler

Recommended for you

Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond

A lookout on the upcoming Java releases, on breaking functionality and projects that will come after the current schedule.

javafuturejava 11
Understanding Java byte code and the class file format
Understanding Java byte code and the class file formatUnderstanding Java byte code and the class file format
Understanding Java byte code and the class file format

At first glance, Java byte code can appear to be some low level magic that is both hard to understand and effectively irrelevant to application developers. However, neither is true. With only little practice, Java byte code becomes easy to read and can give true insights into the functioning of a Java program. In this talk, we will cast light on compiled Java code and its interplay with the Java virtual machine. In the process, we will look into the evolution of byte code over the recent major releases with features such as dynamic method invocation which is the basis to Java 8 lambda expressions. Finally, we will learn about tools for the run time generation of Java classes and how these tools are used to build modern frameworks and libraries. Among those tools, I present Byte Buddy, an open source tool of my own efforts and an attempt to considerably simplify run time code generation in Java. (http://bytebuddy.net)

javajvmjava virtual machine
Byte code field report
Byte code field reportByte code field report
Byte code field report

This document discusses Java bytecode manipulation techniques using unsafe, instrumentation, and Java agents. It covers areas where bytecode manipulation is commonly used like mocking, persistence, and security. It analyzes techniques for defining and transforming classes at runtime and discusses challenges like injecting state and working with modules. The document also proposes ideas to standardize testing support and provide a unified dynamic code generation concept in Java.

javainstrumentationproxy
Variables String s = “string”; int a = -14; long b = 5000000000l; float c = 2.5f; double d = -4.0d; byte e = 0x7f; char f = ‘c’; short g = -31000; boolean h = true; int s are signed 32-bit long s are signed 64-bit float s are signed 32-bit double s are signed 64-bit byte s are signed 8-bit char s are signed 16-bit short s are signed 16-bit boolean s are 1-bit, either  true  or  false
Operators Standard arithmetic operators for ints, longs, shorts, bytes, floats and doubles + - * / % << >> >>> Boolean operators for non-floating point & | ^ ~ Logical operators for  boolean s && || ^^ ~ Comparisons generate  boolean s == < <= > >= != Can be suffixed with  =  to indicate an assignment a = a + b      a += b ++   and   --   operators also ( a = a - 1      a-- ) Ternary Operator: (a >= b) ? c : d      if (a >= b) c else d
Reference Types Reference Types are non-primitive constructs Includes  String s Consist of variables and methods (code) Typically identified with capital letter Foo bar = new Foo(); Use the  new  keyword to explicitly construct new objects Can take arguments No need for destructor or to explicitly remove it No pointers C++:  Foo &bar  = *(new Foo());
String Strings are a reference type, but  almost  a primitive in Java String s = “this is a string”; No need for  new  construction Overloaded + operator for concatenation String s = “a” + “ kitten”;

Recommended for you

final year project center in Coimbatore
final year project center in Coimbatorefinal year project center in Coimbatore
final year project center in Coimbatore

Clarozon Technologies final year project center in coimbatore The mixtures of dynamic professionals have made CLAROZON TECHNOLOGIES standout from the competition. We have a team dedicated to share and infuse knowledge into Brains. With subject ideas and experts concentrating on their areas of experience, we are transforming in a unique way.

project center in coimbatorefinal year project center in coimbatore
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP

Object Oriented Programming (OOP) allows developers to organize complex programs using classes and objects. OOP uses concepts like encapsulation, inheritance and polymorphism to keep data and functionality together in objects. The basic building blocks in OOP are classes, which define the properties and methods of an object, and objects, which are instances of classes. Classes can inherit properties and methods from parent classes, and objects can be identified and compared using operators like instanceof. Magic methods allow objects to override default behavior for operations like property access, method calling and object destruction.

beginnerexamplesphp
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.

Synapseindia Reviews about java Tutorial: platform independent programming language similar to C++ in syntax similar to Smalltalk in mental paradigm

synapseindia reviewssynapse india reviews
Coercion Coercion = automatic conversion between types Up is easy ( int  to  double , anything to  String ) Down is hard int i = 2; double num = 3.14 * i; String s = “” + num; int a = Integer.parseInt(t);
Expressions and Statements An statement is a line of code to be evaluated a = b; An statement can be made compound using curly braces { a = b; c = d; } Curly braces also indicate a new scope (so can have its own local variables) Assignments can also be used as expressions (the value is the value of the variable after the assignment) a = (b = c);
if-then-else  statements if (bool) stmt1; if (bool) stmt1 else statement2; if (bool) stmt1 else if stmt2 else stmt3; if (bool) { stmt1; … ; } … if  (i == 100) System.out.println(i);
Do-while loops while (bool) stmt; do stmt; while (bool); boolean stop = false; while  (!stop) { // Stuff if (i == 100) stop = true; }

Recommended for you

Java Tut1
Java Tut1Java Tut1
Java Tut1

Java allows writing code once that can run on any platform. It compiles to bytecode that runs on the Java Virtual Machine (JVM). Key features include automatic memory management, object-oriented design, platform independence, security, and multi-threading. Classes are defined in .java files and compiled to .class files. The JVM interprets bytecode and uses just-in-time compilation to improve performance.

javatutorialjava
Javatut1
Javatut1 Javatut1
Javatut1

This document provides an overview of the Java programming language. It discusses key features such as platform independence, object-oriented programming principles like inheritance and polymorphism, automatic memory management, and security features. It also covers basic Java concepts like primitive data types, variables, operators, control flow statements, methods, and classes.

Sam wd programs
Sam wd programsSam wd programs
Sam wd programs

The document provides an index and descriptions of various topics related to web development including: 1. The modulus operator and examples of using it to check for divisibility. 2. Relational and logical operators like greater than, less than, equal to and examples of using them in code. 3. Descriptions of do-while and for loops with examples. 4. An example using a parameterized constructor to initialize cube dimensions. 5. Examples of string methods like startsWith, length, and trim. 6. Descriptions and examples of overloading methods and constructors. 7. An example of inheritance with overriding methods. 8. An interface example with animal classes

for  loops for  ( prestmt ;  bool ;  stepstmt ;)  stmt ; =  {  prestmt ; while ( bool ) {  stmt ;  stepstmt ; } } for (int i = 0; i < 10; i++) { System.out.print(i + “ “); } Outputs: “ 0 1 2 3 4 5 6 7 8 9   ”
switch  statement switch  ( int expression ) { case   int_constant :   stmt ; break ; case   int_constant :   stmt ; case   int_constant :   stmt ; default:   stmt ; }
Arrays int []  array =  { 1,2,3 } ; int []  array =  new int[ 10 ]; for (int i = 0; i <  array.length ; i++) array [ i ]  = i; Array indices are from 0 to (length – 1) Multi-dimensional arrays are actually arrays of arrays: int [][]  matrix = new int [3][3]; for (int i = 0; i <  matrix.length ; i++) for (int j = 0; j <  matrix[i].length ; j++) System.out.println(“Row: “ + i + “, Col: “ + j + “ = “ + matrix [i][j] );
enum s What about something, like size? Pre-Java 1.5,  int small = 1, medium = 2, … But what if  mySize == -14 ? enum  Size {Small, Medium, Large}; Can also do switch statements on enums switch (mySize) { case Small:  // … default:  // … }

Recommended for you

Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...

The document discusses various concepts in Java programming including basic elements of Java programs, strings, date and time, switch statements, methods, recursion, polymorphism through method overloading and overriding, user input, and sample questions. It provides code examples to demonstrate strings, date/time, switch statements, methods, recursion, polymorphism, and user input. It also defines method overloading and overriding and compares the two.

internet and web technology (class-16) [basic elembasic elements of java programnielit web technology
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...

The document discusses Java programming and object-oriented programming concepts. It includes: - An overview of Java including its history, platforms, and creator James Gosling. - Explanations of object-oriented programming concepts in Java including classes, objects, encapsulation, inheritance, polymorphism, and abstraction with examples. - Code samples demonstrating Java syntax and basic programming. - Questions about HTML tags, Apache Tomcat, JavaScript functions, and alternative scripting languages.

internet and web technology (class-15) [java basicjava basicsnielit web technology
Java programs
Java programsJava programs
Java programs

The document contains code snippets for several Java programs including: 1. An Armstrong number checker that uses recursion to check if a number is an Armstrong number. 2. A binary search program that searches an integer array using a binary search algorithm. 3. A binary search on a float array using the Arrays binarySearch method. The document then continues with additional code examples for recursive binary search, bubble sort, constructors, converting between object and primitive types, data input/output streams, encapsulation, enumerating a vector, exception handling, and creating threads by extending the Thread class.

Loop breaking break  breaks out of the current loop or switch statement while (!stop) { while (0 == 0) { break ; } // Execution continues here }
Loop continuing continue  goes back to the beginning of a loop boolean stop = false; int num = 0; while (!stop) { if (num < 100)  continue ; if (num % 3) stop = true; }
Objects class  Person { String name; int age; } Person me =  new  Person(); me.name = “Bill”; me.age = 34; Person[] students = new Person[50]; students[0] = new Person();
Subclassing class Professor  extends  Person { String office; } Professor bob = new Professor(); bob.name = “Bob”; bob.age = 40; bob.office = “U367”; However, a class can only “extend” one other class

Recommended for you

Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to 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.

ganesh chittalwar try to show presentation of javaeasy way to show presentation
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial

- Java is a platform independent programming language that is similar to C++ in syntax but similar to Smalltalk in its object-oriented approach. It provides features like automatic memory management, security, and multi-threading capabilities. - Java code is compiled to bytecode that can run on any Java Virtual Machine (JVM). Only depending on the JVM allows Java code to run on any hardware or operating system with a JVM. - Java supports object-oriented programming concepts like inheritance, polymorphism, and encapsulation. Classes can contain methods and instance variables to define objects.

javatutorial
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT

This document provides an overview of the Java programming language including how it works, its features, syntax, and input/output capabilities. Java allows software to run on any device by compiling code to bytecode that runs on a virtual machine instead of a particular computer architecture. It is an object-oriented language with features like automatic memory management, cross-platform capabilities, and a robust class library.

javatutorial
Abstract Classes If not all of its methods are implemented (left abstract), a class is called abstract abstract  class Fish { abstract  void doesItEat(String food); public void swim() { // code for swimming } }
Interfaces class MyEvent  implements  ActionListener { public void actionPerformed(ActionEvent ae) { System.out.println(“My Action��); } } Can implement multiple interfaces Interfaces have abstract methods, but no normal variables
Static and final A  static  method or variable is tied to the class, NOT an instance of the class Something marked  final  cannot be overwritten (classes marked final cannot be subclassed) class Person { public  final static  int version = 2; static  long numberOfPeople = 6000000000; static void birth() { numberOfPeople++; } String name; int age; } // … in some other code Person.numberOfPeople++; System.out.println(“Running Version “ + Person.version + “ of Person class);
Special functions All classes extend the Object class Classes have built-in functions: equals(Object obj), hashCode(), toString() Equals used to determine if two objects are the same o == p  – checks their memory addresses o.equals(p)  – runs  o.equals() hashCode()  – used for hash tables ( int ) toString()  – used when cast as a  String  (like printing)

Recommended for you

Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT

This document provides an overview of the Java programming language including how it works, its features, syntax, and input/output capabilities. Java allows software to run on any device by compiling code to bytecode that runs on a virtual machine. It is object-oriented, supports features like inheritance and polymorphism, and has memory management and security benefits over other languages. The document also discusses Java concepts like classes, methods, arrays, and streams for file input/output.

Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals

This document provides an overview of key concepts in the Java programming language, including: - Java is an object-oriented language that is simpler than C++ and supports features like platform independence. - The Java development environment includes tools for compiling, debugging, and running Java programs. - Java programs work with basic data types like int and double, as well as user-defined classes, variables, and arrays. - The document explains operators, control structures, formatting output, and the basics of classes and objects in Java.

javaprogrammingbasic
Java tutorials
Java tutorialsJava tutorials
Java tutorials

This document provides an overview of the Java programming language. It discusses how Java is platform independent and compiles code to bytecode that runs on the Java Virtual Machine (JVM). Key Java features like automatic memory management, object-oriented design, and security are summarized. The document also covers Java syntax like data types, operators, control flow, and classes/methods. It provides examples of working with files, streams, and serialization in Java.

Packages Classes can be arranged into packages and subpackages, a hierarchy that Java uses to find class files Prevents naming issues Allows access control By default, a null package Doesn’t work well if you need more than a few classes, or other classes from other packages java.io  – Base I/O Package java.io.OutputStream  – full name Declare a package with a  package  keyword at the top Import stuff from package with the import keyword import java.io.*; import java.util.Vector; import static java.util.Arrays.sort;
Using Packages Compile like normal Packages = a directory Java has a “classpath”: root directories and archives where it expects to look for classes Example java -cp compiled swenson.MyServer In the the “compiled” directory, look for a class MyServer in the subfolder “swenson” /compiled/swenson/MyServer.class Also need to specify  -classpath  when compiling Class files can also be put into ZIP files (with a suffix of JAR instead of ZIP)
Permissions public  – accessible by anyone  protected  – accessible by anything in the package, or by subclasses (default) – accessible by anything in the package private  – accessible only by class
Coding Style class Test { public static void main(String[] args) { if (args.length > 0) System.out.println(“We have args!”); for (int i = 0; i < args.length; i++) { int q = Integer.parseInt(args[i]); System.out.println(2 * q); } System.exit(0); } }

Recommended for you

Java tut1
Java tut1Java tut1
Java tut1

This document provides an overview of the Java programming language. It discusses key features such as platform independence, object-oriented programming principles like inheritance and polymorphism, automatic memory management, and security features. It also covers basic Java concepts like primitive data types, variables, operators, control flow statements, methods, classes and objects.

Java tut1
Java tut1Java tut1
Java tut1

Java is an object-oriented programming language that is platform independent, allowing code to run on any device. It features automatic memory management, strong typing, and multi-threading. Java code is compiled to bytecode that runs on a Java Virtual Machine, providing platform independence. Methods and classes encapsulate code and data, and inheritance, polymorphism, and interfaces support object-oriented programming.

java tut1
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial

Java Tutorial Write Once, Run Anywhere The document provides an overview of Java including: - Java is a platform independent programming language similar to C++ in syntax and Smalltalk in mental paradigm. - Key features of Java include automatic type checking, garbage collection, simplified pointers and network access, and multi-threading. - Java code is compiled to bytecode, which is interpreted by the Java Virtual Machine (JVM) on any platform, allowing Java to be platform independent. Just-in-time compilers attempt to increase speed.

javaprogrammingsoftware development
Tools: Eclipse Popular Auto Complete Fancy Multi-language
Tools: NetBeans Another good GUI Full-featured Java-centric
Tools: JSwat Debugger
emacs

Recommended for you

Java_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.pptJava_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.ppt

Java Basics

Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart

Java is a platform independent programming language similar to C++ in syntax and Smalltalk in mental paradigm. It has features like automatic type checking, garbage collection, simplified pointers and network access. Java code is compiled to bytecode, which is interpreted by the Java Virtual Machine (JVM) on various platforms, making Java portable across different operating systems and hardware. Methods and data in Java classes can be declared as public or private to control access and eliminate errors between classes.

Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)

Java is a cross-platform language originally developed by James Gosling at Sun Microsystems. It enables writing programs for many operating systems using a C/C++-like syntax but with a simpler object model and fewer low-level facilities. Java programs are compiled to bytecode that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Common Java development tools include Eclipse and NetBeans integrated development environments.

vi
TextPad
Homework Download Java Download a GUI and learn it (e.g., Eclipse) Implement a Card class enum s for Suit hashCode()  should return a different value for two different cards, but should be the same for two instances of the same card (e.g., Jack of Diamonds) Write a program that builds a deck and deals 5 cards to 4 different players toString()  should work so you can use System.out.println() to print out a deck, hand, or a card

More Related Content

What's hot

A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
Rafael Winterhalter
 
Java byte code in practice
Java byte code in practiceJava byte code in practice
Java byte code in practice
Rafael Winterhalter
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
Rafael Winterhalter
 
Core java Essentials
Core java EssentialsCore java Essentials
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performance
Rafael Winterhalter
 
Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
Rafael Winterhalter
 
Understanding Java byte code and the class file format
Understanding Java byte code and the class file formatUnderstanding Java byte code and the class file format
Understanding Java byte code and the class file format
Rafael Winterhalter
 
Byte code field report
Byte code field reportByte code field report
Byte code field report
Rafael Winterhalter
 
final year project center in Coimbatore
final year project center in Coimbatorefinal year project center in Coimbatore
final year project center in Coimbatore
cbeproject centercoimbatore
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
Lorna Mitchell
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
guest5c8bd1
 
Javatut1
Javatut1 Javatut1
Javatut1
desaigeeta
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
Soumya Behera
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Ayes Chinmay
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Ayes Chinmay
 
Java programs
Java programsJava programs
Java programs
Mukund Gandrakota
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
Ganesh Chittalwar
 

What's hot (19)

A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
Java byte code in practice
Java byte code in practiceJava byte code in practice
Java byte code in practice
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performance
 
Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
 
Understanding Java byte code and the class file format
Understanding Java byte code and the class file formatUnderstanding Java byte code and the class file format
Understanding Java byte code and the class file format
 
Byte code field report
Byte code field reportByte code field report
Byte code field report
 
final year project center in Coimbatore
final year project center in Coimbatorefinal year project center in Coimbatore
final year project center in Coimbatore
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Javatut1
Javatut1 Javatut1
Javatut1
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Java programs
Java programsJava programs
Java programs
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 

Similar to Learning Java 1 – Introduction

Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
Intelligo Technologies
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
Intelligo Technologies
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
Java tutorials
Java tutorialsJava tutorials
Java tut1
Java tut1Java tut1
Java tut1
Sumit Tambe
 
Java tut1
Java tut1Java tut1
Java tut1
Sumit Tambe
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
ArnaldoCanelas
 
Java_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.pptJava_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.ppt
Govind Samleti
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
Bui Kiet
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
unit-3java.pptx
unit-3java.pptxunit-3java.pptx
unit-3java.pptx
sujatha629799
 
Reading and writting v2
Reading and writting v2Reading and writting v2
Reading and writting v2
ASU Online
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
parveen837153
 
Control statements
Control statementsControl statements
Control statements
raksharao
 
Intro to Java for C++ Developers
Intro to Java for C++ DevelopersIntro to Java for C++ Developers
Intro to Java for C++ Developers
Zachary Blair
 
Introduction to java programming part 2
Introduction to java programming  part 2Introduction to java programming  part 2
Introduction to java programming part 2
university of education,Lahore
 
Jist of Java
Jist of JavaJist of Java
Jist of Java
Nikunj Parekh
 
JAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESJAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICES
Nikunj Parekh
 
core java
 core java core java
core java
dssreenath
 

Similar to Learning Java 1 – Introduction (20)

Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.pptJava_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.ppt
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
unit-3java.pptx
unit-3java.pptxunit-3java.pptx
unit-3java.pptx
 
Reading and writting v2
Reading and writting v2Reading and writting v2
Reading and writting v2
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
Control statements
Control statementsControl statements
Control statements
 
Intro to Java for C++ Developers
Intro to Java for C++ DevelopersIntro to Java for C++ Developers
Intro to Java for C++ Developers
 
Introduction to java programming part 2
Introduction to java programming  part 2Introduction to java programming  part 2
Introduction to java programming part 2
 
Jist of Java
Jist of JavaJist of Java
Jist of Java
 
JAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESJAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICES
 
core java
 core java core java
core java
 

Recently uploaded

DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
ArgaBisma
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
BookNet Canada
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
Andrey Yasko
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 
The Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive ComputingThe Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive Computing
Larry Smarr
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
Safe Software
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
Eric D. Schabell
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Best Programming Language for Civil Engineers
Best Programming Language for Civil EngineersBest Programming Language for Civil Engineers
Best Programming Language for Civil Engineers
Awais Yaseen
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
Liveplex
 
20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf
Sally Laouacheria
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
Matthew Sinclair
 
Mitigating the Impact of State Management in Cloud Stream Processing Systems
Mitigating the Impact of State Management in Cloud Stream Processing SystemsMitigating the Impact of State Management in Cloud Stream Processing Systems
Mitigating the Impact of State Management in Cloud Stream Processing Systems
ScyllaDB
 
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
Toru Tamaki
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
KAMAL CHOUDHARY
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 

Recently uploaded (20)

DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 
The Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive ComputingThe Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive Computing
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
Best Programming Language for Civil Engineers
Best Programming Language for Civil EngineersBest Programming Language for Civil Engineers
Best Programming Language for Civil Engineers
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
 
20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
 
Mitigating the Impact of State Management in Cloud Stream Processing Systems
Mitigating the Impact of State Management in Cloud Stream Processing SystemsMitigating the Impact of State Management in Cloud Stream Processing Systems
Mitigating the Impact of State Management in Cloud Stream Processing Systems
 
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 

Learning Java 1 – Introduction

  • 1. Learning Java 1: Introduction Christopher Swenson Center for Information Security University of Tulsa 600 S. College Ave Tulsa, OK 74104
  • 2. Learning Java Based on Learning Java , by Niemeyer and Knudsen Quick and Dirty overview of Java fundamentals and advanced programming Introduction Objects and Classes Generics, Core Utilities Threads, Synchronization I/O, Network Programming Swing
  • 3. Overview (Ch. 1–5) Java Hello World! Using Java Java Language Objects
  • 4. Java Modern, Object-Oriented (OO) Language with C-like syntax Developed at Sun Microsystems (James Gosling, Bill Joy) in the early 1990s Virtual Machine Intermediate bytecode Extremely portable Surprisingly fast (comparable to C++) Features HotSpot on-the-fly native compiling Safe and Clean Dynamic Memory Management Robust Error Handling http://java.sun.com http://java.sun.com/j2se/1.5.0/docs/api/
  • 5. Let’s Go! Standard CLI utilities, although IDEs and GUIs exist (Eclipse, Netbeans) Windows: Start  Run  “ cmd ” UNIX / OS X: Open up a command terminal “ javac HelloJava.java ” Compiles the file HelloJava.java Outputs executable .class files
  • 6. HelloJava.java public class HelloJava { public static void main(String[] args) { System.out.println(“Hello World!”); } } Run with: java -cp . HelloJava Outputs: Hello World!
  • 7. Some Notes public class HelloJava { … Everything in Java must be in a class (container for code and data). public static void main(String[] args){ … This is a method (which contains executable code). The function called from the command-line is required to be main . Takes a String array (the arguments), and returns nothing ( void ). System.out.println(“Hello World!”); System is a class that contains a lot of useful system-wide tools, like standard I/O, and its out class represents standard out. The println method of out (and all PrintStream objects) prints the String containted within, followed by a newline. java -cp . HelloJava Invokes the Java Virtual Machine (JVM) to execute the main of the named class ( HelloJava ). Searches the current directory for the class file ( -cp . ).
  • 8. Comments /* */ C-style comments are also supported /** */ are special JavaDoc comments Allow automatic documentation to be built from source code, using the javadoc utility. // C++-style comments are preferred Less ambiguity Simpler
  • 9. Variables String s = “string”; int a = -14; long b = 5000000000l; float c = 2.5f; double d = -4.0d; byte e = 0x7f; char f = ‘c’; short g = -31000; boolean h = true; int s are signed 32-bit long s are signed 64-bit float s are signed 32-bit double s are signed 64-bit byte s are signed 8-bit char s are signed 16-bit short s are signed 16-bit boolean s are 1-bit, either true or false
  • 10. Operators Standard arithmetic operators for ints, longs, shorts, bytes, floats and doubles + - * / % << >> >>> Boolean operators for non-floating point & | ^ ~ Logical operators for boolean s && || ^^ ~ Comparisons generate boolean s == < <= > >= != Can be suffixed with = to indicate an assignment a = a + b  a += b ++ and -- operators also ( a = a - 1  a-- ) Ternary Operator: (a >= b) ? c : d  if (a >= b) c else d
  • 11. Reference Types Reference Types are non-primitive constructs Includes String s Consist of variables and methods (code) Typically identified with capital letter Foo bar = new Foo(); Use the new keyword to explicitly construct new objects Can take arguments No need for destructor or to explicitly remove it No pointers C++: Foo &bar = *(new Foo());
  • 12. String Strings are a reference type, but almost a primitive in Java String s = “this is a string”; No need for new construction Overloaded + operator for concatenation String s = “a” + “ kitten”;
  • 13. Coercion Coercion = automatic conversion between types Up is easy ( int to double , anything to String ) Down is hard int i = 2; double num = 3.14 * i; String s = “” + num; int a = Integer.parseInt(t);
  • 14. Expressions and Statements An statement is a line of code to be evaluated a = b; An statement can be made compound using curly braces { a = b; c = d; } Curly braces also indicate a new scope (so can have its own local variables) Assignments can also be used as expressions (the value is the value of the variable after the assignment) a = (b = c);
  • 15. if-then-else statements if (bool) stmt1; if (bool) stmt1 else statement2; if (bool) stmt1 else if stmt2 else stmt3; if (bool) { stmt1; … ; } … if (i == 100) System.out.println(i);
  • 16. Do-while loops while (bool) stmt; do stmt; while (bool); boolean stop = false; while (!stop) { // Stuff if (i == 100) stop = true; }
  • 17. for loops for ( prestmt ; bool ; stepstmt ;) stmt ; = { prestmt ; while ( bool ) { stmt ; stepstmt ; } } for (int i = 0; i < 10; i++) { System.out.print(i + “ “); } Outputs: “ 0 1 2 3 4 5 6 7 8 9 ”
  • 18. switch statement switch ( int expression ) { case int_constant : stmt ; break ; case int_constant : stmt ; case int_constant : stmt ; default: stmt ; }
  • 19. Arrays int [] array = { 1,2,3 } ; int [] array = new int[ 10 ]; for (int i = 0; i < array.length ; i++) array [ i ] = i; Array indices are from 0 to (length – 1) Multi-dimensional arrays are actually arrays of arrays: int [][] matrix = new int [3][3]; for (int i = 0; i < matrix.length ; i++) for (int j = 0; j < matrix[i].length ; j++) System.out.println(“Row: “ + i + “, Col: “ + j + “ = “ + matrix [i][j] );
  • 20. enum s What about something, like size? Pre-Java 1.5, int small = 1, medium = 2, … But what if mySize == -14 ? enum Size {Small, Medium, Large}; Can also do switch statements on enums switch (mySize) { case Small: // … default: // … }
  • 21. Loop breaking break breaks out of the current loop or switch statement while (!stop) { while (0 == 0) { break ; } // Execution continues here }
  • 22. Loop continuing continue goes back to the beginning of a loop boolean stop = false; int num = 0; while (!stop) { if (num < 100) continue ; if (num % 3) stop = true; }
  • 23. Objects class Person { String name; int age; } Person me = new Person(); me.name = “Bill”; me.age = 34; Person[] students = new Person[50]; students[0] = new Person();
  • 24. Subclassing class Professor extends Person { String office; } Professor bob = new Professor(); bob.name = “Bob”; bob.age = 40; bob.office = “U367”; However, a class can only “extend” one other class
  • 25. Abstract Classes If not all of its methods are implemented (left abstract), a class is called abstract abstract class Fish { abstract void doesItEat(String food); public void swim() { // code for swimming } }
  • 26. Interfaces class MyEvent implements ActionListener { public void actionPerformed(ActionEvent ae) { System.out.println(“My Action”); } } Can implement multiple interfaces Interfaces have abstract methods, but no normal variables
  • 27. Static and final A static method or variable is tied to the class, NOT an instance of the class Something marked final cannot be overwritten (classes marked final cannot be subclassed) class Person { public final static int version = 2; static long numberOfPeople = 6000000000; static void birth() { numberOfPeople++; } String name; int age; } // … in some other code Person.numberOfPeople++; System.out.println(“Running Version “ + Person.version + “ of Person class);
  • 28. Special functions All classes extend the Object class Classes have built-in functions: equals(Object obj), hashCode(), toString() Equals used to determine if two objects are the same o == p – checks their memory addresses o.equals(p) – runs o.equals() hashCode() – used for hash tables ( int ) toString() – used when cast as a String (like printing)
  • 29. Packages Classes can be arranged into packages and subpackages, a hierarchy that Java uses to find class files Prevents naming issues Allows access control By default, a null package Doesn’t work well if you need more than a few classes, or other classes from other packages java.io – Base I/O Package java.io.OutputStream – full name Declare a package with a package keyword at the top Import stuff from package with the import keyword import java.io.*; import java.util.Vector; import static java.util.Arrays.sort;
  • 30. Using Packages Compile like normal Packages = a directory Java has a “classpath”: root directories and archives where it expects to look for classes Example java -cp compiled swenson.MyServer In the the “compiled” directory, look for a class MyServer in the subfolder “swenson” /compiled/swenson/MyServer.class Also need to specify -classpath when compiling Class files can also be put into ZIP files (with a suffix of JAR instead of ZIP)
  • 31. Permissions public – accessible by anyone protected – accessible by anything in the package, or by subclasses (default) – accessible by anything in the package private – accessible only by class
  • 32. Coding Style class Test { public static void main(String[] args) { if (args.length > 0) System.out.println(“We have args!”); for (int i = 0; i < args.length; i++) { int q = Integer.parseInt(args[i]); System.out.println(2 * q); } System.exit(0); } }
  • 33. Tools: Eclipse Popular Auto Complete Fancy Multi-language
  • 34. Tools: NetBeans Another good GUI Full-featured Java-centric
  • 36. emacs
  • 37. vi
  • 39. Homework Download Java Download a GUI and learn it (e.g., Eclipse) Implement a Card class enum s for Suit hashCode() should return a different value for two different cards, but should be the same for two instances of the same card (e.g., Jack of Diamonds) Write a program that builds a deck and deals 5 cards to 4 different players toString() should work so you can use System.out.println() to print out a deck, hand, or a card