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.
This presentation is ideal for a beginner of Java or someone who wants to brush up their Java Knowledge. It's simple to understand and well organized in a way most of the area in core Java has been covered.
This presentation is ideal for a beginner of Java or someone who wants to brush up their Java Knowledge. It's simple to understand and well organized in a way most of the area in core Java has been covered.
Core Java introduction | Basics | free course Kernel Training
http://kerneltraining.com/core-java/
Learn the basics of Java and gain practical experience that is required to begin your career in java programming. Kernel Training has designed classroom and online course to upgrade your knowledge and skills in core Java.
Course Curriculum:
Introduction to Java
JDK and practical applications
Java Basic Data Types and Operators
Programming Constructs, Classes and Methods, constructor and Finalizer
Polymorphism
Inheritance
Method overriding and abstract classes
Packages and Interfaces
Strings and Arrays
Enums
Concurrent Programming in Java provides a brief overview of the following topics:
• Java language support for concurrency
• Concurrency utilities (java.util.concurrent package)
• Java collections for multithreading (java.util package)
• Parallel streams in Java 8.
Try out the examples. Source code here: https://github.com/CodeOpsTech/ConcurrentJava
Mahika Tutorials sharing PPT slide for core java programming language. Go threw this slide and visit our YouTube page too
https://www.youtube.com/c/mahikatutorials
This presentation is about advanced multithreading and concurrency in Java. I have tried my best to explain the concepts with code. Feel free to reach me if you have any questions or concerns.
www.denizoguz.com-For an in company JDK 7 orientation I have prepared a presentation which summaries new features of JDK 7. I would like to make it public for everyone who needs it.
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.
Core Java introduction | Basics | free course Kernel Training
http://kerneltraining.com/core-java/
Learn the basics of Java and gain practical experience that is required to begin your career in java programming. Kernel Training has designed classroom and online course to upgrade your knowledge and skills in core Java.
Course Curriculum:
Introduction to Java
JDK and practical applications
Java Basic Data Types and Operators
Programming Constructs, Classes and Methods, constructor and Finalizer
Polymorphism
Inheritance
Method overriding and abstract classes
Packages and Interfaces
Strings and Arrays
Enums
Concurrent Programming in Java provides a brief overview of the following topics:
• Java language support for concurrency
• Concurrency utilities (java.util.concurrent package)
• Java collections for multithreading (java.util package)
• Parallel streams in Java 8.
Try out the examples. Source code here: https://github.com/CodeOpsTech/ConcurrentJava
Mahika Tutorials sharing PPT slide for core java programming language. Go threw this slide and visit our YouTube page too
https://www.youtube.com/c/mahikatutorials
This presentation is about advanced multithreading and concurrency in Java. I have tried my best to explain the concepts with code. Feel free to reach me if you have any questions or concerns.
www.denizoguz.com-For an in company JDK 7 orientation I have prepared a presentation which summaries new features of JDK 7. I would like to make it public for everyone who needs it.
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.
Many students reach out to me asking for project ideas they can do as a summer project for learning. Here is an interesting project idea - implement your own java disassembler (and expand it to a VM later).
What is Java Technology (An introduction with comparision of .net coding)Shaharyar khan
A introductory slides for those who want to learn and know some basics of Java.Also for those persons who want to compare coding difference between Java and .net
This article is about aspect oriented programming (aop) in spring. the related example of an application with aop support is in the following address :
https://github.com/ghorbanihamid/SpringBoot_AOP_JPA_Example
This document is about how to Write a CRUD App with Spring Boot Jpa or jdbc. a related example for this document is on github with the following address :
https://github.com/ghorbanihamid/SpringBoot_AOP_JPA_Example
Enterprise Resource Planning System includes various modules that reduce any business's workload. Additionally, it organizes the workflows, which drives towards enhancing productivity. Here are a detailed explanation of the ERP modules. Going through the points will help you understand how the software is changing the work dynamics.
To know more details here: https://blogs.nyggs.com/nyggs/enterprise-resource-planning-erp-system-modules/
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
The European Union Agency for Law Enforcement Cooperation (Europol) has suffered an alleged data breach after a notorious threat actor claimed to have exfiltrated data from its systems. Infamous data leaker IntelBroker posted on the even more infamous BreachForums hacking forum, saying that Europol suffered a data breach this month.
The alleged breach affected Europol agencies CCSE, EC3, Europol Platform for Experts, Law Enforcement Forum, and SIRIUS. Infiltration of these entities can disrupt ongoing investigations and compromise sensitive intelligence shared among international law enforcement agencies.
However, this is neither the first nor the last activity of IntekBroker. We have compiled for you what happened in the last few days. To track such hacker activities on dark web sources like hacker forums, private Telegram channels, and other hidden platforms where cyber threats often originate, you can check SOCRadar’s Dark Web News.
Stay Informed on Threat Actors’ Activity on the Dark Web with SOCRadar!
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Java programming basics
1. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
Java – Overview
- was created in 1991 by (James Gosling, Mike Sheridan, and Patrick Naughton)
- developed and Published by Sun Microsystems which in 1995 as Java 1.0
- Initially called Oak, its name was changed to Java because there was
already a language called Oak.
Editions:
Java ME (Micro Edition): targeting environments with limited resources (mobile
devices, micro-controllers, sensors, gateways, TV set-top boxes, printers)
Java SE (Standard Edition): core Java programming platform
targeting desktop and server environments It contains all of the libraries and APIs that
any Java programmer should learn (java.lang, java.io, java.math, java.net, java.util,
etc...).
Java EE (Enterprise Edition):
targeting large scale softwares (Network or Internet environments)
Versions:
JDK 1.0 (January 23, 1996)[38]
JDK 1.1 (February 19, 1997)
J2SE 1.2 (December 8, 1998)
J2SE 1.3 (May 8, 2000)
J2SE 1.4 (February 6, 2002)
J2SE 5.0 (September 30, 2004)
Java SE 6 (December 11, 2006)
Java SE 7 (July 28, 2011)
Java SE 8 (March 18, 2014)
Note: As of 2015, only Java 8 is officially supported
2. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
٢
Principles:
guaranteed to be Write Once, Run Anywhere.
Object Oriented: In Java, everything is an Object.
Secure: With Java's secure feature it enables to develop virus-free, tamper-
free systems.
Portable: Compiler in Java is written in ANSI C with a clean portability
boundary, which is a POSIX subset.
Platform Independent: Unlike many other programming languages including C
and C++, when Java is compiled, it is not compiled into platform specific machine, rather
into platform independent byte code. This byte code is distributed over the web and
interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.
JVM (Java Virtual Machine): bytecode interpreter
JVM is a virtual machine which work on top of your operating system to provide a recommended
environment for your compiled Java code. JVM only works with bytecode. Hence you need to
compile your Java application(.java) so that it can be converted to bytecode format (.class file). Which
then will be used by JVM to run application. JVM only provide the environment It needs the Java code
library to run applications.
3. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
٣
JDK (Java Development Kit)
JDK contains everything that will be required to develop and run Java application.
JDK = JRE + development tools
JRE (Java Run time Environment)
JRE contains everything required to run Java application which has already been compiled. It
doesn’t contain the code library required to develop Java application.
JRE = JVM + Java Packages Classes (like util, math, lang, awt, swing etc) + runtime libraries.
The programming structure:
Sun Micro System has prescribed the following structure for developing java application.
4. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
۴
Package: Package is a collection of classes, interfaces and sub-packages. A sub package contains
collection of classes, interfaces and sub-sub packages etc. java.lang.*; package is imported by default and
this package is known as default package.
Class: In Java, every line of code that can actually run needs to be inside a class. Notice that when we
declare a public class, we must declare it inside a file with the same name, otherwise we'll get an error
when compiling.
Methods: A method is a set of code which is referred to by name. When that name is encountered in a
program, the execution of the program branches to the body of that method. When the method is
finished, execution returns to the area of the program code from which it was called, and the program
continues on to the next line of code.
Language basics:
Case Sensitivity: Java is case sensitive, which means identifier Hello and hello would have
different meaning in Java.
Class Names: For all class names the first letter should be in Upper Case. If several words are used to
form a name of the class, each inner word's first letter should be in Upper Case.
Example: class MyFirstJavaClass
Method Names: All method names should start with a Lower Case letter. If several words are used
to form the name of the method, then each inner word's first letter should be in Upper Case.
Example: public void myMethodName()
Program File Name: Name of the program file should exactly match the class name. When saving
the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to
the end of the name (if the file name and the class name do not match, your program will not compile).
Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as
'MyFirstJavaProgram.java'
public static void main(String args[]): Java program processing starts from the main() method
which is a mandatory part of every Java program.
5. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
۵
Java Data types:
There are two data types available in Java:
- Primitive Datatypes: There are 8 basic data types available within the Java language.
Name Type
Minimum
value
Maximum value Default
value
byte number, 1 byte -128 , 128 0
short number, 2 bytes -32,768 32,767 0
int number, 4 bytes - 2,147,483,648
(-2^31)
2,147,483,647 (2^31 -1) 0
long number, 8 bytes -2^63 2^63 -1 0L
float float number, 4 bytes 1.4E^-45 3.4028235E^38 0.0f
double float number, 8 bytes 4.9E^-324 1.7976931348623157E^308 0.0d
char a character, 2 bytes 'u0000' (or 0) 'uffff' (or 65,535) 'u0000'
boolean true or false, 1 bit false
*** Note: To declare and assign a number use the following syntax:
Variable_Type variable_Name;
Example:
int a, b, c; // Declares three ints, a, b, and c.
int a = 10, b = 10; // Example of initialization
byte B = 22; // initializes a byte type variable B.
double pi = 3.14159; // declares and assigns a value of PI.
char a = 'a'; // the char variable a is initialized with value 'a'
- Reference/Object Datatypes : A reference type is a data type that’s based on a class, a
reference type is an instantiable class
Example:
Person person = new Person();
6. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
۶
Java Variables
To declare and assign a number use the following syntax:
Variable_Type variable_Name;
***Following are the types of variables in Java:
- Local Variables
- Class Variables (Static Variables)
- Instance Variables (Non-static Variables)
Local Variables: Local variables are declared in methods, constructors, or blocks and are visible
only within the declared method, constructor, or block.
Instance Variables: Instance variables belong to the instance of a class(an object) and every
instance of that class (object) has it's own copy of that variable.
Example:
public class Product {
public int barcode; // an instance variable
}
public class MyFirstJavaProgram {
public static void main(String[] args) {
Product product1 = new Product();
product1.barcode = 123456;
System.out.println(product1.barcode);
}
}
Class Variables: Class variables also known as static variables are declared with the
static keyword in a class, but outside a method, constructor or a block. class variable is
a variable defined in a class of which a single copy exists, regardless of how many instances
of the class exist.
public class MyFirstJavaProgram {
static int barcode;
}
7. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
٧
Java Modifiers:
Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are
two categories of modifiers:
Access Modifiers: default, public , protected, private
Non-access Modifiers: final, abstract, strictfp
if-else statement:
An if statement can be followed by an optional else statement, which executes when the
Boolean expression is false.
if( x < 20 ) {
System.out.print("This is if statement");
}else {
System.out.print("This is else statement");
}
while-loop
A while loop statement in Java programming language repeatedly executes a target
statement as long as a given condition is true.
int x = 0;
while( x < 20 ) {
System.out.print("This is while statement : " + x);
X++;
}
do-while-loop
A do...while loop is similar to a while loop, except that a do...while loop is guaranteed
to execute at least one time.
int x = 0;
while( x < 20 ) {
System.out.print("This is while statement : " + x);
X++;
}
8. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
٨
for-loop
A for loop is a repetition control structure that allows you to efficiently write a loop that
needs to be executed a specific number of times.
for( int i = 0; i < 20; i++ ) {
System.out.print("This is for-loop statement : " + i);
}
For-each loop
The for-each loop(Advanced or Enhanced For loop) introduced in Java5. It is mainly
used to traverse array or collection elements. The advantage of for-each loop is that it
eliminates the possibility of bugs and makes the code more readable.
for(data_type variable : array | collection){ …. }
Example 1:
int arr[]={12,13,14,44};
for( int i:arr) {
System.out.print("This is for- each loop statement : " + i);
}
Example 2:
ArrayList<String> list=new ArrayList<String>();
list.add("vimal");
list.add("sonoo");
list.add("ratan");
for(String s:list){
System.out.println(s);
}
9. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
٩
Branching Statements
Java offers three branching statements:
break
continue
return
Break
This statement can be used to terminate a switch, for, while, or do-while loop
for(int i=1;i<=10;i++){
if(i==5){
break;
}
System.out.println(i);
}
Continue
The continue keyword causes the loop to immediately jump to the next iteration of the loop.
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
if(i==2&&j==2){
continue;
}
System.out.println(i+" "+j);
}
}
return
used to exit from the current method.
public static int minFunction(int n1, int n2) {
int min;
min = n2;
return min;
}
10. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
Switch statement
The Java switch statement executes one statement from multiple conditions. It is like if-
else-if ladder statement.
Example:
public class SwitchExample {
public static void main(String[] args) {
int number=20;
switch(number){
case 10: System.out.println("10");break;
case 20: System.out.println("20");break;
case 30: System.out.println("30");break;
default:System.out.println("Not in 10, 20 or 30");
}
}
}
public class Test {
public static void main(String args[]) {
char grade = 'C';
switch(grade) {
case 'A' :
System.out.println("Excellent!");
break;
case 'B' :
case 'C' :
System.out.println("Well done");
break;
case 'D' :
System.out.println("You passed");
case 'F' :
System.out.println("Better try again");
break;
default :
System.out.println("Invalid grade");
}
System.out.println("Your grade is " + grade);
}
}
11. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
Arrays
Java arrays, is a data structure which stores a fixed-size sequential collection of elements
of the same type. An array is used to store a collection of data, but it is often more useful
to think of an array as a collection of variables of the same type.
Syntax:
1)
dataType[] arrayName; or
dataType arrayName[];
Example:
// declaration
Int[] myList;
// instantiate object
myList = new int[10];
2)
dataType[] arrayName = new datatype[size];
Example:
double[] myList = new double[10];
Array initialization:
1) after declaration:
a[0]=10;
a[1]=20;
a[2]=70;
a[3]=40;
2) with declaration:
int[] arr = {1, 2, 3, 4, 5};
String[] days = { “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”,“Sun”};
12. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
Note1: The elements of an array have indexes from 0 to n-1.
Note that there is no array element arr[n]! This will result in an
"array-index-out-ofbounds" exception.
Note2: You cannot resize an array.
public class TestArray {
public static void main(String[] args) {
double[] myList = {1.9, 2.9, 3.4, 3.5};
// Print all the array elements
for (int i = 0; i < myList.length; i++) {
System.out.println(myList[i] + " ");
}
// Summing all elements
double total = 0;
for (int i = 0; i < myList.length; i++) {
total += myList[i];
}
System.out.println("Total is " + total);
// Finding the largest element
double max = myList[0];
for (int i = 1; i < myList.length; i++) {
if (myList[i] > max) max = myList[i];
}
System.out.println("Max is " + max);
}
}
13. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
Copying Array:
1) reference Copy: use the assignment statement (=)
list2 = list1;
2) Value Copy:
2_1) write a loop to copy every element:
2_2) use arraycopy method: it is in the java.lang.System class
arraycopy(sourceArray, srcPos, targetArray, tarPos, length);
srcPos and tarPos indicate the starting positions in sourceArray and
targetArray, respectively.
The number of elements copied from sourceArray to targetArray is
indicated by length.
arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
14. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
Multidimensional Arrays:
1) int[][] arr = new int[3][3]; //3 row and 3 column
2) // declaring and initializing 2D array
int arr[][] = {{1,2,3},{2,4,5},{4,4,5}};
Example:
// String array 4 rows x 2 columns
String[][] dogs = {
{ "terry", "brown" },
{ "Kristin", "white" },
{ "toby", "gray"},
{ "fido", "black"}
};
Example:
// character array 8 x 16 x 24
char[][][] threeD = new char[8][16][24];
15. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
Lengths of Two-Dimensional Arrays
x = new int[3][4];
x.length is ?
Traversing 2D array
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
Output:1 2 3
2 4 5
4 4 5
16. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
The Array Class
The java.util.Arrays class contains various static methods for sorting and searching arrays,
comparing arrays, and filling array elements.
Sort:
This method sorts the specified array of ints into ascending numerical order.
BinarySearch:
searches the specified array of ints for the specified value using the binary search
algorithm.The array must be sorted before making this call.
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
// initializing unsorted int array
int iArr[] = {2, 1, 9, 6, 4};
// sorting array
Arrays.sort(iArr);
for (int number : iArr) {
System.out.println("Number = " + number);
}
int searchVal = 12;
int retVal = Arrays.binarySearch(intArr,searchVal);
System.out.println("The index of element 12 is : " + retVal);
}
}
17. Java Programming basics http://ir.linkedin.com/in/ghorbanihamid
١
equals: You can use the equals method to check whether two arrays are equal.
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
// initiliazing three object arrays
Object[] arr1 = new Object[] { 1, 123 };
Object[] arr2 = new Object[] { 1, 123, 22, 4 };
Object[] arr3 = new Object[] { 1, 123 };
// comparing arr1 and arr2
boolean retval=Arrays.equals(arr1, arr2);
System.out.println("arr1 and arr2 equal: " + retval);
// comparing arr1 and arr3
boolean retval2=Arrays.equals(arr1, arr3);
System.out.println("arr1 and arr3 equal: " + retval2);
}
}
fill: You can use the fill method to fill in the whole array or part of the array.
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
// initializing int array
int arr[] = new int[] {1, 6, 3, 2, 9};
// using fill for placing 18
Arrays.fill(arr, 18);
for (int value : arr) {
System.out.println("Value = " + value);
}
}
}