0% found this document useful (0 votes)
58 views

Significance of Searching Class Path

The document discusses how the Java compiler and JVM search classpaths to locate classes. Both use

Uploaded by

sajeer
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Significance of Searching Class Path

The document discusses how the Java compiler and JVM search classpaths to locate classes. Both use

Uploaded by

sajeer
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Java was created around the time when the Unicode standard had values defined for a much

smaller set of characters. Back then it was felt that 16-bits would be more than enough to encode all the characters that would ever be needed. With that in mind Java was designed to use UTF-16. In fact, the char data type was originally used to be able to represent a 16-bit Unicode code point. Since Java SE v5.0, the char now represents a code unit. It makes little difference for representing characters that are in the basic multilingual plane because the value of the code unit is the same as the code point. It does mean that for the characters on the other planes two chars are needed. The important thing to remember is a single char data type can no longer represent all the Unicode characters.
One thing great about Java is that it is unicode based. That means, you can use characters from writing systems that are not english alphabets (e.g. Chinese or math symbols), not just in data strings, but in function and variable names too.

Unicode enables a single software product or a single website to be designed for multiple platforms, languages and countries (no need for re-engineering) which can lead to a significant reduction in cost over the use of legacy character sets. Unicode data can be used through many different systems without data corruption. Unicode represents a single encoding scheme for all languages and characters. Unicode is a common point in the conversion between other character encoding schemes. Since it is a superset of all of the other common character encoding systems, you can convert from one encoding scheme to Unicode, and then from Unicode to the other encoding scheme. Unicode is the preferred encoding scheme used by XML-based tools and applications.

Significance of searching class path Java is an OOP language. In java programming language for compiling the program we use the compiler that converts the source code into the byte code after that, that byte code is interpreted by JVM that converts the bytecode into the machine independent code. In java how the Java compiler and the JVM use the class search path to locate classes when they are referenced by other Java code. Searching class path is important for all Java developers.Many development tools have their own ways of manipulating the class path, which vary from product to product.For doing this we will use only simple command-line tools to carry out the compile operations. No difference, between the way that the Java compiler searches for classes, and the way that the JVM does it at run time. The compiler has the ability to compile classes from source code, where the JVM does not. We will use the compiler, but similar issues apply at run time. Searching of multiple class directories

javac(compiler)search the files in only one directory at a time. But, class search path will contain numerous directories and JAR archives. The classpath option to javac and java allows multiple entries to be specified, but the syntax is different for Unix and Windows systems.

Event hanling The most common technique for handling events in Java is to use event listeners. A listener is an object that includes one or more event-handling methods. When an event is detected by another object, such as a button or menu, the listener object is notified and it responds by running the appropriate event-handling method. An event is detected or generated by an object. Another object, the listener, has the responsibility of responding to the event. The event itself is actually represented by a third object, which carries information about the type of event, when it occurred, and so on. This division of responsibilities makes it easier to organize large programs.

Super and final keyword

The super keyword is used to call variables, methods, and/or constructors of a parent class. If references the parent class through the super keyword (super.[field] or super.[method/constructor]([args])). The final keyword has a few uses. 1. The most common is to make a variable's value constant, and create a compile error if it is changed after its first assignment of a value. This does not mean that the variable is immutable: the value itself can possibly change, but the assignment to that value cannot. 2. A method declared final cannot be changed in a subclass. 3. A final class cannot be subclassed.

Constructors
When you create a new instance (a new object) of a class using the new keyword, a constructor for that class is called. Constructors are used to initialize the instance variables (fields) of an object. Constructors are similar to methods, but with some important differences.

Constructor name is class name. A constructors must have the same name as the class its in. Default constructor. If you don't define a constructor for a class, a default parameterless constructor is automatically created by the compiler. The default constructor calls the default parent constructor (super()) and initializes all instance variables to default value (zero for numeric types, null for object references, and false for booleans). Default constructor is created only if there are no constructors. If you define any constructor for your class, no default constructor is automatically created.

Java SDK Directory Structure


This section introduces the Directory and file structure of SDK (Software Development Kit). The following figure shows jdk1.5.0 software stored in 'c' directory that has multiple subdirectories like bin, demo, include and jre etc. to hold all important developing and testing tools. See detail information bellow

The jdk1.5.0 has following directory: Bin directory - The bin directory provides all inessential tools for developing and testing the program through the help of command provided by Java compiler. Demo directory - This directory consists many applications and applets with source code. Include directory - It contains all header files like for 'C' programming language that enables you to combine C code into a Java program. Jre directory - When you run any java program then you have to compile it by the help of Java interpreter or Java Runtime Environment (JRE). The SDK uses the internal adaptation of JRE, which containing in the jre root directory. Lib directory - This is a most important directory for development tools that contains libraries and it's supported files. Docs directory - It is the last directory of Software Development Kit that assists you to store the Java documents. The docs directory is an optional directory.
Sorting a string of an array with size n

