You are on page 1of 13

JAVA Core

by:- Sahil Chopra 10901966

Intro to Java
Java

programming language

platform independent programming language Compiled to byte code of JVM

Java virtual machine (JVM)


Java interpreter interpret the compiled byte code Software simulated CPU architecture

Java runtime environment (JRE)


Predefined set of java classes available to use Core Java APIs basic utilities, I/O, graphics, network .

Characteristics of Simple Secure Portable Object-oriented Robust Multithreaded Architecture-neutral Interpreted High performance Distributed Dynamic

Java

How it works!
Java is independent only for one reason: Only depends on the Java Virtual Machine (JVM), code is compiled to bytecode, which is interpreted by the resident JVM, JIT (just in time) compilers attempt to increase speed New release of Java is improving the speed a lot Just-in-time (JIT) compiler: convert byte codes to native machine language on the fly

Classes and Objects


The class is the unit of programming A Java program is a collection of classes Each class definition (usually) in its own .java file The file name must match the class name A class describes objects (instances) Thus all the instances have these same characteristics These characteristics are: Data fields for each object Methods (operations) that do work on the objects

Cont . 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.

Things to notice
Java is case sensitive. whitespace doesnt 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.

Hello World !!!


File name: Hello.java /* Our first Java program Hello.java */ public class Hello { //main() public static void main ( String[] args ) { System.out.println( "hello world!" ); } }

Grouping Classes: The Java API


API = Application Programming Interface Java = small core + extensive collection of packages A package consists of some related Java classes: Swing: a GUI (graphical user interface) package AWT: Application Window Toolkit (more GUI) util: utility data structures (important to CS 187!) The import statement tells the compiler to make available classes and methods of another package A main method indicates where to begin executing a class (if it is designed to be run as a program)

Difference between C and Java


No pointers. No global variable across classes. Variable declaration anywhere. Forward reference
Method can be invoked before defined

Method overloading
As long as the methods have different parameter lists

No variable-length argument list

Object-Oriented Programming
Understanding OOP is fundamental to writing good Java applications Improves design of your code Improves understanding of the Java APIs\ There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Inheritance Polymorphism

Java Development Kit


Javac The Java Compiler java - The Java Interpreter appletviewer -Tool to run the applets

javap - to print the Java bytecodes javaprof - Java profiler javadoc - documentation generator javah - creates C header files

You might also like