0% found this document useful (0 votes)
178 views20 pages

Internshala Core - Java

This document provides an overview and roadmap for an Internshala Core Java summer training. It includes brief introductions to Java concepts like object-oriented programming, classes, objects, and arrays. It also covers setting up a Java development environment, how to write and run a simple "Hello World" program, and importing libraries. The training will culminate in a project to build the Connect Four game.

Uploaded by

Sourabh Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views20 pages

Internshala Core - Java

This document provides an overview and roadmap for an Internshala Core Java summer training. It includes brief introductions to Java concepts like object-oriented programming, classes, objects, and arrays. It also covers setting up a Java development environment, how to write and run a simple "Hello World" program, and importing libraries. The training will culminate in a project to build the Connect Four game.

Uploaded by

Sourabh Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

INTERNSHALA CORE– JAVA

Summer training

Sourabh_Pathak
ROADMAP

• Brief intro to Java oops


• Develop and compile environment
• Intro to object/class
• Java basics
• My project-
• Connect four game
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…
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
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.
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/index.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)
HELLO WORLD!
File name: Hello.java

/* Our first Java program – Hello.java */ Command line


public class Hello { arguments
//main()
public static void main ( String[] args ) {
System.out.println( "hello world!" );
}
}
Standard output, print with new line
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.
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
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


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.
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
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
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??
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
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];
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.
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
Certificate

CERTIFICATE
PROJECT-CONNECT FOUR GAME

You might also like