1. import java.util.Scanner; 2. public class Names 3. { 4. public static void main(String[ ] args) 5. { 6. 7. 8. 9. 10. 11. 12. 13. } 14. public static void sortStringBubble( String 15. { 16. 17. 18. 19. int j; boolean flag = true; //determine if sort is finished String temp; while ( flag ) x [ ] ) Scanner scanner = new Scanner (System.in); String names; System.out.print("Enter names you would like sorted alphabetically: "); names = scanner.next(); sortStringBubble (names); for ( int k = 0; k < 4; k++ ) System.out.println( names[k] );

20. { 21. 22. 23. { 24. ) 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. } } } } { // ascending sort temp = x [ j ]; x [ j ] = x [ j+1]; x [ j+1] = temp; flag = true; } // swapping if( x [ j ].compareToIgnoreCase( x [ j+1 ] ) > 0 flag = false; for ( j = 0; j < x.length - 1; j++ )

Menue A menu provides a space-saving way to let the user choose one of several options. Other components with which the user can make a one-of-many choice include combo boxes, lists, radio buttons, spinners, and tool bars. If any of your menu items performs an action that is duplicated by another menu item or by a tool-bar button JMenuBar menuBar;
menuBar = new JMenuBar();

A class that holds a list of EventListeners. A single instance can be used to hold all listeners (of all types) for the instance using the list. It is the responsiblity of the class using the EventListenerList to provide type-safe API (preferably conforming to the JavaBeans spec) and methods which dispatch event notification methods to appropriate Event Listeners on the list. The main benefits that this class provides are that it is relatively cheap in the case of no listeners, and it provides serialization for event-listener lists in a single place, as well as a degree of MT safety (when used correctly). Usage example: Say one is defining a class that sends out FooEvents, and one wants to allow users of the class to register FooListeners and receive notification when FooEvents occur. The following should be added to the class definition:
EventListenerList listenerList = new EventListenerList();

break - The break statement is used to jump out of loop. After the break statement control passes to the immediate statement after the loop. continue - Using continue we can go to the next iteration in loop.

exit - it is used to exit the execution of program.


s1(); s2(); if a = b then exit sub s3(); scope and rules for java applet programming
An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal. There are some important differences between an applet and a standalone Java application, including the following:

An applet is a Java class that extends the java.applet.Applet class. A main() method is not invoked on an applet, and an applet class will not define main(). Applets are designed to be embedded within an HTML page. When a user views an HTML page that contains an applet, the code for the applet is downloaded to the user's machine. A JVM is required to view an applet. The JVM can be either a plug-in of the Web browser or a separate runtime environment. The JVM on the user's machine creates an instance of the applet class and invokes various methods during the applet's lifetime. Applets have strict security rules that are enforced by the Web browser. The security of an applet is often referred to as sandbox security, comparing the applet to a child playing in a sandbox with various rules that must be followed. Other classes that the applet needs can be downloaded in a single Java Archive (JAR) file

Local and Remote applet

A LOCAL applet is the one which is stored on our computer system.when browser try to access the applet, it is not necessary for our computer to be connected to The Internet. A REMOTE applet is the one which is not stored on our computer system and we are required to be connected to the Internet. Listing 3.1 LST3_1.TXT: Specifying a Local Applet.
<applet codebase="tictactoe" code="TicTacToe.class" width=120 height=120> </applet>

Listing 3.2 LST3_2.TXT: Specifiying a Remote Applet.


<applet codebase="http://www.myconnect.com/applets/"

code="TicTacToe.class" width=120 height=120> </applet>


Life cycle if multithread

What is Multithreading? Explain the life cycle of a thread.



Multithreading is executing two parts of the same program concurrently. Multithreading is a form of multitasking. In thread based multi tasking environment, a smallest unit of sequential flow of code is a thread. A program can contain more than one thread. Ex: A browser can serve a web page while downloading a file. Each of these actions is a thread. The two factors to get the benefit of multithreading are: 1. The CPU idle time can be minimized 2. I/O devices such as ports, disks are much slower than the CPU. A program spends a majority of execution time waiting to send or receive data to or from a device.

This idle time can be used to perform another task in an application.

Life cycle of a thread:



New State: Soon after creation of a thread, the thread is said to in the new state. Runable State: The life of a thread starts after invoking the start() method. The start() method invokes the run() method. Running State: When the thread is currently running, it is in the state of running. Wait State : When other threads are holding the resources, the current thread is said to be in wait state Dead State: When the thread is completed the execution of run() method, it is said to be dead state. In other words, when a thread cannot ever run.

Color demonstration of applet


//Program for Collerdemonstration import java.awt.*; import java.applet.*; /* <applet code="ColorDemonstration" width=300 height=300> </applet> */ public class ColorDemonstration extends Applet{ public void paint(Graphics g){ Color c1=new Color(255,100,100); Color c2=new Color(100,255,100); Color c3=new Color(100,100,255); g.setColor(c1); g.drawLine(170,170,270,270); g.setColor(c2); g.drawRect(0,0,40,40); g.setColor(c3); g.fillRect(50,50,100,100); g.drawLine(0,10,100,10); } }

Difference between interface and class Following are the difference between the Classes and Interface 1. The interfaces are used in java to implementing the concept of multiple inheritence whereas classes are not used to implement multiple inheriyence. 2. We are not allocating the memory for the interfaces whereas the memory is allocated for the classes 3. Interfaces are always implemented whereas clases are always extended Write a java program for the text and print the number of occurrence

package useToken; import java.io.*; class readFile extends StreamTokenizer { readFile(InputStream in ){ super(in); } public static void main (String argv[]){ try { int ret; String string; BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); System.out.print("Enter some text: "); string = in.readLine(); String[] file = {"file1.txt","file2.txt","file3.txt"}; for(int i=0;i<3;i++){ FileInputStream fin = new FileInputStream(file[i]); readFile rt = new readFile(fin); int counter =0; while((ret = rt.nextToken())!= 0 && rt.sval != null){ if(rt.sval.equals(string)){ System.out.println("Found Text :" + rt.sval ); counter++; } } System.out.println("The String Found :" + counter + " " + "times"); System.out.println(file[i] + " " + "Complete"); } } catch (Exception e ){ System.err.println("Exception :" + e); } } }

four button on screen using different layout object


import javax.swing.*; 02 import java.awt.FlowLayout;

03 import java.awt.Frame; 04 import javax.swing.JPanel; 05 import javax.swing.JFrame; 06 import javax.swing.JLabel; 07 import javax.swing.SwingConstants; 08 import javax.swing.Icon; 09 import javax.swing.ImageIcon; 10 import javax.swing.*; 11 import java.awt.*; 12 public class RAC11_01 { 13 14 /** 15 * @param args 16 */ 17 public static void main(String[] args) { 18 RAC11_01 gui = new RAC11_01(); 19 gui.go(); 20 } 21 22 23 public void go(){ 24 25 26 JFrame frame = new JFrame("Test Frame"); 27 JPanel panel1 = new JPanel (); 28 JPanel panel2 = new JPanel (); 29 30 31 panel1.setBackground(Color.BLACK); 32 frame.getContentPane().add(panel1); 33

34 frame.getContentPane().setLayout(new FlowLayout()); 35 frame.setSize(300,150); 36 37 JButton button1 = new JButton("Show Rectangle"); 38 JButton button2 = new JButton("Show Oval"); 39 40 panel1.add(button1); 41 panel1.add(button2); 42 43 44 frame.setVisible(true); 45 panel2.setBackground(Color.GREEN); 46 47 frame.getContentPane().add(panel2); 48 49 JButton button4 = new JButton("Show Arc"); 50 JButton button5 = new JButton("Show Polygon"); 51 52 53 panel2.add(button4); 54 panel2.add(button5); 55 ; 56 frame.setSize(300,150); 57 frame.setVisible(true); 58 59 60 frame.setDefaultCloseOperation( 61 JFrame.EXIT_ON_CLOSE); 62 63 } 64 65 }

USERDEFINED PACKAGES

A user defined package is one which is developed by java programmers to simplify the task of the java programmers to keep set of classes, interfaces and sub packages which are commonly used. Any class or interface is commonly used by many java programmers that class or interface must be placed in packages.

Syntax: package pack1[.pack2[.pack3[.packn]..]]; Here, package is a keyword which is used for creating user defined packages, pack1 represents upper package and pack2 to packn represents sub packages. For example: package p1; statement-1 package p1.p2; statement-2

Method overriding

A method is said to be overridden when one is in parent class and another is in child class with the same name, same return type, same parameter.
class Animal { int height=10; int weight=20; void talk() { System.out.println(\"Animal talking\"); } void food() { System.out.println(\"Animal Eating\"); } } class Cat extends Animal { void talk() { System.out.println(\"meo... meo\"); }

void food() { System.out.println(\"Drink MILK\"); } }

class functionOverride { public static void main(String[] args) { Animal a = new Animal(); Cat c = new Cat(); /* c.height=20 */; c.talk(); c.food(); System.out.println(\"Height \"+c.height); } }

GUI layout manager

A layout manager is an object that implements the LayoutManager interface* and determines the size and position of the components within a container. Although components can provide size and alignment hints, a container's layout manager has the final say on the size and position of the components within the container.

Components
components consist of a custom set of widgets for various styles of user interaction. The range of widgets includes: text labels; buttons; choice and list selections; scrollbars; text fields and editing areas; canvas painting areas. Container

A container is a component which can contain other components inside itself. It is also an instance of a subclass of java.awt.Container. java.awt.Container extends java.awt.Component so containers are themselves components. AWT The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes (JFC)

the standard API for providing a graphical user interface (GUI) for a Java program.

You might also like